Operating System Information --> Unix (WAM and Glue) --> Unix Utilities --> Unix File Management Commands -->

Unix File Management Commands

These commands will work with most (if not all) distributions of Linux as well as most implementations of Unix. They're the commands that everybody knows. To be able to navigate in Linux, you should become familiar with these.

File Management

cp

Copying works very much the same. The cp command can be used just like the MS-DOS copy command, only remember that directories are separated with slashes (/) instead of backslashes (\). So a basic command line is just cp filename1 filename2.

There are other extensions to the cp command. You can use the -f command to force it. You can use the -p command to preserve the permissions.

You can move an entire directory to its new destination. Let's say you want to copy a directory (and all of its contents) from where you are to be /home/jack/newdirectory/. You would type cp -rpf olddirectory /home/jack/newdirectory. To issue this command you would have to be in the directory where the subdirectory "olddirectory" is actually located.

ln

A feature of linking files is available in Linux. It works by "redirecting" a file to the actual file. It's referred to as a symbolic link. Don't confuse this term with the linking of programs, which is when binary programs are connected with libraries that they need to load in order to run.

The most simple way that I've ever used ln to create symbolic links is ln -s existing_file link. You can also use the -f flag to force the command line to overwrite anything that might have the symbolic link's file name already.

To remove a symbolic link, simply type rm symbolic_link. It won't remove the file that it's linked to.

mv

The mv command can be used both to move files and to rename them. The syntax is mv fileone filetwo, where "fileone" is the original file ame and "filetwo" will be the new file name.

You can't move a directory that is located in one partition to another, unfortunately. You can copy it, though, using cp -rpf, and then remove it with rm -rf later on. If you have only a single partition that makes up your filesystem then you have very little to worry about in this area.

rm

The rm command is used for removing files. Let's say you want to remove a file called foobar in your current directory. To do that, simply type rm foobar.

A good idea is to have rm aliased to rm -i so it will act in the same manner as it does on Wam/Glue accounts.

To delete something in some other directory, use the full path as the file name. For example, if you want to delete a file called "windows" that's in the directory /usr/local/src/, you would type rm /usr/local/src/windows.

To remove an entire directory and its contents, type rm -rf /directory where "/directory" is the path to the directory that you want to delete.

The "rf" stands for "recursive" and "force". Be very careful with this command, as it can wreak havoc easily if misused.

Copyright © 1997-1999 Joshua Go (jtg@computers.iwz.com). All rights reserved. Permission to use, distribute, and copy this document is hereby granted. You may modify this document as long as credit to me is given.

How do I:
How are we doing? Comments on this page?
Office of Information Technology
Office of Information Technology Help Desk Web Site University of Maryland Web Site Office of Information Technology Web Site