Basic Commands in Linux: /root /etc
Basic Commands in Linux: /root /etc
The root (/) of the filesystem is at the top of the tree, and the following
are the most important subdirectories to know:
/root The home directory of the all-powerful root user
/etc Generally contains the Linux configuration files—files that con-
trol when and how programs start up
/home The user’s home directory
/mnt Where other filesystems are attached or mounted to the
filesystem
/media Where CDs and USB devices are usually attached or mounted
to the filesystem
/bin Where application binaries (the equivalent of executables in
Microsoft Windows or applications in macOS) reside
/lib Where you’ll find libraries (shared programs that are similar to
Windows DLLs)
We’ll spend more time with these key directories throughout this book.
Understanding these first-level directories is important to navigating through
the filesystem from the command line.
It’s also important to know before you start that you should not log in
as root when performing routine tasks, because anyone who hacks your
system (yes, hackers sometimes get hacked) when you’re logged in as root
would immediately gain root privileges and thus “own” your system. Log in
as a regular user when starting regular applications, browsing the web, run-
ning tools like Wireshark, and so on. For the practice you’ll do in this book,
staying logged in as root should be fine.
kali >pwd
/root
In this case, Linux returned /root, telling me I’m in the root user’s
directory. And because you logged in as root when you started Linux, you
should be in the root user’s directory, too, which is one level below the top
of the filesystem structure (/).
If you’re in another directory, pwd will return that directory name
instead.
kali >whoami
root
kali >whoami
OTW
6 Chapter 1
line interface, the structure is entirely text based, and navigating the file-
system means using some commands.
kali:/etc >pwd
/etc
To move up one level in the file structure (toward the root of the file
structure, or /), we use cd followed by double dots (..), as shown here:
kali:/etc >cd ..
kali >pwd
/
kali >
This moves us up one level from /etc to the / root directory, but you can
move up as many levels as you need. Just use the same number of double-
dot pairs as the number of levels you want to move:
So, for example, to move up two levels, enter cd followed by two sets of
double dots with a forward slash in between:
You can also move up to the root level in the file structure from any-
where by entering cd /, where / represents the root of the filesystem.
kali >ls
bin initrd.img media run var
This command lists both the files and directories contained in the
directory. You can also use this command on any particular directory, not
just the one you are currently in, by listing the directory name after the
command; for example, ls /etc shows what’s in the /etc directory.
To get more information about the files and directories, such as their
permissions, owner, size, and when they were last modified, you can add
the -l switch after ls (the l stands for long). This is often referred to as
long listing. Let’s try it here:
kali >ls -l
total 84
drw-r--r-- 1 root root 4096 Dec 5 11:15 bin
drw-r--r-- 2 root root 4096 Dec 5 11:15 boot
drw-r--r-- 3 root root 4096 Dec 9 13:10 dev
drw-r--r-- 18 root root 4096 Dec 9 13:43 etc
--snip--
drw-r--r-- 1 root root 4096 Dec 5 11:15 var
If you aren’t seeing a file you expect to see, it’s worth trying ls with the
a flag When using multiple flags, you can combine them into one, as we’ve
done here with -la instead of -l -a.
Getting Help
Nearly every command, application, or utility has a dedicated help file in
Linux that provides guidance for its use. For instance, if I needed help
using the best wireless cracking tool, aircrack-ng, I could simply type the
aircrack-ng command followed by the --help command:
Note the double dash here. The convention in Linux is to use a double
dash (--) before word options, such as help, and a single dash (-) before
single-letter options, such as –h.
8 Chapter 1
When you enter this command, you should see a short description of
the tool and guidance on how to use it. In some cases, you can use either -h
or -? to get to the help file. For instance, if I needed help using the hacker’s
best port-scanning tool, nmap, I would enter the following:
kali >nmap -h
This opens the manual for aircrack-ng, providing you with more
detailed information than the help screen. You can scroll through this
manual file using the ENTER key, or you can page up and down using the
PG DN and PG UP keys, respectively; you can also use the arrow keys. To exit,
simply enter q (for quit), and you’ll return to the command prompt.
Finding Stuff
Until you become familiar with Linux, it can be frustrating to find your way
around, but knowledge of a few basic commands and techniques will go a
long way toward making the command line much friendlier. The following
commands help you locate things from the terminal.
In this case, whereis returned just the aircrack-ng binaries and man page,
rather than every occurrence of the word aircrack-ng. Much more efficient
and illuminating, don’t you think?
Here, which was able to find a single binary file in the directories listed
in the PATH variable. At minimum, these directories usually include /usr/bin,
but may include /usr/sbin and maybe a few others.
10 Chapter 1