You are not logged in.
Pages: 1
A freind and i have several terabytes of data we are trying to organize. Some of it is files that we would like put into folders of the same name. Currently we have to do this by hand for each file/folder. such as:
mkdir file01
mv file01.abc ./file01/
However i believe it is possible to do this in a simpler way. Perhaps using regular expressions, which i know very little of.
I'm looking for a way to take a list of all the file names in a given folder less there extensions, and create a folder for each, then move the files into that folder.
I'd also like to know if there is a simple way to chmod -R 644 all files under a given directory while not affecting directories themselves (because they should be 775)
Hopefully these 2 questions make sense to someone out there. I know what im asking is probably a pretty rare case.
Offline
1.
NB: Is there an easier way to get the basename? basename only seems to work if you actually know the extension
IFS="
"
mkdir $(for file in *; do echo ${file%%.*}; done | sort | uniq)
for dir in *; do [ -d "$dir" ] && mv -v --backup=t "$dir".* "$dir"; done
2.
find -type f -exec chmod 644 '{}' \;
EDIT: Probably want to use some safety with mv (added -v --backup=t)
Last edited by Procyon (2008-12-21 14:44:53)
Offline
2.
find -type f -exec chmod 644 '{}' \;
This is going to be super-inefficient, because find will fork off a chmod for every single file. Try this instead:
find . -type f -print0 | xargs -0 chmod 644
Offline
Good idea, that is definitely an improvement.
You can also do:
IFS="
"
chmod 644 $(find . -type f)
Offline
(I'm apparently feeling really nit-picky today. )
If you've got a massive number of files, you could conceivably exceed the limit on number of command-line arguments using the $( ) formulation. In that case, xargs will do the Right Thing for you. (Where massive is, I believe, on the order of 32k these days. It's a kernel configuration parameter.)
Last edited by tam1138 (2008-12-21 20:50:26)
Offline
Thanks so much guys! The commands worked perfectly, you saved us a good few hours of sorting.
Offline
Pages: 1