78 The Digital Research Initiative The Digital Research Initiative
The University of North Carolina at Chapel Hill

Part Two

Important Commands

The table below explains commonly used UNIX commands:

Command Function Example
cd dirname Changes current (working) directory to the specified directory. If cd is entered without a specified directory to move to, you are taken to your home directory. cd work
ls -a/-l/-al/-p/-R/-t/-x Lists files in working directory. Typing ls by itself lists the file names alone.
  • The -a flag lists all files, including "hidden" ones.
  • The -l flag includes information about each files size, owner, date of last modification, and other info.
  • The -p flag includes a slash (/) at the end of directory names during listing.
  • The -r flag displays the files in reverse order.
  • The -R flag lists the contents of all directories in the listing.
  • The -t flag displays the files in order of modification date/time.
  • The -x flag displays the files in columns across the screen.
ls -a -l
cp -i/-r oldfile newfile This command makes a copy of a file. You must specify the name of the file to be copied and the name of the new file to be created.
  • The -i flag tells the computer to ask before it overwrites any files in this process.
  • The -r flag copies any files in subdirectories if you are copying directories.
cp -i webpage.html webpage2.html
rm -i/-r filename This command erases the specified file.
  • The -i command asks you for confirmation before a file is deleted.
  • The -r flag erases directories/subdirectories and all the files they may contain.
rm -i work
rmdir -r directoryname This command is for erasing directories.
  • The -r flags allows you to erase a directory and all of its contents. Without this flag, the directory must be empty before you erase it.
rmdir unix
mv -i filename1 filename2 This renames a file.
  • The -i flag asks for confirmation before overwriting a file if you attempt to use to a filename which is already taken. Without the flag, the original file with of the same name will be automatically erased.
mv 1996work 1997work
mv -i filename directoryname/filename This command moves a file to another directory. The flag serves the same purpose as in the other mv command. mv index.html webwork/index.html

Tip:

Two periods (..) represents the above directory. For example, if you are in a directory called work which is under your home directory, you can enter cd .. to move to your home directory. Also, if in your work directory, you have a file called "index.html," you can enter mv index.html ../web to move the file to the web directory, which is on the same level as the work directory in your home directory.

This tip illustrates the importance of drawing a mental map of your UNIX work area. Remember that when a directory contains a subdirectory, the directory is "above" the subdirectory, which is "below" the first directory. For example:


DirectoryA

	Subdirectory1

		Subdirectory2


This site made by
eric
This site was created especially for students of the UNC School of Journalism's
JOMC 050 Class, and anyone else who may be interested.
For more information, please contactdaikat@email.unc.edu