Quote:
Originally posted by sirpelidor
macemoneta: when tried your method:
[apple@localhost test]$ ls -l kuku2comic\\hunterXhunter\\hunter212\\212\\* | awk -F\\ '{print "mv \"" $0 "\"",$5}' | bash
i got this:
mv: invalid option -- r
did i type something wrong?
|
Yes; the option after the first command (ls) is -1 (one) not -l (lowercase L). The -1 option insures that only a single file is listed per line. If you break the stages down (with a few sample files I created):
$ ls -1 kuku2comic\\hunterXhunter\\hunter212\\212\\*
kuku2comic\hunterXhunter\hunter212\212\01.jpg
kuku2comic\hunterXhunter\hunter212\212\02.jpg
kuku2comic\hunterXhunter\hunter212\212\03.jpg
kuku2comic\hunterXhunter\hunter212\212\10.jpg
kuku2comic\hunterXhunter\hunter212\212\11.jpg
The first stage, above, lists the files that will be manipulated.
$ ls -1 kuku2comic\\hunterXhunter\\hunter212\\212\\* | awk -F\\ '{print "mv \"" $0 "\"",$5}'
mv "kuku2comic\hunterXhunter\hunter212\212\01.jpg" 01.jpg
mv "kuku2comic\hunterXhunter\hunter212\212\02.jpg" 02.jpg
mv "kuku2comic\hunterXhunter\hunter212\212\03.jpg" 03.jpg
mv "kuku2comic\hunterXhunter\hunter212\212\10.jpg" 10.jpg
mv "kuku2comic\hunterXhunter\hunter212\212\11.jpg" 11.jpg
Adding the second stage, above, lists the files to be manipulated to awk, which converts them into the commands that will perform the renames. These are just displayed to standard out.
By adding the pipe to bash, the commands will get executed:
$ ls -1 kuku2comic\\hunterXhunter\\hunter212\\212\\* | awk -F\\ '{print "mv \"" $0 "\"",$5}' | bash
$ ls
01.jpg 02.jpg 03.jpg 10.jpg 11.jpg