Copying and Removing Files



next up previous contents index
Next: Alphabetized List of Up: Your Home Directory Previous: Making and Removing

Copying and Removing Files

Unix tries to make life simple for you by having files follow the same naming conventions as directories. That means, though, that it is hard to tell files, directories, and commands apart, so, we use the ls -l, ls -CF, and file commands. The full path name for a file contains all the directories leading up to that file as well as the file name itself. For example, the full path name for the file exam.f, which bohr found above, is /usr/local/class/exam.f. 

The basic commands for manipulating files are cp, mv, and rm. They are defined in Specific Unix Commands and Alphabetized List of Unix Commands. Here we give an example of their use with an undirected make work project undertaken by bohr; we suggest you try them on your terminal, too:

% cd Bohr changes to his home directory.
% pwd And checks where he is.
/u/bohr Voilá, bohr's home directory.
% ls List files in this directory.
% It's empty so we get the prompt back.gif
% mkdir phys Bohr makes directory phys.
% cd phys Change into new directory.
% ls List files in working directory phys.
Empty again.
% cp /usr/local/class/exam.f . Copy exam.f via full path name
directly to current directory, '.'
% ls Check what's there.
exam.f
% mv exam.f myprog.f Rename exam.f to myprog.f.
% ls
myprog.f
% cat myprog.f List contents of myprog.f on screen.
line 1
line 2
... And so forth.
% rm myprog.f Bohr removes myprog.f.
% ls
Nothing is there.

Like a razor, the rm command is simple, quick, and irreversible; both require care.gif



next up previous contents index
Next: Alphabetized List of Up: Your Home Directory Previous: Making and Removing