Linux Basic
Linux Basic
2. At the prompt, type cd / and press Enter to move to the root of the
Linux directory structure.
3. At the prompt, type ls -l and press Enter to see all the directories
under the root directory in long list format (-l).
The dark blue color of the boot, etc, and home directories indicates
that these are directories. This is also indicated by a "d" in the
directory listing.
The light blue color of the bin, lib, and sbin directories indicates that
these directories are links - specifically, symbolic links. A symbolic link
is a pointer to another file or directory, similar to a shortcut in
Windows (there are some critical differences, but those are beyond
the scope of this lab). A symbolic link is also indicated by an “l”
(lowercase L) in the directory listing.
Note: The /bin directory is where Linux keeps its binaries: command
line tools like ls, pwd, cat, more, less, cd, etc. Modern Linux systems
have moved these files to /usr/bin, but a link is created for backward
compatibility with the FHS.
The "-" symbol indicates that permission is not granted. For example,
everyone has read and execute permission to the /home directory
but not write permission.
Note: The /home directory is where users' files and folders are kept.
When you log in, you are placed first in the
/home/username directory (username being your username). Even
though users do not have write access to the /home directory, they
will have full access to their sub-directory inside /home.
4. At the prompt, type tree / -L 1 and press Enter for another view of
the Linux directory structure.
The "-L 1" command line argument tells the tree command only to
go one level deep. Try -L 2 and -L 3 as well.
Note: The tree command does not come natively with Linux. On
Debian-based Linux distributions, the tree command can be installed
using sudo apt-get install tree -y
5. At the prompt, type sudo tree /home and press Enter to view the
contents of the /home directory.
There are currently two users: cybrary and ubuntu. Notice all the
folders generated for the cybrary user.
6. At the prompt, type sudo adduser michael and press Enter to create
a new user.
7. At the prompt, type sudo tree /home and press Enter to view the
contents of the /home directory.
Notice the michael user has a new home directory named michael.
Note: The additional directories you see under user cybrary are only
created for a user once they log in for the first time.
Note that cybrary is the owner and has rwx (essentially full
permission) on all directories in their home.
9. At the prompt, type ls /etc and press Enter to list the objects in the
/etc directory.
The /etc directory contains critical configuration files for the Linux OS.
Here is just a small sample:
10. At the prompt, type ls /var and press Enter to see where Linux stores
its variable data files.
11. At the prompt, type ls /var/log and press Enter to list the objects in
the /var/log directory.
This is where Linux keeps logs of everything happening on the
system. Notice that some logs end in .gz, indicating they have
been zipped to save space. As logs fill up, Linux will automatically zip
them up. Below are a few of the more essential logs:
Note: you cannot simply open the lastlog log file with a text editor.
You must use the last command to see prior logins. Similarly, you
must use the who command to read the wtmp logs.
12. At the prompt, type sudo last and press Enter to view login
information.
13. At the prompt, type sudo who to see who is currently logged on.
14. At the prompt, type sudo tail -f /var/log/syslog and Enter to watch
live syslog messages.
Because very little is happening on your lab server, the number of
new logs you see may be small - or non-existent. Type CTRL-C to
quit tail.
15. At the prompt, type tree /usr -L 1 and press Enter to view directories
under the /usr directory.
16. At the prompt, type ls /opt and press Enter to view directories under
/opt.
17. At the prompt, type ls /dev and press Enter to view directories under
/dev.
Dev is short for device. In Linux, devices are treated as files. For
example, take note of the “file” called xvda. This "file" is a
representation of the entire hard drive.
18. At the prompt, type sudo fdisk -l | grep xvda and press Enter to list
all drives (fdisk -l) with "xvda" in the name. Take note of the output.
Note: We say “hard disk,” but it’s more likely this is SSD storage in
the cloud.
19. At the prompt, type lsblk and press Enter to list all disks using a
different command.
Other interesting "devices" in /dev include:
Note: The "files" under /dev are device files and are not human-
readable.
20. At the prompt, type ls /mnt and press Enter to view directories under
/mnt.
The name "mnt" is short for mount. This directory is used to mount
other devices, such as a cdrom or USB stick. Currently, the directory is
empty; nothing is mounted on the remote virtual machine.
Note: The FSH wants you to use /media for removable media like
cdroms and USB drives. The /mnt directory should be used for other
storage connections like NFS. That being said, it is very common to
see /mnt used for removable media.
21. At the prompt, type ls / and press Enter to list all directories under
root once more.
Take note of the /root directory, which is the root user's home
directory. Ordinary users cannot view root's home directory, though
the cybrary user can use sudo ls /root. While this is root's directory, it
is not the root ( / ) directory.
22. At the prompt, type ls /proc and press Enter to view the contents of
the /proc directory.
24. In the original terminal window, type ls /boot and press Enter to
display the contents of the /boot directory.
Linux stores important boot files used before the kernel starts any
user-mode programs in this directory.