More on rm (or "Oops! I Didn't Really Mean That.")
When you delete a file with Linux, it is gone. If you didn't really mean to delete (or
) a file, it is time to find out if you have been keeping good
rm -i file_name1 file_name2 file_name3
rm : remove 'file_name1'?
If you like to be a bit wordier than that, you can also try
rm --interactive file_name
but that goes against the system administrator's first principle.
Of course, in following that principle, you could remove all the files starting with the word file by using the asterisk:
rm -i file*
Making Your Life Easier with alias
You might find that you want to use the
option every time you delete anything, just in case. It's a lot easier to type Y in confirmation than it is to go looking through your
alias rm='rm -i'
Now every time you execute the
command, it will check with you beforehand. This behavior will only be in effect until you log out. If you want this to be the default behavior for
, you should add the
command to your local
file. If you want this to be the behavior for every
[root@website /root]# alias alias cp='cp -i' alias ls='ls --color' alias mv='mv -i' alias rm='rm -i'
Using the cat command, you can look in your local .bashrc file and discover the same information:
[root@website /root]# cat .bashrc # .bashrc # User specific aliases and functions alias rm='rm -i' alias cp='cp -i' alias mv='mv -i' # Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc fi
Well, isn't this interesting? Notice the two other commands here, the cp (copy files) and mv (rename files) commands, and both have the -i flag as well. They too can be set to work interactively, verifying with you before you overwrite something important. Let's say I want to make a backup copy of a file called important_info using the cp command:
cp important_info important_info.backup
Perhaps what I am actually trying to do is rename the file (rather than copy it). For this, I would use the mv command:
mv important_info not_so_important_info
The only time you would be bothered by an "Are you sure?" type of message is if the file already existed. In that case, you would get a message like the following:
mv: overwrite 'not_so_important_info'?
Forcing the Issue
The answer to the inevitable
Imagine a hypothetical scenario in which you move a
mv -f *.logs /path_to/backup_directory/
The reverse of the