In Unix, when you remove a file or directory, it is gone forever.
In Unix, when you remove a file or directory, it is gone forever.
In Unix, when you remove a file or directory, it is gone forever.
Are we clear on this? The file is not moved to the Trash, where you can go back and retrieve it later. Yes, it is theoretically possible to recover a deleted file, but unless you're with the CIA and have a government agency behind you, don't count on it. (See the sidebar "To Use the Trash from the Command Line.")
To remove a file:
To remove an empty directory:
To remove a directory and everything inside it:
O PTION | M EANING |
---|---|
-d | Remove empty directories as well as files. |
-r | Recursively remove directories and their contents; implies -d . |
-f | Force attempts to override permission restrictions and does not report errors. |
-i | Inquire before removing each file; type a y to confirm. |
Tips
Be extremely careful with rm . Consider moving the file(s) to ~/.TRash instead.
Be especially careful when using wildcards in arguments; for example, rm * would remove every file (except dot files) from the current directory. Think twice before doing that.
Some people like to configure their shells so that rm is always used with the -i option. See Chapter 7 to find out how to create an alias of rm in your shell so that it becomes rm -i .
To Use the Trash from the Command LineWhen you use the Finder, the files you put in the Trash are actually moved into a "hidden" directory in your home directory, called .TRash (in Unix, files whose name starts with a . are not normally displayed). Instead of deleting files, you can move them to the Trash with mv -i filename ~/.TRash The -i (for inquire ) option prompts you before overwriting a file with the same name in the .TRash directory. This is different from the Finder behavior in which the filename of the newly trashed file gets changed, instead of the older trashed file of the same name being deleted. (See Chapter 9, "Creating and Using Scripts," for a script that emulates the Finder behavior.) |