Protecting Data from Accidental Loss
There are a number of ways to protect your files from accidental
loss:
-
Use the chmod command to remove your own write access to
any files you don't intend to change and want to protect.
You will be unable to accidentally modify such a file in the
future.
If you try to delete a file for which you you have
removed your own write access, without specifying the
-f (force) flag on the rm command,
you will be prompted and
have to reply affirmatively before the file will be removed.
-
Use the chmod command to remove your own write access to any
directories you don't intend to change and want to protect.
This protects all the files in the directory from being
accidentally deleted or modified.
-
Backup your files on another system, an external hard drive,
a flash drive, a CD or a DVD.
-
Make backup copies of directories in compressed tar format.
The tar command creates a single file,
called a tar archive, out of multiple files and compresses
it in a single step.
It is convenient to place all the files and subdirectories
for a single project in a single subdirectory of your
home directory and then tar that directory into
a single compressed tar file.
-
Modify your personal Linux environment to
change the cp, mv, and rm
commands so that you are prompted for confirmation
before any existing file is deleted or overwritten:
-
bash shell:
-
Add the following commands to your $HOME/.bashrc file:
alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -i'
-
tcsh shell:
-
Add the following commands to your $HOME/.cshrc file:
alias cp 'cp -i'
alias mv 'mv -i'
alias rm 'rm -i'
-
Modify your personal Linux environment to
prevent any existing file from being overwritten by the output
redirection (>) symbol.
-
bash shell:
-
Add the following command to your $HOME/.bashrc file:
set -o noclobber
-
tcsh shell:
-
Add the following command to your $HOME/.cshrc file:
set noclobber