Saturday, December 10, 2016

bash - How do I move files from many child directories into my root directory?



I'm using bash on Mac 10.9.5. I have PDF files in many directories, all one level from the root ...




Dir_1/abc.PDF
Dir_2/def.PDF
Dir_3/ghi.PDF
Dir_3/jkl.PDF
...


How do I write a shell command to move all these files into the "root" directory, that is make the files line up alongside the child directories ...



abc.PDF

def.PDF
ghi.PDF
Dir_1
Dir_2
Dir_3


?


Answer



How about just:




mv ./*/*.pdf .


I've done a test on my computer (zsh 5.0.7 (x86_64-pc-linux-gnu)) and it worked perfectly:



> ls -r *    

sub3:
r.2 r.1


sub2:
s.2 s.1

sub1:
t.2 t.1

> mv ./*/*.pdf .
> ls
r.1 r.2 s.1 s.2 sub1 sub2 sub3 t.1 t.2



> tree
.
├── r.1
├── r.2
├── s.1
├── s.2
├── sub1
├── sub2

├── sub3
├── t.1
└── t.2

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...