To rename a set of files to a name starting with a particular pattern (here the pattern is taken to be to start the filename with "MyFile_"
files = `ls -1`;for file in $files; do mv $file MyFile_$file ; done
Dissection:
files = `ls -1`;for file in $files; do mv $file MyFile_$file ; done
Dissection:
- ls -1
- ls is the command in linux to list the files in the present directory
- The parameter -1 will list one file a line
- "files" is a variable which has the list of all the files listed by the command ls -1
- files = `ls -1`
- save the result of ls -1 to a variable called files
- Remember to put the command inside a pair of back ticks ` (the key is generally found just before the key "1" in the keyboard)
- Significance of ` (backtick)
- for file in $files
- Loop through each file name available in the variable files
- do mv $file MyFile_$file; done (The do - done loop)
- Executes the command given after do
- End the do with a done
Comments
Post a Comment
Please post your comment