0% found this document useful (0 votes)
10 views

Linux Basic

Uploaded by

Hacker 6326
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Linux Basic

Uploaded by

Hacker 6326
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

In this exercise, you will explore the Linux file system and practice exploring

the Filesystem Hierarchy Standard.

1. On the Linux desktop, right-click anywhere and select Open


Terminal Here from the context menu to open a Terminal window.

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 combination of rwx characters in the directory listing are the


permissions associated with each object. As noted earlier, the Linux
file system records the permissions on links, directories, and files.
Permission is granted to owners, groups, and everyone else.
In the case of the /bin pointer, the root user is the owner and has rwx
(read, write, and execute) permission on the link. The root group has
rwx, and everyone else also has rwx. This lax permission makes sense,
as all users need permission to read, write, and execute the standard
Linux tools even if they are not the root user.

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.

Use password as the password. Complete the remaining prompts as


follows:

Full Name: Michael Corleone


Room Number: leave blank
Work Phone: leave blank
Home Phone: leave blank
Other: leave blank

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.

8. At the prompt, type ls -l /home/cybrary and press Enter to see the


permissions granted to the cybrary user.

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:

/etc/hosts - contains local IP to name mappings


/etc/fstab - used to mount and unmount filesystems
/etc/crontab - contains commands that run on a schedule
/etc.rc0.d-rc5.d - contain commands that run at system startup
/etc/netplan - contains networking information on modern Linux
systems

10. At the prompt, type ls /var and press Enter to see where Linux stores
its variable data files.

One of the most important directories in /var is the log directory.

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:

/var/log/dmesg - contains kernel-related messages


/var/log/syslog - contains all system messages (look here first when
there is an issue)
/var/log/auth.log - contains authentication-related logs
/var/log/lastlog - contains a log of all logins to the system
/var/log/wtmp - contains logs of who is currently logged on

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.

Executables and support files are kept under /usr, including:

/usr/bin - where commands are kept and where /bin points to


/usr/sbin - where administrative tools are kept (tools that require
elevated privileges)
/usr/lib - where system libraries are kept (special functions used by
other programs)
/usr/share - where documentation is kept (e.g., man pages)
/usr/local - where admins should compile tools (e.g., using make)

16. At the prompt, type ls /opt and press Enter to view directories under
/opt.

The /opt directory is currently empty. The /opt directory is where


unbundled third-party packages are installed. A popular example is
the Oracle database.

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:

/dev/null can be used as a black hole to dump unwanted output.


/dev/urandom can be used to create random ascii

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.

The name "proc" is short for processes. This directory is removed on


system shutdown and recreated when the system boots up. Notice
there are numbered directories. Each directory represents a running
process (PID) in Linux.
23. Open a second terminal window, then type ps -e and press Enter to
see a list of the active running processes.
Every process ID you see has a corresponding directory under /proc.
You can close the second terminal window when done comparing.

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.

If you haven't already, be sure to answer the questions in the Tasks


tab, then proceed to the challenge exercise.

You might also like