home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam    

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 21.10 Keep a Directory Listing at Top of the Screen: dirtop Chapter 21
More About Managing Files
Next: 21.12 Copying Files to a Directory
 

21.11 Safer Removing, Moving, and Copying

rm
By default, the UNIX utilities rm , mv , and cp do what you tell them to without asking. If that means overwriting existing files or deleting all the files in the directory, they'll do it. If you want more safety, you can add aliases like these to your shell startup files ( 2.2 ) :


C shell
   
ksh
, 
bash

alias rm /bin/rm -i   alias rm='/bin/rm -i'
alias cp /bin/cp -i   alias cp='/bin/cp -i'
alias mv /bin/mv -i   alias mv='/bin/mv -i'

(The pathname /bin/ may be different on your system. You may be able to omit it completely, but watch out for alias loops if you do.) Then, when you type cp or mv at the command line, the command will prompt you before destroying an existing file. And the rm command will always prompt you before every file you ask it to remove (with a wildcard, this can take some time!). These aliases set the -i (interactive) option; most versions of cp , mv , and rm have it.

cp
mv
The GNU versions of cp and mv have -i options. They also have an alternative: the -b option, which automatically makes a backup of any file that will be overwritten.

NOTE: These aliases can be dangerous when you don't have them. If you change to a new shell or use another account without these aliases, you can destroy files before you realize that the aliases aren't there to protect you. So, I don't use any of these aliases on my account. Instead, I check what I type before I press RETURN.

You can override the alias by typing:

% 

\rm *.o

   
C shells


$ 

command rm *.o

   
bash

$ 

/bin/rm *.o

   
Bourne shells

- JP


Previous: 21.10 Keep a Directory Listing at Top of the Screen: dirtop UNIX Power Tools Next: 21.12 Copying Files to a Directory
21.10 Keep a Directory Listing at Top of the Screen: dirtop Book Index 21.12 Copying Files to a Directory

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System










??????????????@Mail.ru