One: add suffix to batch files
- Requirements: Add the suffix ".tar.gz" to all files ending in .txt in the current directory
#!/bin/sh
for files in $(ls *.txt)
do mv $files $files".tar.gz"
Two: Batch files delete specified characters
- Requirements: For all files ending in .txt.tar.gz in the current directory, delete the .tar.gz suffix
#!/bin/sh
for file in `ls | grep .txt.tar.gz`
do
newfile=`echo $file | sed 's/.tar.gz//g'`
mv $file $newfile
done
Three: Batch replace file names
- Requirements: Replace all files ending with .txt in the current directory with .p.txt
#!/bin/sh
for file in `ls | grep .txt`
do
newfile=`echo $file | sed 's/.txt/.p.txt/g'`
mv $file $newfile
done