cdThe cd command changes directories. When you open a terminal you will be in your home directory. To move around the file system you will use cd.
- To navigate into the root directory, type:
- To navigate to your home directory, type:
The ~ character represents the current user's home directory. As seen above, cd ~ is equivalent to cd /home/username/. However, when running a command as root (using sudo, for example), ~ points instead to
/root. When running a command with sudo, the full path to your home directory must be given.
- To navigate up one directory level, type:
- To navigate to the previous directory (or back), type:
- To navigate through multiple levels of directories at once, specify the full directory path that you want to go to. For example, type:
cd /var/wwwto go directly to the
/var/. As another example, type:
cd ~/Desktopto move you to the
Desktopsubdirectory inside your home directory.
Desktopdirectory, will show
ls ~will show you the files that are in your home directory.
Used with the -l options, ls outputs various other information alongside the filename, such as the current permissions on the file, and the file's owner.
cp foo barto make an exact copy of
fooand name it
foowill be unchanged.
mv foo barwill rename the file
mv foo ~/Desktopwill move the file
Desktopdirectory but will not rename it.
rm foodeletes the file
foofrom the current directory.
By default, rm will not remove directories. To remove a directory, you must use the -R option. For example,
rm -R foobarwill remove the directory foobar, and all of its contents!
mkdir musicwill create a directory named
musicin the current directory.