Boston University
Mathematics and Statistics
Mathematics and Statistics
Overview People Courses Programs of Study Seminars Special Programs Events Research Jobs
Mathematics and Statistics
 
next up previous contents
Next: Viewing the Contents Up: Introduction to UNIX Previous: Creating Files and
 

Renaming, Duplicating and Deleting Files and Directories

If you want to make a duplicate of an existing file, use the cp command (it stands for copy). This example has the effect of copying the contents of chapter1.tex into the file named chapter1.revised:

math thesis % cp chapter1.tex chapter1.revised

To duplicate the contents of a directory, use the cp -r command. For example:

math joe % cp -r thesis publication

A new directory will be created called publication, and it will contain copies of all the files that were in the thesis directory.

If you want to rename a file, use the mv command (it stands for move). This example has the effect of making a new file called chapter1-new.tex, placing the contents of chapter1.tex into it, and the removing the old chapter1.tex file:

math thesis % mv chapter1.tex chapter1-new.tex

If you want to delete a file, use the rm command (it stands for remove). This example has the effect of removing a file called junk:

math thesis % rm junk

To remove an empty directory, you need to use the rmdir command:

math joe % rmdir thesis

Note: All of these commands have the potential for deleting files accidently. Recovering files that were accidently removed or overwritten is neither easy nor convenient. Therefore all new accounts in the Math Department have these commands aliased. For example, when a user types rm they automatically use the command rm -i which will ask them to confirm that they want to remove a file. A user must respond with a y to have the file deleted. For example if you accidently type rm RMAIL you have a chance to change your mind before it is deleted:

math joe % rm RMAIL
remove RMAIL? n
math joe % ls
RMAIL* thesis/



next up previous contents
Next: Viewing the Contents Up: Introduction to UNIX Previous: Creating Files and



Tim Kohl
 
September 2004
Mathematics and Statistics
Boston University