Skip to content

Chapter 2: Basic Commands and Directory Hierarchy

Unix commands and shell built-ins

Bear in mind that not everything that executes an action in shell is an Unix command (i.e., it has an executable located in the /bin directory for example). The command cd is an example of shell built-in command.

Command-Line Edditing

Where: page 25

Improve productivity using the command-line key strokes. For example

  • Ctrl+P: Previous Command
  • Ctrl+N: Next Command
  • Ctrl+A: Move to the begin of the line
  • Ctrl+E: Move to the end of the line.

Features of the man command

Search by keyword

man -k keyword

Search with (manual) section information

man 5 passwd # To read the /etc/passwd file description instead of the command passwd(1)

Try the info command

The info command goes even further into the content exposed to a manual page.

info sort

Directory permissions

You can list the contents of a directory if it's readable; but you can only access a file in a directory if the directory is executable. You need both in most cases. (Page 37)

Packing and compression

The tar utility packs multiple files into an archive.

Compression utilities such as gzip compress a single file.

Table-of-content mode in the tar utility

To check the contents of a packed created by the tar utility before extracting them, you can use the command

tar tf archive.tar <my_list_of_files>

This will avoid creating a mess in your working directory due to a badly packed tar file.

A compressed archived file

tar cf archive.tar <my_list_of_files>
gzip archiver.tar

tar zcf archive.tar.gz <my_list_of_files>

Filesystem Hierarchy Standard

The /usr directory is where it is stored files that were created due to user interaction with the system. But not only that, the bulk of the Linux system is stored there and its hierarchy is very similar to the one you find in /. The reason to have a separate directory is to make the root smaller. Therefore, we can say that subdirectories /bin, /lib, /sbin ... contains a subset of the Linux system. It is supposed to be used when initializing the system in a safety mode, for example. If some part of the filesystem gets corrupted, that would be located in the /usr directory.

/usr

It is where most of the user-space programs and data reside. Notice that this directory contains files that compose the Linux system as well. In fact, custom user programs should be located in /usr/local and its structure should be similar to the one you find in / or /usr.

The journal systemd

This is a kind of centralized log in which you can visualise operations done in the system under some categories. For example,

journalctl SYSLOG_IDENTIFIER=sudo

show all operations that were executed using sudo.