Introduction
In this lab, you will discover how to effectively manage processes within a Linux environment leveraging the at
command. This comprehensive guide delves into exploring the Linux file system hierarchy, mastering file and directory management with essential commands, and demystifying Linux permissions. Gain a deep understanding of the file system hierarchy, its various directories, and their respective functions. Learn to wield commands like ls
, cd
, and chmod
to interact seamlessly with files and directories. This lab provides hands-on examples to elevate your proficiency in process management on a Linux system, a core skill for any aspiring systemadmin.
Explore the Linux File System Hierarchy
This section focuses on the Linux file system structure. You'll learn to navigate the directory tree and understand the role of each directory.
The Linux file system is structured hierarchically, starting from the root directory (/
). Let's start by listing the contents of the root directory:
sudo ls -l /
Example output:
total 80
drwxr-xr-x 2 root root 4096 Apr 18 06:14 bin
drwxr-xr-x 2 root root 4096 Apr 18 06:14 boot
drwxr-xr-x 5 root root 4096 May 11 05:53 dev
drwxr-xr-x 93 root root 4096 May 11 05:53 etc
drwxr-xr-x 3 root root 4096 Apr 18 06:14 home
lrwxrwxrwx 1 root root 33 Apr 18 06:14 initrd.img -> boot/initrd.img-5.15.0-58-generic
drwxr-xr-x 20 root root 4096 Apr 18 06:14 lib
drwxr-xr-x 2 root root 4096 Apr 18 06:14 lib64
drwxr-xr-x 2 root root 4096 Apr 18 06:14 media
drwxr-xr-x 2 root root 4096 Apr 18 06:14 mnt
drwxr-xr-x 2 root root 4096 Apr 18 06:14 opt
dr-xr-xr-x 99 root root 0 May 11 05:53 proc
drwx------ 2 root root 4096 Apr 18 06:14 root
drwxr-xr-x 5 root root 4096 Apr 18 06:14 run
drwxr-xr-x 2 root root 4096 Apr 18 06:14 sbin
drwxr-xr-x 2 root root 4096 Apr 18 06:14 snap
drwxr-xr-x 2 root root 4096 Apr 18 06:14 srv
dr-xr-xr-x 13 root root 0 May 11 05:53 sys
drwxrwxrwt 2 root root 4096 May 11 05:53 tmp
drwxr-xr-x 12 root root 4096 Apr 18 06:14 usr
drwxr-xr-x 14 root root 4096 Apr 18 06:14 var
lrwxrwxrwx 1 root root 30 Apr 18 06:14 vmlinuz -> boot/vmlinuz-5.15.0-58-generic
The root directory houses several key subdirectories, each serving a distinct purpose:
/bin
: Contains essential user command binaries./boot
: Stores files needed for the boot process./dev
: Represents device files for hardware access./etc
: Holds system-wide configuration files./home
: Serves as the parent directory for user home directories./lib
: Contains critical shared libraries and kernel modules./media
: Acts as a mount point for removable media./mnt
: Used for temporarily mounting file systems./opt
: Often used to store optional or third-party software./proc
: A virtual file system exposing kernel and process information./root
: The home directory specifically for the root user./run
: Stores runtime variable data./sbin
: Contains system administration command binaries./srv
: Holds data for services provided by the system./sys
: Another virtual file system, providing access to kernel objects./tmp
: A directory for temporary files./usr
: A secondary hierarchy for read-only user data and applications./var
: Stores variable data, including logs, spool files, and caches.
Dive deeper into these directories and their contents to gain a comprehensive understanding of the Linux file system hierarchy. This knowledge is critical for any systemadmin.
Manage Files and Directories with Essential Commands
This section teaches you how to create, modify, and delete files and directories using fundamental Linux commands. These commands are essential for every systemadmin.
First, create a new directory inside your home directory's project folder:
cd ~/project
mkdir my_directory
Now, enter the newly created directory and create a file within it:
cd my_directory
touch my_file.txt
Confirm that the file has been successfully created:
ls -l
Example output:
total 0
-rw-r--r-- 1 labex labex 0 May 11 06:01 my_file.txt
Next, let's add some content to the file:
echo "This is my file content." > my_file.txt
Display the file's content using the following command:
cat my_file.txt
Example output:
This is my file content.
To create a copy of the file:
cp my_file.txt my_copied_file.txt
To rename the file:
mv my_copied_file.txt my_moved_file.txt
Finally, remove the files and the directory:
rm my_file.txt my_moved_file.txt
rmdir my_directory
Verify that the files and directory have been removed using the list command:
ls -l ~/project
Example output:
total 0
Understand and Use Linux Permissions
This section explores the Linux permission system and how it controls access to files and directories. Mastering Linux permissions is crucial for any systemadmin.
Linux uses a robust permission system to regulate access to files and directories. Each file and directory has three permission types: read, write, and execute. These are assigned to the owner, the group, and all other users.
Create a new file and then examine its permissions:
cd ~/project
touch my_file.txt
ls -l my_file.txt
Example output:
-rw-r--r-- 1 labex labex 0 May 11 06:10 my_file.txt
The permissions are displayed as a 10-character string, with the following meaning:
- The first character indicates the file type ('-' for regular file, 'd' for directory).
- The next 3 characters represent the owner's permissions (read, write, execute).
- The subsequent 3 characters define the group's permissions.
- The final 3 characters indicate the permissions for all other users.
The chmod
command is used to change file permissions. For instance, make the file executable for the owner:
chmod u+x my_file.txt
ls -l my_file.txt
Example output:
-rwxr--r-- 1 labex labex 0 May 11 06:10 my_file.txt
Numeric values can also be used to represent permissions, according to the following:
- 4 represents read permission.
- 2 represents write permission.
- 1 represents execute permission.
- 0 represents no permission.
To set permissions to read-write-execute for the owner, read-execute for the group, and read-only for others:
chmod 754 my_file.txt
ls -l my_file.txt
Example output:
-rwxr-xr- 1 labex labex 0 May 11 06:10 my_file.txt
Lastly, create a directory and configure its permissions:
mkdir my_directory
chmod 755 my_directory
ls -ld my_directory
Example output:
drwxr-xr-x 2 labex labex 4096 May 11 06:10 my_directory
With 755
permissions, the owner has read, write, and execute permissions, while the group and others have read and execute permissions.
Summary
In this lab, you'll begin by exploring the Linux file system hierarchy, learning about different directories and their roles. Then, you'll manage files and directories using essential Linux commands like ls
, cd
, mkdir
, and rm
. Finally, you'll grasp the concept and usage of Linux permissions, including read, write, and execute for files and directories.
This lab covers essential aspects of navigating and managing the Linux file system, foundational skills for any Linux user or system administrator. By the end of this lab, you'll have a solid grasp of the Linux file system structure and the proficiency to work effectively with files and directories through the command line.