(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 /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!).
%> ls >/filelist
Now if you execute the commands:
%> cd /it will delete all files and folders in root except those listed in the file called "filelist".
>%> rm -r "`ls | grep -v -x --file=/filelist`"
or (a safer way to go about cleaning the top level of the hard drive!)
%> cd /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).
%> mv "`ls | grep -v -x --file=/filelist`" ~/Documents/
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.

