Recursively move files one directory up
Hello,
I have folders using the following structure: Code:
root@/volume1/Movies/Hitman.2007-FLX: tree I have a lot of movies so it would be handy if someone would know a command to do this with. Thanks! Dennis |
Quote:
1. Detect the circumstances you want. 2. Move to the target subdirectory (containing the file to be moved). 3. Code:
$ mv (filename) .. |
Quote:
Are you mad? |
Guys come on. He probably means he wants to move all his movies one directory up, and of course as fast and easy as possible (not one by one).
supposing you are in the directory /volume1/Movies as in your example; Code:
ls -Q */*/*mkv|sed -e 'p' -e 's/\(^.*\/\).*\/.*mkv/\1/' >temp1.txt This would put every movie (the one the 1 and 3 directories) on the their upper directories. If you want only the ones on the 3 directory to be moved, you just replace the part that says "ls -Q */*/*mkv" with "ls */3*/*mkv". Also, you may want to see the output of the command first (just to be sure your movies are going to be moved to the right place), taking the "|bash" part out will only show you the command, without moving your movies. You should put the above lines in a file and run it by Code:
bash this_file Code:
ls -Q */*/*mkv|sed -e 'p' -e 's/\(^.*\/\).*\/.*mkv/\1/' >temp1.txt ;sed -e 'N' -e 's/\n/ /g' -e 's/^/mv /g' temp1.txt |bash ;rm temp1.txt |
Quote:
Quote:
|
Quote:
The command worked like a charm! Regards, Dennis |
Quote:
Quote:
The OP can use this one-liner once, for one purpose, one day, then he is well-advised to throw it away. Or is the real point to look like a genius and make computer programming seem incomprehensible except to those few superior individuals on whom nature has smiled? Contrary to common belief, computer programming is not an open-ended code obfuscation contest. |
... But FLX is running as root, so he won't mind copying and pasting obscure one- (maybe two-) liners and executing them, will he? ;)
|
Quote:
This is also a box on a sealed vlan, my rule of thumb is never to use shady commands in a prod env. This however was a private matter and worked well. Give me a break. |
All times are GMT -5. The time now is 03:46 PM. |