I need to rename all the files in a directory like below:
Original file name: ABC_DEFGHIJK_LMNO Thu Jul 30 07:29:14 CEST 2020
Renamed file name: ABC_DEFGHIJK_LMNO
So basically I need to ignore every thing after first space while renaming the file.
You can write a simple bash script like this:
#!/bin/bash
cd /path/to/files
for f in *
do
new_name=$(echo "$f" | cut -d ' ' -f1)
echo renaming file "$f" to "$new_name"
# mv "$f" "$new_name"
done
If the output is alright, uncomment the mv
command to rename the files.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.