working with directories
This module is a brief overview of the most common commands to work with directories: pwd, cd, ls, mkdir and rmdir. These commands are available on any Linux (or Unix) system. This module also discusses absolute and relative paths and path completion in the bash shell.
- pwd
The you are here sign can be displayed with the pwd command (Print Working Directory). Go ahead, try it: Open a command line interface (also called a terminal, console or xterm) and type pwd. The tool displays your current directory.
2. cd
You can change your current directory with the cd command (Change Directory).
3. cd~
The cd is also a shortcut to get back into your home directory. Just typing cd without a target directory, will put you in your home directory. Typing cd ~ has the same effect
4. cd ..
To go to the parent directory (the one just above your current directory in the directory tree), type cd .. .
To stay in the current directory, type cd . ;-) We will see useful use of the . character representing the current directory later.
5. cd -
Another useful shortcut with cd is to just type cd — to go to the previous directory.
absolute and relative paths
You should be aware of absolute and relative paths in the file tree. When you type a path starting with a slash (/), then the root of the file tree is assumed. If you don’t start your path with a slash, then the current directory is the assumed starting point.
The screenshot below first shows the current directory /root. From within this directory, you have to type cd /home instead of cd home to go to the /home directory.
When inside /home, you have to type cd paul instead of cd /root to enter the subdirectory root of the current directory /home.
This was the last screenshot with pwd statements. From now on, the current directory will often be displayed in the prompt. Later we will explain how the shell variable $PS1 can be configured to show this.