Operation Method of Batch Adding File Prefix in linux
- 2021-07-10 21:19:34
- OfStack
Need to add "gt_" before the file name of all txt files in the folder;
That is, from the original file "xxx. txt" to "gt_xxx. txt":
The scripts searched online are as follows:
for i in `ls`;
do mv -f $i 'echo "gt_"$i`;
done
1. First, the linux command line switches to the directory where you need to modify the file name:
cd Destination Directory
2. Create a new sh file in this directory:
touch xxx.sh
3. Open the xxx. sh file:
vim xxx.sh
3. Copy the script content to the sh file, save and exit
Edit sh file: Shift+I
Save exit after pasting: Ctrl+Alt + D Exit edit status, then enter: wq! Quit
Execute the sh file:./xxx. sh
I haven't touched the instructions of linux before, but now I need to use some, so I take notes as a memo ~ ~ ~
ps: Batch change file prefix command under linux
for f in * ; do mv -- "$f" "PRE_$f" ; done
Summarize