Keep a folder in a standard state

Aug 16, '01 10:24:24AM

Contributed by: colin

If you want to keep a folder in a standard state (for whatever reason) then the following is one way of doing it (I'm sure there are others). Making the folder read only is another way, but this may not be what you want to do.

(MAKE SURE YOU USE THE CORRECT " ' ` SYMBOLS IN THESE STEPS!)

Create a list of the files in the directory that you want to keep standard e.g. the root level of your hard drive ( '%>' represents the prompt):

%> cd /
%> ls >/filelist
This creates a file at the top level of your hard drive called 'filelist', which we'll use to compare contents to. If you are using this to keep the top level of your hard drive clean then run 'ls >/filelist' twice so the 'filelist' file does not get deleted or moved!).

Now if you execute the commands:
%> cd /
>%> rm -r "`ls | grep -v -x --file=/filelist`"
it will delete all files and folders in root except those listed in the file called "filelist".

or (a safer way to go about cleaning the top level of the hard drive!)
%> cd /
%> mv "`ls | grep -v -x --file=/filelist`" ~/Documents/
which will move all files and folders not listed in the filelist from root to the current logged in users 'Documents' folder (or any other path you care to specify).

One use for this is to make the last example into a shell script that would run at startup (discussed elsewhere on this site) and this would then move all files that had been saved loose on the HD (root) to the users Document folder, thereby keeping the hard drive tidy.

Comments (5)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20010816102424875