Topics Map > University of Chicago > IT Services > Applications, Operating Systems, & Devices
Basic Unix - Managing Files and Directories
This article describes how to manage files and directories in the Unix operating system.
Unix has a series of commands for copying, moving or renaming, and deleting files. It also has special commands for creating or deleting directories.
To create a subdirectory within your home directory, use the "mkdir" command. For example, to create a directory called Information, type:
mkdir Information <ENTER>
Copying files (cp)
The cp command makes a copy of a specified file. To copy /usr/local/doc/getting-help to a file in your home directory called myhelp, type:
cp /usr/local/doc/getting-help myhelp <ENTER>
Note: if the file name you specify for the new file already exists (in this case, "myhelp"), it will be overwritten by the file you are copying; "cp" has an "-i" (interactive) option which will warn you before overwriting files:
cp -i firstfile secondfile <ENTER>
Renaming and moving files (mv)
A Unix file is renamed by "moving" it from one file name to another using the "mv" command. To rename the file myfile as MyHelpFile, type:
mv myfile MyHelpFile <ENTER>
You can also move a file from one directory to another. To move the file MyHelpFile to the Information
mv MyHelpFile Information <ENTER>
The "mv" command works exactly like "cp," except that the original file is deleted. Like "cp," "mv" has an "-i" option which will warn you if a file with the name you have indicated (in this case, MyHelpFile) already exists.
Deleting files (rm)
To delete a file or files from a directory, use the "rm" command.
Before you start experimenting, however, be aware that "rm" removes files permanently. Unless you are certain that the file is on a system backup (it is older than a week, say, and you have not touched it since), you should treat "rm" with a great deal of caution. To remove the file MyHelpFile from the Information directory, type:
rm -i Information/MyHelpFile <ENTER>
Deleting directories (rmdir)
The "rmdir" command removes a directory. Only empty directories can be deleted. To remove the directory Information, type:
rmdir -i Information <ENTER>