Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Keep a folder in a standard state Desktop
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.
    •    
  • Currently 3.00 / 5
  You rated: 3 / 5 (3 votes cast)
 
[2,707 views]  

Keep a folder in a standard state | 5 comments | Create New Account
Click here to return to the 'Keep a folder in a standard state' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
recipe for disaster
Authored by: robh on Aug 20, '01 06:43:43PM

This tip is a recipe for disaster.

What happens the next time you do a system update and the installer puts vital new files in '/' and then does the automatic reboot ?. The startup script would then (re)move the new files and you could spend days trying to sort out the mess, especially if you forget the script is there.

A better tip would be... don't mess with the root dir (/). Don't put your own stuff there and NEVER remove anything from it.



[ Reply to This | # ]
recipe for alphabet soup
Authored by: colin on Aug 21, '01 05:45:36AM

Not so, the script in this state does not affect anything other than things in / , it is not recursive. Software updates etc would be placed in one of the folders that alredy exist e.g. 'System Folder' /var, /etc etc... this is just information that some people may have a use for. if you're not fully sure this script is for you then DON'T USE IT!!!

ls | grep -v -x --file=/filelist > ~/Documents/difference.txt
when used with the rest of this tip will place a text file of the differences found in your documents folder, is this better for you?



[ Reply to This | # ]
recipe for alphabet soup
Authored by: robh on Aug 21, '01 06:12:40AM

>Not so, the script in this state does not affect anything other than things in /

And you can guarantee that Apple will never need to add anything in '/' ?

Here's another scenario where things can go badly wrong..

Let's say that while trying to do the "ls / > filenames" something goes wrong, e.g. the disk fills.
The result will be a truncated list of files. When you then reboot you'll start removing essential files, maybe even the kernel itself.



[ Reply to This | # ]
recipe for smaller portions
Authored by: colin on Aug 21, '01 06:18:55AM

......."ls / > filenames" something goes wrong, e.g. the disk fills.".......
you really have that many files in root? wow. We are talking a tiny file here.. maybe with 'ls -R' it could be a possibility (please don't try puutting this in the example, it won't work), but not a plain 'ls'.



[ Reply to This | # ]
The REAL recipe for disaster...
Authored by: colin on Aug 21, '01 06:27:40AM

I just thought, if people are too dumb to make judgement on how to use a sample command (or not), as you seem to be suggesting, then maybe they are also unable to copy things from here correctly. In light of this please disregard this whole post as forgetting the '-v' switch on the grep will delete/move all the files that ARE listed in the /filelist file and this would be disastrous.



[ Reply to This | # ]