|
|
This thread is locked; no one can reply to it.
|
1
2
|
| Flatten directory structure in Linux |
|
Billybob
Member #3,136
January 2003
|
The google result for this doesn't work I need to simply flatten the directory structure of some directory. Take all the files under all the directories and put them in the main directory. So: some -> dir1 -> file1.zip dir2 -> file2.zip file3.zip file4.zip Becomes: flat -> file1.zip file2.zip file3.zip file4.zip some -> dir1 -> file1.zip dir2 -> file2.zip file3.zip file4.zip
Any ideas on a command line solution? I tried:
|
|
Evert
Member #794
November 2000
|
Can't you do something like cp `find . -type f -path 'some/*'` flat/? |
|
jhuuskon
Member #302
April 2000
|
for /R %I in (/some) do copy %~fI /flat But that's how would do it. You don't deserve my sig. |
|
Billybob
Member #3,136
January 2003
|
Quote: Can't you do something like cp `find . -type f -path 'some/*'` flat/?
Indeed I can! Danke sehr! EDIT:
|
|
Thomas Fjellstrom
Member #476
June 2000
|
Re Edit: Use some proper bash maybe? or learn how to use find? find . -type f -path foo -exec cp '{}' flat (I think thats how find's exec works, I'd probably use the folowing version though) -- |
|
Billybob
Member #3,136
January 2003
|
TF: That seems to work. Danke!
|
|
axilmar
Member #1,204
April 2001
|
In Windows you can do it with the search window: just place *.* in the filename and then move the results to the directory of your preference. |
|
HoHo
Member #4,534
April 2004
|
You could do the same in Linux but that wouldn't be half as fun __________ |
|
Billybob
Member #3,136
January 2003
|
Wow this is annoying: I get that error on the following command:
|
|
ReyBrujo
Moderator
January 2001
|
find ./zips -type f -name "*.zip" -exec cp '{}' flat \; (Edited: Added file type and name) -- |
|
James Stanley
Member #7,275
May 2006
|
Quote: In Windows you can do it with the search window: just place *.* in the filename and then move the results to the directory of your preference.
Yeah, but you couldn't have your program do it with just one call to system()... |
|
Peter Wang
Member #23
April 2000
|
find with spaces: find some -name '*.zip' -print0 | xargs -0 -i'{}' cp '{}' flat The -print0 and -0 options use the NUL terminator as a filename separator instead of spaces. If you were using zsh (and probably some other shells, but not bash): cp some/**/*.zip flat
|
|
Arthur Kalliokoski
Second in Command
February 2005
|
Quote: In Windows you can do it with the search window: just place *.* in the filename and then move the results to the directory of your preference. IIRC, you can do the same by emptying the Recycle Bin (to get rid of extraneous files), then send the directory to the Recycle Bin. At least it did that 8-10 years ago when I stopped using it. They all watch too much MSNBC... they get ideas. |
|
BAF
Member #2,981
December 2002
|
What are you talking about Arthur? I don't understand what you are saying to do with the recycling bin. |
|
HoHo
Member #4,534
April 2004
|
I think he deletes stuff and then uses the "restore to" command __________ |
|
CGamesPlay
Member #2,559
July 2002
|
Quote: find some -name '*.zip' -print0 | xargs -0 -i'{}' cp '{}' flat Stop the misinformation! The {} notation is special to find, [edit]
Peter's method still won't work because it preserves directories, though. -- Ryan Patterson - <http://cgamesplay.com/> |
|
kazzmir
Member #1,786
December 2001
|
|
|
CGamesPlay
Member #2,559
July 2002
|
Again with the not working with spaces (Also cp wastes disk space) -- Ryan Patterson - <http://cgamesplay.com/> |
|
Kitty Cat
Member #2,815
October 2002
|
for i in `find somedir -type f` do mv "$i" "place/`basename $i`" done
-- |
|
kazzmir
Member #1,786
December 2001
|
Quote:
Again with the not working with spaces Oh right, forgot the space thing. Stupid bash! I guess you could put in some -print0 garbage like Rey had. |
|
CGamesPlay
Member #2,559
July 2002
|
KittyCat: The for loop is splitting them, not the cp command. -- Ryan Patterson - <http://cgamesplay.com/> |
|
ReyBrujo
Moderator
January 2001
|
Again, find . -type f -name "*.zip" -exec mv {} test \; with test being the directory where you want to put all the zip files. Easy -- |
|
CGamesPlay
Member #2,559
July 2002
|
Quote: find . -type f -name "*.zip" -exec mv {} test \; Err, duh >_< The reason I didn't do that in the most recent use of this script (for me) was because I was doing something like: -- Ryan Patterson - <http://cgamesplay.com/> |
|
Peter Wang
Member #23
April 2000
|
Quote: Peter's method still won't work because it preserves directories, though. No, it doesn't.
|
|
Thomas Fjellstrom
Member #476
June 2000
|
Quote: (Also cp wastes disk space)
cp -l is your friend Quote: find some -type f | while read i; do ln -i "$i" flat/$(echo $i | sed 's///./g'); done find some -type f | while read i; do ln -i "$i" flat/`basename $i`; done ?? -- |
|
|
1
2
|