Manipulating Directories and Files

IDevice Icon Manipulating Directories and Files

Command

Summary Use

cd

Use cd to change directories. Type cd followed by the name of a directory to access that directory. Keep in mind that you are always in a directory and can navigate to directories hierarchically above or below. Ex:
cd games
If the directory games is not located hierarchically below the current directory, then the complete path must be
written out. Ex:
cd /usr/games
To move up one directory, use the shortcut command. Ex:
cd ..

Use cp -r to copy a directory and all of its contents
Type cp -r followed by the name of an existing directory and the name of the new directory. Ex:
cp -r testing newdir
You must include the -r or you’ll see the following message:
cp: testing is a directory and -r not specified.
This command saves you time if you need to make a mirror image of a directory packed with files.

mkdir

Use mkdir to make/create a brand new directory
Type mkdir followed by the name of a directory. Ex:
mkdir testdir

mv

Use mv to change the name of a directory
Type mv followed by the current name of a directory and the new name of the directory. Ex:
mv testdir newnamedir

pwd

Trying to find out where on your Linux server you currently are located? The pwd (print working directory) command will show you the full path to the directory you are currently in. This is very handy to use, especially when performing some of the other commands on this page!

rmdir

Use rmdir to remove an existing directory (assuming you have permissions set to allow this).
Type rmdir followed by a directory's name to remove it. Ex:
rmdir testdir

You CAN'T remove a directory that contains files with this command. A more useful command is rm -r that removes directories and files within the directories. You can read more about this in Commands for Beginning Admins

The rmdir command is used mostly to remove empty directories. If you have a desire to use this command then you'll need to delete or move the files before attempting to remove a full directory. For more help please read the mv command and also
File Related Commands.