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
- 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.
๐๐ก๐๐ญ ๐ข๐ฌ ๐ฅ๐ฌ?
The first command we learn is ๐ฅ๐ฌ. This is the list command. It allows usโฆ list the content of the directory.
๐ฅ๐ฌ is the command we can encounter in all ๐๐ข๐ง๐ฎ๐ฑ and ๐๐ง๐ข๐ฑ ๐ฌ๐ฒ๐ฌ๐ญ๐๐ฆ๐ฌ. We can see it as one of the โ๐๐จ๐ซ๐โ commands in the system.
๐๐ค, ๐ฅ๐๐ญโ๐ฌ ๐ฉ๐ฅ๐๐ฒ ๐ฐ๐ข๐ญ๐ก ๐ข๐ญ ๐ ๐ฅ๐ข๐ญ๐ญ๐ฅ๐.
Run ๐ฅ๐ฌ
What we see on the screen is a ๐ฅ๐ข๐ฌ๐ญ of the content of the current directory.
What is visible immediately, that we have different colors. We can imagine what it means, but letโs forget it for a second. What many waves of โ๐๐ฅ๐๐ฌ๐ฌ๐ข๐โ sys admins saw in their days:
๐ฅ๐ฌ โ ๐๐จ๐ฅ๐จ๐ซ=๐ง๐จ
So, this leads us to the first output, the colorized list of content. In order to have it, we need to run
๐ฅ๐ฌ โ ๐๐จ๐ฅ๐จ๐ซ=๐ฒ๐๐ฌ
or, alternatively for now
๐ฅ๐ฌ โ ๐๐จ๐ฅ๐จ๐ซ=๐๐ฎ๐ญ๐จ .
For now, it will be enough to say, this colorized option is added as default in one place in the system, we will go there in one of the future lessons.
Man Command
This chapter will explain the use of man pages (also called manual pages) on your Unix or Linux computer.
Most Unix files and commands have pretty good man pages to explain their use. Man pages also come in handy when you are using multiple flavours of Unix or several Linux distributions since options and parameters sometimes vary.
1. man $command
Type man followed by a command (for which you want help) and start reading. Press q to quit the manpage. Some man pages contain examples (near the end).
2. man $configfile
Most configuration files have their own manual.
[root@ip-172โ31โ35โ176 ~]# man syslog.conf
Reformatting syslog.conf(5), please waitโฆ
3. man $daemon
This is also true for most daemons (background programs) on your system..
[root@ip-172โ31โ35โ176 ~]# man syslogd
Reformatting syslogd(8), please waitโฆ
4. man -k (apropos)
man -k (or apropos) shows a list of man pages containing a string.
[root@ip-172โ31โ35โ176 ~]# man -k syslog
lm-syslog-setup (8) โ configure laptop mode to switch syslog.conf โฆ logger (1) โ a shell command interface to the syslog(3) โฆ syslog-facility (8) โ Setup and remove LOCALx facility for sysklogd syslog.conf (5) โ syslogd(8) configuration file syslogd (8) โ Linux system logging utilities. syslogd-listfiles (8) โ list system logfiles
5. whatis
To see just the description of a manual page, use whatis followed by a string.
[root@ip-172โ31โ35โ176 ~]# whatis route
route (8) โ show / manipulate the IP routing table.
6. whereis
The location of a manpage can be revealed with whereis.
[root@ip-172โ31โ35โ176 ~]# whereis -m whois
whois: /usr/share/man/man1/whois.1.gz
This file is directly readable by man.
[root@ip-172โ31โ35โ176 ~]# man /usr/share/man/man1/whois.1.gz
7. man sections
By now you will have noticed the numbers between the round brackets. man man will explain to you that these are section numbers. Executable programs and shell commands reside in section one.
8. man $section $file
Therefor, when referring to the man page of the passwd command, you will see it written as passwd(1); when referring to the passwd file, you will see it written as passwd(5). The screenshot explains how to open the man page in the correct section.
[root@ip-172โ31โ35โ176 ~]# man passwd
# opens the first manul found
[root@ip-172โ31โ35โ176 ~]# man 5 passwd
# opens a page from section 5
9. man man
If you want to know more about man, then Read The Fantastic Manual (RTFM). Unfortunately, manual pages do not have the answer to everythingโฆ
10. mandb
Should you be convinced that a man page exists, but you canโt access it, then try running mandb on Debian/Mint.
Or run makewhatis on CentOS/Redhat.