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

End-to-End Linux commands sheet for Dev-Ops

The Linux Handbook provides a comprehensive guide to essential Linux commands for file and directory management, as well as system access management. It covers commands for navigating the file system, managing files and directories, and controlling user access and permissions. The document serves as a valuable resource for users looking to effectively utilize Linux in various environments.

Uploaded by

dulamsrinu46
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)
2 views

End-to-End Linux commands sheet for Dev-Ops

The Linux Handbook provides a comprehensive guide to essential Linux commands for file and directory management, as well as system access management. It covers commands for navigating the file system, managing files and directories, and controlling user access and permissions. The document serves as a valuable resource for users looking to effectively utilize Linux in various environments.

Uploaded by

dulamsrinu46
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/ 39

Linux Handbook

| AKHIL THYADI
Linux Commands
📁 1. File & Directory Management
This section covers the essential commands used to interact with the Linux file system. It explains
how to navigate directories, create and manage files and folders, list contents, understand paths
(absolute and relative), and manage permissions. Mastering these commands is fundamental to using
Linux effectively in any environment.

📌 Topics Explained:

• pwd – Displays current working directory.


• ls, ls -a – Lists files and hidden files.
• cd – Changes directory (back, home, specific path).
• mkdir, mkdir -p – Creates directories and nested directories.
• rmdir, rm -rf – Deletes directories (simple and recursive).
• cp, cp -r – Copies files and directories.
• mv – Moves or renames files/directories.
• touch – Creates empty files.
• cat, vi, echo – Viewing, editing, and appending data to files.

1. Present working directory = pwd

user@717e40ca0442:~$ pwd
/home/user

2. List of files = ls

user@717e40ca0442:~$ ls
answer.txt task_1

3. List of all files including hidden files = ls -a

user@717e40ca0442:~$ ls -a
. .. .bash_logout .bashrc .profile answer.txt task_1

4. Change directory to one step back = cd ..

user@717e40ca0442:~$ cd ..
user@717e40ca0442:/home$

5. Helps to change directory to user = cd

user@717e40ca0442:/home$ cd
user@717e40ca0442:~$
Linux Commands
6. Change directory to specific directory = cd <directory>

user@717e40ca0442:~$ cd task_1
user@717e40ca0442:~/task_1$

user@717e40ca0442:~/task_1$ cd-
user@717e40ca0442:~$

7. Create or make directory = mkdir <directory>

user@717e40ca0442:~$ mkdir test


user@717e40ca0442:~$ ls
answer.txt task_1 test

8. Create a directory inside of another directory = mkdir -p test_1/test_2/test_3

user@717e40ca0442:~$ mkdir -p test_1/test_2/test_3

user@717e40ca0442:~$ ls
answer.txt task_1 test test_1
user@717e40ca0442:~$ cd test_1
user@717e40ca0442:~/test_1$ ls
test_2
user@717e40ca0442:~/test_1$ cd test_2
user@717e40ca0442:~/test_1/test_2$ ls
test_3
user@717e40ca0442:~/test_1/test_2$ cd test_3
user@717e40ca0442:~/test_1/test_2/test_3$

user@717e40ca0442:~/test_1/test_2/test_3$ cd
user@717e40ca0442:~$
user@717e40ca0442:~$ cd test_1
user@717e40ca0442:~/test_1$ cd test_2
user@717e40ca0442:~/test_1/test_2$ cd test_3

9. Change directory using path = cd <absolute path>

user@717e40ca0442:~/test_1/test_2/test_3$ cd /home/user
user@717e40ca0442:~$

10. Change directory to root = cd /

user@717e40ca0442:~$ cd /
user@717e40ca0442:/$ ls
bin boot dev ecs-execute-command-59bc2f9b-d05b-44c1-a0e9-801104dbaf2a etc home lib lib32
lib64 libx32 media mnt opt proc root run sbin srv sys tmp usr var
Linux Commands
11. Dictionary or manual of all commands = man <cmnd>

user@717e40ca0442:/$ man ls

12. To run two commands in a single line = <command1>; <command2>; …

user@717e40ca0442:~$ pwd; ls
/home/user
answer.txt task_1 test test_1

13. To remove directory = rmdir <directory_name>

user@717e40ca0442:~$ rmdir test


user@717e40ca0442:~$ ls
answer.txt task_1 test_1

user@717e40ca0442:~$ mkdir -p test/test_2


user@717e40ca0442:~$ ls
answer.txt task_1 test test_1
user@717e40ca0442:~$ rmdir test
rmdir: failed to remove 'test': Directory not empty
# We cannot use rmdir if the directory is not empty, here the test directory is having another directory
inside, rmdir can be used only if the directory is empty

14. To remove a directory recursively and forcefully = rmdir -rf <directory_name>

user@717e40ca0442:~$ rm -rf test


user@717e40ca0442:~$ ls
answer.txt task_1 test_1 # Here the directory is removed forcefully

DANGER
user@717e40ca0442:~$ rm -rf / # It will forcefully delete the directory and files starting from the
user.

15. Change directory to root directory = cd /<directory_name>

user@717e40ca0442:~$ cd /bin

user@d5cc04afe2b3:~$ pwd; ls
/home/user
answer.txt task_1

16. To create a file = touch<file_name>

user@d5cc04afe2b3:~$ touch file


Linux Commands
17. To copy a file if we know it's absolute path = cp <Origin_absolute_path> <Dest_absolute_path>

user@d5cc04afe2b3:/bin$ cp /home/user/file /bin

18. To copy a File if we don't know it's absolute path = cp <Origin_absolute_path> .

user@d5cc04afe2b3:/bin$ cp /home/user/file . # Copying a file from /home/user/file to . ("." means


current location)

user@d5cc04afe2b3:/bin$
user@d5cc04afe2b3:/bin$ cd

19. To copy entire directory or folder to another directory or folder

user@d5cc04afe2b3:~$ cp -r /home /tmp # Copying the home directory recursively and pasting it in
tmp directory
user@d5cc04afe2b3:~$ cd /tmp
user@d5cc04afe2b3:/tmp$ ls
file.zip home setup

20. To copy directory files to another directory or folder without copying the directory

user@d5cc04afe2b3:/tmp$ cp -r /home/* /tmp # * will copy the all files recursively in a directory
and leaves the directory

user@d5cc04afe2b3:/tmp$ ls
file.zip home setup user
user@d5cc04afe2b3:/tmp$ cd user; ls
answer.txt file task_1

21. To move or rename a directory or file from one location to another

user@d5cc04afe2b3:/tmp/home/user$ mv /user/file /user/file_renamed


user@d5cc04afe2b3:/tmp/home/user$ ls
answer.txt file task_1

22. To rename or move any directory from one location to another

user@d5cc04afe2b3:/tmp/home/user$ mv file file_renamed


user@d5cc04afe2b3:/tmp/home/user$ ls
answer.txt file_renamed task_1

23. To create a file = touch <file_name>

user@d5cc04afe2b3:/tmp/home/user$ touch file_name


Linux Commands
24. To edit the file = vi <file_name>

user@d5cc04afe2b3:/tmp/home/user$ vi file_name

25. To read the file = cat <file_name>

user@d5cc04afe2b3:/tmp/home/user$ cat file_name


Hi this is Akhil
I'm working at Amazon

26. To print anything we use = echo

user@d5cc04afe2b3:/tmp/home/user$ echo "my name" >> file_name


user@d5cc04afe2b3:/tmp/home/user$ cat file_name
Hi this is Akhil
I'm working at Amazon
my name

27. To view or read 'N' no of bottom lines in a file = tail -num <file_name>

user@d5cc04afe2b3:/tmp/home/user$ tail -2 file_name


my name
how are you

28. To view or read 'N' no of top lines in a file = head -num <file_name>

user@d5cc04afe2b3:/tmp/home/user$ head -2 file_name


Hi this is Akhil
I'm working at Amazon

29. To view the available memory space = free

user@d5cc04afe2b3:/tmp/home/user$ free
total used free shared buff/cache available
Mem: 3876468 332916 927948 1076 2615604 3251872
Swap: 0 0 0

30. To view the available memory space in human readable format = free -h

user@d5cc04afe2b3:/tmp/home/user$ free -h
total used free shared buff/cache available
Mem: 3.7Gi 325Mi 906Mi 1.0Mi 2.5Gi 3.1Gi
Swap: 0B 0B 0B
Linux Commands
System Access Management
This section is focused on managing users, groups, and access control in a Linux system. It's vital for
ensuring system security and controlling access to files and directories. This is commonly used by
system admins to manage multi-user environments.

📌 Topics Explained:

• whoami – Identifies the current user.


• sudo – Executes commands as a superuser.
• useradd, groupadd – Creates users and groups.
• usermod, userdel, groupdel – Modifies or deletes users/groups.
• passwd – Sets or changes user passwords.
• chown, chmod – Changes ownership and file permissions.
• getfacl, setfacl – Manages Access Control Lists (ACLs).
• /etc/sudoers – Configuration file for granting sudo privileges.

1. To check current user = whoami

user@ddde4a3e1ec3:~$ whoami
user

2. SUDO = Super User Do

# sudo acts like a root user and it has all the permissions like the root user.

3. Create user = sudo useradd <username>

user@ddde4a3e1ec3:~$ sudo useradd scaler


[sudo] password for user:

4. Create group = sudo groupadd <groupname>

user@ddde4a3e1ec3:~$sudo groupadd scaler


[sudo] password for user:

5. Assign user to group = sudo usermod -aG <groupname> <username>

user@ddde4a3e1ec3:~$sudo usermod -aG scaler scaler


[sudo] password for user:

6. Delete user = sudo userdel

user@ddde4a3e1ec3:~$sudo userdel
[sudo] password for user:
Linux Commands
7. Delete group = sudo groupdel

user@ddde4a3e1ec3:~$sudo groupdel
[sudo] password for user:

8. Verify the user details = cat /etc/passwd| grep -i scaler

user@ddde4a3e1ec3:~$ cat /etc/passwd | grep -i scaler

scaler:x:1002:1002::/home/scaler:/bin/sh

9. To search the user details in the list of users = cat /etc/passwd | grep <username>

user@ddde4a3e1ec3:~$ cat /etc/passwd | grep -i scaler


scaler:x:1002:1002::/home/scaler:/bin/sh
# grep command is used to search any keyword in a list and -i flag is for case sensitive
10. Create user password = sudo passwd scaler

user@ddde4a3e1ec3:~$ sudo passwd scaler


New password:
Retype new password:
passwd: password updated successfully

11. Change to new user = su scaler

user@ddde4a3e1ec3:~$ su scaler
Password:
$ whoami
scaler
$ exit

12. To check the history of commands that we used = history

user@ddde4a3e1ec3:~$ history
1 whoami
2 sudo useradd scaler
3 cat /etc/passwd
4 cat /etc/passwd | grep scaler
5 cat /etc/passwd | grep -i scaler
6 sudo passwd scaler
7 su scaler
8 cat /etc/passwd | grep -i scaler
9 history
Linux Commands
13. Shortcut to write any command that we have used earlier in the terminal = Ctrl + R

(reverse-i-search)`ge': getfacl answer.txt # In Terminal press Ctrl + R, it gives this line and we need to
start typing the command and the terminal will suggest the command that we are looking for, which is
called reverse search.
user@63f082294dbc:~$ getfacl answer.txt

14. To check the permissions of files in a directory = ls -ltra

user@ddde4a3e1ec3:~$ ls -ltra
total 20
-rw-r--r-- 1 user user 807 Mar 31 2024 .profile
-rw-r--r-- 1 user user 3771 Mar 31 2024 .bashrc
-rw-r--r-- 1 user user 220 Mar 31 2024 .bash_logout
drwxr-xr-x 1 root root 4096 Sep 6 09:58 ..
drwxr-x--- 2 user user 4096 Sep 6 09:58 .

user@ddde4a3e1ec3:~$ mkdir ubuntu


user@ddde4a3e1ec3:~$ ls -ltra # Listing and checking permissions of all the files in the current
directory
total 28
-rw-r--r-- 1 user user 807 Mar 31 2024 .profile
-rw-r--r-- 1 user user 3771 Mar 31 2024 .bashrc
-rw-r--r-- 1 user user 220 Mar 31 2024 .bash_logout
drwxr-xr-x 1 root root 4096 Sep 6 09:58 ..
drwxrwxr-x 2 user user 4096 Nov 14 09:04 ubuntu
drwxr-x--- 1 user user 4096 Nov 14 09:04 .

15. To change the ownership of a file = sudo chown user_name : group_name <filename>

user@ddde4a3e1ec3:~$ sudo chown scaler:scaler ubuntu


[sudo] password for user:

user@ddde4a3e1ec3:~$ ls -ltra
total 28
-rw-r--r-- 1 user user 807 Mar 31 2024 .profile
-rw-r--r-- 1 user user 3771 Mar 31 2024 .bashrc
-rw-r--r-- 1 user user 220 Mar 31 2024 .bash_logout
drwxr-xr-x 1 root root 4096 Sep 6 09:58 ..
drwxrwxr-x 2 scaler scaler 4096 Nov 14 09:04 ubuntu # The user and group name has changed to
scaler from user
drwxr-x--- 1 user user 4096 Nov 14 09:04 .

16. To change the permissions for files using numeric expression's = sudo chmod 777 <filename>

user@ddde4a3e1ec3:~$ sudo chmod 777 ubuntu


# Here Read(r) = 4, Write(w) = 2, Execute(x) = 1 ; "777" is denoted as setting full permissions to read,
write, execute for the users, groups and others to the directory ubuntu
Linux Commands
user@ddde4a3e1ec3:~$ ls -ltra
total 28
-rw-r--r-- 1 user user 807 Mar 31 2024 .profile
-rw-r--r-- 1 user user 3771 Mar 31 2024 .bashrc
-rw-r--r-- 1 user user 220 Mar 31 2024 .bash_logout
drwxr-xr-x 1 root root 4096 Sep 6 09:58 ..
drwxrwxrwx 2 scaler scaler 4096 Nov 14 09:04 ubuntu
drwxr-x--- 1 user user 4096 Nov 14 09:04 .

17. To change the permissions for files using alphabetic expression's = sudo chmod [ugoa][+-=][rwx]
<filename>

user@63f082294dbc:~$ sudo chmod u-rwx answer.txt


user@63f082294dbc:~$ ls -ltra
total 24
-rw-r--r-- 1 user user 807 Feb 25 2020 .profile
-rw-r--r-- 1 user user 3771 Feb 25 2020 .bashrc
-rw-r--r-- 1 user user 220 Feb 25 2020 .bash_logout
drwxr-xr-x 1 root root 4096 Oct 9 09:59 ..
----rwxrwx 1 root root 0 Nov 14 09:35 answer.txt # Here permissions are changed to no permissions
for user
drwxr-xr-x 1 user user 4096 Nov 14 09:35 .

18. What is a shortcut and how it looks like

user@ddde4a3e1ec3:~$ cd /
user@ddde4a3e1ec3:/$ ls -ltra

total 84
drwxr-xr-x 2 root root 4096 Apr 8 2024 lib.usr-is-merged
drwxr-xr-x 2 root root 4096 Apr 8 2024 sbin.usr-is-merged
drwxr-xr-x 2 root root 4096 Apr 8 2024 bin.usr-is-merged
lrwxrwxrwx 1 root root 8 Apr 22 2024 sbin -> usr/sbin # Here it's a shortcut created to sbin ->
it will re-direct to usr/sbin

19. To set permission for files = setfacl -m u:<username>:<permissions> <filename>


user@63f082294dbc:~$ setfacl -m u:scaler:rw answer.txt # Here I'm giving read and write permissions
for user(u) = scaler over the file answer.txt

20. To get permissions details of all users and groups for any particular file = getfacl <filename>

user@63f082294dbc:~$ getfacl answer.txt # This will give the list of users and groups that have
permissions for this answer.txt file.
Linux Commands
21. To check the user permissions of any file or directory = vi /etc/sudoers

" ============================================================================
" Netrw Directory Listing (netrw v165)
" /etc/sudoers.d
" Sorted by name
" Sort sequence:
[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$
" Quick Help: <F1>:help -:go up dir D:delete R:rename s:sort-by x:special
" ==============================================================================
../
./
README
user
~
~
~
~
~
"/etc/sudoers" [Permission Denied] # But the permission is denied to view

22. To get the permission as a super user or root user here we have to use sudo

user@7b05bce9df89:~$ sudo vi /etc/sudoers # This will give access to view the permission details in
that file

#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset
Defaults mail_badpass
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification


root ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges


Linux Commands
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command


%sudo ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d
~
~
23. To specify the groups and users with specific permission for any particular file we have to Insert

# This file MUST be edited with the 'visudo' command as root.


#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset
Defaults mail_badpass
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification


root ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges


%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command


%sudo ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

scaler ALL=(ALL) ALL NOPASSWD: ALL # For giving sudo access to a user
%groupname scaler ALL=(ALL) ALL NOPASSWD: ALL # For giving sudo access to a group
~
Linux Commands
Interview Question:

Imagine you are a DevOps Engineer and you are asked to setup development environment for new
application project and the project team consists of three things they are Developers, Testers and
Project Managers. You have to ensure that developer has access to the source code, and they can
deploy on the deployment servers, second Testers should have access to the testing environment but
they cannot make any changes to source code and the Project Manager should access to can view the
access reports and the progress but cannot modify anything in the code. You have to Create Groups
according to use case and Create Users and assign Users to Groups and Create Directories like Project,
Testing and Reports. And you have assign correct Ownership and Permissions that will be there to all
these Projects and Directories.

Step 1: Creating Users

user@1ef819edc6f9:~$ sudo useradd Developer


[sudo] password for user:
user@1ef819edc6f9:~$ sudo useradd Tester
user@1ef819edc6f9:~$ sudo useradd Program_manager

# Users are created Developer, Tester, Program_manager

Step 2: Creating Groups

user@1ef819edc6f9:~$ sudo groupadd DEVELOPER


user@1ef819edc6f9:~$ sudo groupadd TESTER
user@1ef819edc6f9:~$ sudo groupadd PROGRAM_MANAGER

# Groups are created DEVELOPER, TESTER, PROGRAM_MANAGER

Step 3: Creating Directories

user@1ef819edc6f9:~$ sudo mkdir -p /home/user/Dev


user@1ef819edc6f9:~$ sudo mkdir -p Test
user@1ef819edc6f9:~$ sudo mkdir -p PM

# Directories are created Dev, Test, PM

user@1ef819edc6f9:~$ pwd
/home/user
user@1ef819edc6f9:~$ ls
Dev PM Test
user@1ef819edc6f9:~$ ls -ltra
total 36
-rw-r--r-- 1 user user 807 Mar 31 2024 .profile
-rw-r--r-- 1 user user 3771 Mar 31 2024 .bashrc
-rw-r--r-- 1 user user 220 Mar 31 2024 .bash_logout
Linux Commands
drwxr-xr-x 1 root root 4096 Sep 6 09:58 ..
drwxr-xr-x 2 root root 4096 Nov 15 09:52 Dev
drwxr-xr-x 2 root root 4096 Nov 15 09:52 Test
drwxr-xr-x 2 root root 4096 Nov 15 09:52 PM
drwxr-x--- 1 user user 4096 Nov 15 09:52 .

# Here we see the Root is the owner of the Directories

Step 4: Setting Groups ownership

user@1ef819edc6f9:~$ sudo chown -R :DEVELOPER /home/user/Dev


user@1ef819edc6f9:~$ sudo chown -R :TESTER /home/user/Test
user@1ef819edc6f9:~$ sudo chown -R :PROGRAM_MANAGER /home/user/PM
user@1ef819edc6f9:~$
user@1ef819edc6f9:~$ ls -ltra
total 36
-rw-r--r-- 1 user user 807 Mar 31 2024 .profile
-rw-r--r-- 1 user user 3771 Mar 31 2024 .bashrc
-rw-r--r-- 1 user user 220 Mar 31 2024 .bash_logout
drwxr-xr-x 1 root root 4096 Sep 6 09:58 ..
drwxr-xr-x 2 root DEVELOPER 4096 Nov 15 09:52 Dev
drwxr-xr-x 2 root TESTER 4096 Nov 15 09:52 Test
drwxr-xr-x 2 root PROGRAM_MANAGER 4096 Nov 15 09:52 PM
drwxr-x--- 1 user user 4096 Nov 15 09:52 .

# Here we see the DEVELOPER, TESTER, PROGRAM_MANAGER Groups are the owners of their
Directories

Step 5: Setting Permissions for Groups to Directories

user@1ef819edc6f9:~$ sudo chmod -R 770 /home/user/Dev


user@1ef819edc6f9:~$ sudo chmod -R 770 /home/user/Test
user@1ef819edc6f9:~$ sudo chmod -R 774 /home/user/PM
user@1ef819edc6f9:~$ ls -ltra
total 36
-rw-r--r-- 1 user user 807 Mar 31 2024 .profile

-rw-r--r-- 1 user user 3771 Mar 31 2024 .bashrc


-rw-r--r-- 1 user user 220 Mar 31 2024 .bash_logout
drwxr-xr-x 1 root root 4096 Sep 6 09:58 ..
drwxrwx--- 2 root DEVELOPER 4096 Nov 15 09:52 Dev
drwxrwx--- 2 root TESTER 4096 Nov 15 09:52 Test
drwxrwxr-- 2 root PROGRAM_MANAGER 4096 Nov 15 09:52 PM
drwxr-x--- 1 user user 4096 Nov 15 09:52 .

# Here the permissions of the Directories are changed respectively


Linux Commands
🔗 LINKS in LINUX
Linux supports two types of file links: symbolic (soft) and hard links. This section explores their
creation, differences, and use cases. Links are a powerful way to reference and access files from
multiple locations without duplicating data.

📌 Topics Explained:

• Soft Link (ln -s) – A shortcut that points to the original file. Breaks if the original file is deleted.
• Hard Link (ln) – A direct reference to the file data on disk. Persists even if the original file is
deleted.
• Use Cases – Managing project dependencies, simplifying navigation, and maintaining backup
copies.

Soft Link
user@ebfc42bdd95d:~$ pwd; ls
/home/user
user@ebfc42bdd95d:~$ mkdir test # Creates a test directory
user@ebfc42bdd95d:~$ vi abc.txt # Creates a file
user@ebfc42bdd95d:~$ ls
abc.txt test
user@ebfc42bdd95d:~$ cd test/
user@ebfc42bdd95d:~/test$ ls # Nothing is present inside of test directory
user@ebfc42bdd95d:~/test$ ln -s /home/user/abc.txt /home/user/test/xyz.txt # Creating a link file
named xyz.txt of abc.txt file in test directory
user@ebfc42bdd95d:~/test$ ls -ltra
total 8
drwxr-x--- 1 user user 4096 Nov 15 10:19 ..
lrwxrwxrwx 1 user user 18 Nov 15 10:19 xyz.txt -> /home/user/abc.txt # Here it clearly shows that
xyz.txt is a link of original file abc.txt
drwxrwxr-x 2 user user 4096 Nov 15 10:19 .

user@ebfc42bdd95d:~/test$ rm /home/user/abc.txt # Removing the original abc.txt file


user@ebfc42bdd95d:~/test$ ls -ltra
total 8
lrwxrwxrwx 1 user user 18 Nov 15 10:19 xyz.txt -> /home/user/abc.txt # It clearly shows that the link
is also expired
drwxrwxr-x 2 user user 4096 Nov 15 10:19 .
drwxr-x--- 1 user user 4096 Nov 15 10:20 ..
Linux Commands
Hard Link
user@ebfc42bdd95d:~$ vi hard_link_original.txt
user@ebfc42bdd95d:~$ ln /home/user/hard_link_original.txt /home/user/test/hard_link_copy.txt
# Hard link is created for the file hard_link_original in the test directory naming as hard_link_copy

user@ebfc42bdd95d:~$ ls -ltra
total 36
-rw-r--r-- 1 user user 807 Mar 31 2024 .profile
-rw-r--r-- 1 user user 3771 Mar 31 2024 .bashrc
-rw-r--r-- 1 user user 220 Mar 31 2024 .bash_logout
drwxr-xr-x 1 root root 4096 Sep 6 09:58 ..
lrwxrwxrwx 1 user user 18 Nov 15 10:19 xyz.txt -> /home/user/abc.txt
-rw-rw-r-- 1 user user 9 Nov 15 10:21 hard_link_original.txt # Hard link original file is present in
/home/user
-rw------- 1 user user 1014 Nov 15 10:21 .viminfo
drwxr-x--- 1 user user 4096 Nov 15 10:21 .
drwxrwxr-x 2 user user 4096 Nov 15 10:22 test

user@ebfc42bdd95d:~$ ls
hard_link_original.txt test xyz.txt

user@ebfc42bdd95d:~$ cd test/
user@ebfc42bdd95d:~/test$ ls -ltra
total 8
lrwxrwxrwx 1 user user 18 Nov 15 10:19 xyz.txt -> /home/user/abc.txt
drwxr-x--- 1 user user 4096 Nov 15 10:21 ..
lrwxrwxrwx 1 user user 33 Nov 15 10:22 hard_link_copy.txt -> /home/user/hard_link_original.txt
# Hard link copy file is present in /home/user/test
lrwxrwxrwx 1 user user 33 Nov 15 10:22 hard_link_copy.txt
drwxrwxr-x 2 user user 4096 Nov 15 10:22 .

user@ebfc42bdd95d:~/test$ cd ..
user@ebfc42bdd95d:~$ rm hard_link_original.txt # removing the hard_link_original.txt file
user@ebfc42bdd95d:~$ cd test/
user@ebfc42bdd95d:~/test$ ls -ltra
total 8
lrwxrwxrwx 1 user user 18 Nov 15 10:19 xyz.txt -> /home/user/abc.txt
lrwxrwxrwx 1 user user 33 Nov 15 10:22 hard_link_copy.txt -> /home/user/hard_link_original.txt
# Hence after deleting the hard_link_original_file the replica or exact copy is present in test directory
without getting deleted
lrwxrwxrwx 1 user user 33 Nov 15 10:22 hard_link_copy.txt
drwxrwxr-x 2 user user 4096 Nov 15 10:22 .
drwxr-x--- 1 user user 4096 Nov 15 10:24 ..

user@f26bf64d9bce:~$ pwd # pwd gives the location of where am 'I currently


/home/user
Linux Commands
user@f26bf64d9bce:~$ pp # pp is not a command and throws an error but I want to use it instead of
pwd
bash: pp: command not found

user@f26bf64d9bce:~$ alias pp='pwd' # This will create a alias for pwd as pp


user@f26bf64d9bce:~$ pp # Now pp is also giving me the same output as pwd.
/home/user

Interview Questions:

1. I'm trying to create an empty directory, but I'm unable to create it what is the issue ?
A. Inodes

Inodes are the data structures that stores information about files and directories, for suppose in our
system if there is any program where it is creating faulty temporary files which are very minimum of
size just in bytes. At some point of time one of our file stopped writing the log files but there is enough
space but unable to write logs. Where this new file creating faulty temporary files where space is not
exhausted but Inodes got exhausted this leads to send an error while creating a new directory.
Command: df -I # this will give the entire details about Inodes

2. what is bashrc and why it is used ?

bashrc is a hidden file in system, whenever we run a new terminal it will start in the interactive mode
in the bashrc and in the bashrc whatever configurations are there the shell will taking those
configurations and runs it

3. what is alias and why it is used?

Alias are used to rename and write any command as we want.


Linux Commands
Process Management
Managing processes is crucial in Linux. This section dives into monitoring, controlling, and optimizing
system processes and jobs. It's especially useful for performance tuning, automation, and ensuring
system stability.

📌 Topics Explained:

• ps, ps aux, ps -ef – View running processes.


• top, htop – Real-time process monitoring.
• nice, renice – Adjusts process priority.
• kill, pgrep, fg, bg – Manage background and foreground jobs.
• sleep, jobs – Simulate and control tasks.
• Ipcs – Displays IPC resources like semaphores and message queues.
• alias – Create command shortcuts for productivity.

1. Process status = ps

user@bb0e91c81fda:~$ ps
PID TTY TIME CMD
145 pts/1 00:00:00 sh
146 pts/1 00:00:00 bash
496 pts/1 00:00:00 ps

2. List all Processes = ps aux

user@bb0e91c81fda:~$ ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 1136 512 ? Ss 06:46 0:00 /sbin/docker-init -- /usr/bin/tini --
/usr/local/bin/j
root 62 0.0 0.0 2504 1408 ? S 06:46 0:00 /usr/bin/tini -- /usr/local/bin/judge/setup.sh
root 63 0.0 0.0 3984 3072 ? S 06:46 0:00 /bin/bash /usr/local/bin/judge/setup.sh
root 73 0.0 0.4 1757316 15788 ? Ssl 06:46 0:00 /ecs-execute-command-e264bcc5-2940-
4fd2-91c9-06543307a
root 99 0.0 0.0 4524 2816 ? S 06:46 0:00 su - user -c ttyd -W -p 7681 --ping-interval 45 -t
fon
user 101 0.0 0.0 2616 1536 ? Ss 06:46 0:00 -sh -c ttyd -W -p 7681 --ping-interval 45 -t
fontSize=
user 105 0.0 0.0 10116 1280 ? Rl 06:46 0:00 ttyd -W -p 7681 --ping-interval 45 -t fontSize
16 bash
root 129 0.0 0.6 1766992 26032 ? Sl 06:46 0:00 /ecs-execute-command-e264bcc5-2940-
4fd2-91c9-06543307a
root 140 0.0 0.0 2552 1408 ? S 06:46 0:00 tail -f /dev/null
user 141 0.0 0.0 4116 3328 pts/0 Ss+ 06:46 0:00 bash
Linux Commands
user 144 0.0 0.0 2644 1920 pts/0 R+ 06:46 0:00 script -a -q -f -o 500M
/mnt/.script_logs/script.log -
user 145 0.0 0.0 2616 1536 pts/1 Ss 06:46 0:00 sh -c bash
user 146 0.0 0.0 4248 3456 pts/1 S 06:46 0:00 bash
user 333 0.0 0.0 5900 2816 pts/1 R+ 06:51 0:00 ps aux

3. Full list of processes with details = ps -ef

user@bb0e91c81fda:~$ ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 06:46 ? 00:00:00 /sbin/docker-init -- /usr/bin/tini --
/usr/local/bin/judge/setup.sh
root 62 1 0 06:46 ? 00:00:00 /usr/bin/tini -- /usr/local/bin/judge/setup.sh
root 63 62 0 06:46 ? 00:00:00 /bin/bash /usr/local/bin/judge/setup.sh
root 73 0 0 06:46 ? 00:00:00 /ecs-execute-command-e264bcc5-2940-4fd2-91c9-
06543307ae13/amazon-ssm-
root 99 63 0 06:46 ? 00:00:00 su - user -c ttyd -W -p 7681 --ping-interval 45 -t fontSize=16
bash
user 101 99 0 06:46 ? 00:00:00 -sh -c ttyd -W -p 7681 --ping-interval 45 -t fontSize=16 bash
user 105 101 0 06:46 ? 00:00:00 ttyd -W -p 7681 --ping-interval 45 -t fontSize 16 bash
root 129 73 0 06:46 ? 00:00:00 /ecs-execute-command-e264bcc5-2940-4fd2-91c9-
06543307ae13/ssm-agent-w
root 140 63 0 06:46 ? 00:00:00 tail -f /dev/null
user 141 105 0 06:46 pts/0 00:00:00 bash
user 144 141 0 06:46 pts/0 00:00:00 script -a -q -f -o 500M /mnt/.script_logs/script.log --
timing=/dev/nu
user 145 144 0 06:46 pts/1 00:00:00 sh -c bash
user 146 145 0 06:46 pts/1 00:00:00 bash
user 345 146 0 06:51 pts/1 00:00:00 ps -ef

4. To view running processes = top

user@f26bf64d9bce:~$ top
# Top command gives information about running process like process ID(PID), priority(PR),
Niceness(NI), Memory percentage(%MEM)

top - 12:16:18 up 1:06, 1 user, load average: 0.01, 0.02, 0.00


Tasks: 18 total, 1 running, 17 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
MiB Mem : 3785.6 total, 984.9 free, 629.7 used, 2471.1 buff/cache
MiB Swap: 0.0 total, 0.0 free, 0.0 used. 3155.9 avail Mem

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND


1 root 20 0 20656 11896 9720 S 0.0 0.3 0:00.68 systemd
86 root 20 0 1831048 16092 9600 S 0.0 0.4 0:00.14 amazon-ssm-agen
393 root 20 0 18376 7552 6656 S 0.0 0.2 0:00.03 systemd-journal
484 root 20 0 4860 3456 3200 S 0.0 0.1 0:00.00 setup.sh
521 root 20 0 1766992 26040 15616 S 0.0 0.7 0:00.17 ssm-agent-worke
Linux Commands
533 root 20 0 6816 4352 3968 S 0.0 0.1 0:00.00 su
551 message+ 20 0 9428 5248 4736 S 0.0 0.1 0:00.01 dbus-daemon
566 root 20 0 17880 8704 7808 S 0.0 0.2 0:00.24 systemd-logind
849 user 20 0 19904 11008 9344 S 0.0 0.3 0:00.03 systemd
860 user 20 0 21148 3388 1664 S 0.0 0.1 0:00.00 (sd-pam)
906 user 20 0 2800 1664 1664 S 0.0 0.0 0:00.00 sh
909 user 20 0 1352 768 768 S 0.0 0.0 0:00.14 ttyd
919 root 20 0 3156 1792 1792 S 0.0 0.0 0:00.07 tail
920 user 20 0 4752 3584 3328 S 0.0 0.1 0:00.00 bash
922 user 20 0 3144 2048 1920 S 0.0 0.1 0:00.06 script
923 user 20 0 2800 1664 1664 S 0.0 0.0 0:00.00 sh
924 user 20 0 5016 4096 3584 S 0.0 0.1 0:00.01 bash
1026 user 20 0 9288 5632 3584 R 0.0 0.1 0:00.00 top

5. Process Grep = pgrep <process_name>

user@bb0e91c81fda:~$ pgrep sh
63
101
141
145
146
user@bb0e91c81fda:~$ pgrep ttyd
105
user@bb0e91c81fda:~$ pgrep docker-init
1

6. To change the priority of running processes

user@f26bf64d9bce:~$ nice 19 <PID>


# This will set a new process with lowest priority as lowest niceness value is 19

user@f26bf64d9bce:~$ renice -20 <PID>


# This will reset an existing process with highest priority as highest niceness value is -20

7. Creating simple jobs using sleep = sleep <sec> &

user@bb0e91c81fda:~$ sleep 100 &


[1] 430

8. To run a job to the Background = bg %<PID>

user@bb0e91c81fda:~$ bg %1
bash: bg: job 1 already in background
Linux Commands
9. To bring a job to the Foreground = fg %<PID>

user@bb0e91c81fda:~$ fg %1
sleep 100

10. What is Signal and it's types

user@f26bf64d9bce:~$ kill -l
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP
6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1
11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM
16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP
21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ
26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR
31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3
38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8
43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7
58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2
63) SIGRTMAX-1 64) SIGRTMAX

11. To kill a Process = kill <PID>

user@f26bf64d9bce:~$ kill 20
user@f26bf64d9bce:~$ kill -9 20 # This will kill any PID forcefully

12. What is Pipe and how it is used

Pipe is used for the output of one program will be an input to another program
in terminal 1
user@f26bf64d9bce:~$ echo "rat" > pipe
in terminal 2
user@f26bf64d9bce:~$ less < pipe # the output of terminal 1 is reflected to terminal 2
rat

in terminal 1
user@f26bf64d9bce:~$ echo "rat_1" > pipe
in terminal 2
user@f26bf64d9bce:~$ tee output.log < pipe | tail -f # the output of terminal 1 is reflected to
terminal 2
rat_2
Linux Commands
13. To show active IPC(Inter Process Communication's) resources to show message queues, shared
memory segments, semaphore array

user@f26bf64d9bce:~$ ipcs

------ Message Queues --------


key msqid owner perms used-bytes messages

------ Shared Memory Segments --------


key shmid owner perms bytes nattch status

------ Semaphore Arrays --------


key semid owner perms nsems

user@f26bf64d9bce:~$ ipcs -m # Gives information about memory usage

------ Shared Memory Segments --------


key shmid owner perms bytes nattch status

user@f26bf64d9bce:~$ ipcs -q # Gives information about message queues

------ Message Queues --------


key msqid owner perms used-bytes messages

Interview Questions:

Q. How do you handle high CPU utilization, You receive an alert on your machine there is high CPU
utilization at the same time you receive message from one of the management people that some
tasks are blocked. How will you tackle the both tasks at a time.

I will be using top command from "top" command what are the processes running what are the top
processes that consuming high CPU, I will see whether these processes are expected or not, I will see
whether these processes are system generated or cron jobs running or batch processes are running.
Now then I will see whether it is critical or not, this job it might be a possibility that some of the cron
jobs run during peak times which are might not important, I will kill those job for that particular time
and restart them after the peak time to reduce the load on the CPU.

The other scenario receiving messages from management there is an high priority tasks that needs to
be take care, I will increase niceness of that tasks to -5 or -10 or -15 based on other processes
niceness.
Linux Commands
Memory & Storage Management
This section discusses how to monitor and optimize system memory and storage in Linux. Efficient
memory management ensures better performance and reliability, especially in production or resource-
constrained systems.

📌 Topics Explained:

• free, vmstat, top, smem – Memory usage analysis tools.


• cat /proc/meminfo – Detailed memory statistics.
• drop_caches – Clears system cache for performance tuning.
• pmap, pidstat, sar, dmesg – Advanced resource and kernel usage tracking.
• df, du – Disk usage statistics (if not included, we can add them).

1. Displays the system's memory usage = free -h

user@934cc9d6b341:~$ free -h
total used free shared buff/cache available
Mem: 3.7Gi 743Mi 231Mi 3.4Mi 3.0Gi 3.0Gi
Swap: 0B 0B 0B

2. To provide summary of memory, CPU, and I/O usage we use virtual memory statatics
= vmstat 1 5

# Updates every second, 5 times

user@934cc9d6b341:~$ vmstat 1 5
procs -----------memory---------- ---swap-- -----io---- -system-- -------cpu-------
r b swpd free buff cache si so bi bo in cs us sy id wa st gu
2 0 0 230260 128428 3057824 0 0 24604 150644 210996 7 1 1 98 1 0 0
0 0 0 230260 128428 3057824 0 0 0 132 574 1039 0 0 100 0 0 0
0 0 0 230260 128428 3057824 0 0 0 0 516 967 1 0 99 0 0 0
0 0 0 230260 128428 3057824 0 0 0 0 468 891 0 0 100 0 0 0
0 0 0 230260 128428 3057824 0 0 0 148 537 952 0 0 99 0 0 0

3. To Display memory usage by processes in real time = top

user@934cc9d6b341:~$ top
top - 16:16:53 up 0 min, 1 user, load average: 0.04, 0.05, 0.06
Tasks: 18 total, 1 running, 17 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.3 us, 0.3 sy, 0.0 ni, 99.4 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
MiB Mem : 3785.6 total, 233.2 free, 743.1 used, 3111.0 buff/cache
MiB Swap: 0.0 total, 0.0 free, 0.0 used. 3042.5 avail Mem

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND


Linux Commands
1 root 20 0 20764 11844 9668 S 0.0 0.3 0:00.11 systemd
84 root 20 0 1830152 14976 9472 S 0.0 0.4 0:00.04 amazon-ssm-agen
404 root 20 0 18364 7808 7040 S 0.0 0.2 0:00.02 systemd-journal
497 root 20 0 4860 3456 3200 S 0.0 0.1 0:00.00 setup.sh
555 root 20 0 1766992 27648 15616 S 0.0 0.7 0:00.06 ssm-agent-worke
769 message+ 20 0 9428 5120 4608 S 0.0 0.1 0:00.01 dbus-daemon
782 root 20 0 17880 8704 7808 S 0.0 0.2 0:00.28 systemd-logind
1063 root 20 0 6816 4352 3968 S 0.0 0.1 0:00.00 su
1100 user 20 0 19904 11008 9472 S 0.0 0.3 0:00.03 systemd
1112 user 20 0 21148 3520 1792 S 0.0 0.1 0:00.00 (sd-pam)
1156 user 20 0 2800 1664 1664 S 0.0 0.0 0:00.00 sh
1159 user 20 0 1352 768 768 S 0.0 0.0 0:00.00 ttyd
1169 root 20 0 3156 1792 1792 S 0.0 0.0 0:00.00 tail
1170 user 20 0 4884 3968 3584 S 0.0 0.1 0:00.00 bash
1172 user 20 0 3144 2176 2048 S 0.0 0.1 0:00.00 script
1173 user 20 0 2800 1664 1664 S 0.0 0.0 0:00.00 sh
1174 user 20 0 5016 4224 3712 S 0.0 0.1 0:00.00 bash
1179 user 20 0 9288 5504 3456 R 0.0 0.1 0:00.00 top

4. File that contains detailed memory statistics = cat/proc/meminfo

user@934cc9d6b341:~$ cat /proc/meminfo


MemTotal: 3876468 kB
MemFree: 598840 kB
MemAvailable: 3089676 kB
Buffers: 125992 kB
Cached: 2393804 kB
SwapCached: 0 kB
Active: 445364 kB
Inactive: 2368200 kB
Active(anon): 170264 kB
Inactive(anon): 143972 kB
Active(file): 275100 kB
Inactive(file): 2224228 kB
Unevictable: 35476 kB
Mlocked: 27628 kB
SwapTotal: 0 kB
SwapFree: 0 kB
Zswap: 0 kB
Zswapped: 0 kB
Dirty: 28 kB
Writeback: 0 kB
AnonPages: 329244 kB
Mapped: 307612 kB
Shmem: 3556 kB
KReclaimable: 280088 kB
Slab: 363560 kB
Linux Commands
SReclaimable: 280088 kB
SUnreclaim: 83472 kB
KernelStack: 8096 kB
PageTables: 9332 kB
SecPageTables: 0 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 1938232 kB
Committed_AS: 3781596 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 21000 kB
VmallocChunk: 0 kB
Percpu: 1512 kB
HardwareCorrupted: 0 kB
AnonHugePages: 0 kB
ShmemHugePages: 0 kB
ShmemPmdMapped: 0 kB
FileHugePages: 0 kB
FilePmdMapped: 0 kB
Unaccepted: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
Hugetlb: 0 kB
DirectMap4k: 131504 kB
DirectMap2M: 3938304 kB
DirectMap1G: 0 kB

5. To get detailed memory usage per process, including shared memory = smem

user@934cc9d6b341:~$ smem

PID User Command Swap USS PSS RSS


1173 user sh -c bash 0 100 182 1904
1156 user -sh -c ttyd -W -p 7681 --pi 0 124 205 1896
1172 user script -a -q -f -o 500M /mn 0 140 234 2220
1159 user ttyd -W -p 7681 --ping-inte 0 96 484 876
1170 user bash 0 488 813 4112
1174 user bash 0 628 964 4360
1179 user top 0 2356 2632 5660
3895 user /usr/bin/python3 /usr/bin/s 0 12472 13515 14700
Linux Commands
6. To view cache and buffer usage = free -h

user@934cc9d6b341:~$ free -h
total used free shared buff/cache available
Mem: 3.7Gi 789Mi 326Mi 3.5Mi 2.9Gi 2.9Gi
Swap: 0B 0B 0B

7. Clear cache (requires root privileges)

user@934cc9d6b341:~$ sudo sync # Synchronize cached writes to disk


user@934cc9d6b341:~$ sudo echo1 > /proc/sys/vm/drop_caches # Clear page cache
user@934cc9d6b341:~$ sudo echo2 > /proc/sys/vm/drop_caches # Clear dentries and inodes
user@934cc9d6b341:~$ sudo echo3 > /proc/sys/vm/drop_caches # Clear all caches

8. Displays memory usage by processes = ps aux --sort=-%mem | head

user@934cc9d6b341:~$ ps aux --sort=-%mem | head


USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 555 0.0 0.6 1840724 25860 ? Sl 16:16 0:00 /ecs-execute-command-7a09e356-b20c-
4bd4-bd7d-a33ed0c13303/ssm-agent-worker
root 84 0.0 0.4 1831048 16092 ? Ssl 16:16 0:00 /ecs-execute-command-7a09e356-b20c-
4bd4-bd7d-a33ed0c13303/amazon-ssm-agent
root 1 0.0 0.3 20952 12160 ? Ss 16:16 0:00 /usr/lib/systemd/systemd --system --
deserialize=49
user 1100 0.0 0.2 19904 11008 ? Ss 16:16 0:00 /usr/lib/systemd/systemd --user
root 782 0.0 0.2 18012 8704 ? Ss 16:16 0:00 /usr/lib/systemd/systemd-logind
root 404 0.0 0.2 18364 7808 ? Ss 16:16 0:00 /usr/lib/systemd/systemd-journald
user 1179 0.0 0.1 9288 5504 pts/1 T 16:16 0:00 top
message+ 769 0.0 0.1 9428 5120 ? Ss 16:16 0:00 @dbus-daemon --system --
address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
root 1063 0.0 0.1 6816 4352 ? S 16:16 0:00 su - user -c ttyd -W -p 7681 --ping-interval 45
-t fontSize=16 bash

9. To report memory usage for a specific process = pmap <PID>

user@934cc9d6b341:~$ pmap 555


555: /ecs-execute-command-7a09e356-b20c-4bd4-bd7d-a33ed0c13303/ssm-agent-worker
user@934cc9d6b341:~$ pmap 1100
1100: /usr/lib/systemd/systemd --user

10. Displays resource usage by processes = pidstat -r -p ALL

user@934cc9d6b341:~$ pidstat -r -p ALL


Linux 6.5.0-1023-aws (934cc9d6b341) 01/17/25 _x86_64_ (2 CPU)

16:43:16 UID PID minflt/s majflt/s VSZ RSS %MEM Command


16:43:16 0 1 6.04 0.00 21024 12288 0.32 systemd
Linux Commands
16:43:16 0 84 2.74 0.00 1831048 16092 0.42 amazon-ssm-agen
16:43:16 0 404 0.65 0.00 18364 7808 0.20 systemd-journal
16:43:16 0 497 0.63 0.00 4860 3456 0.09 setup.sh
16:43:16 0 555 2.39 0.00 1840724 25860 0.67 ssm-agent-worke
16:43:16 100 769 0.46 0.00 9428 5120 0.13 dbus-daemon
16:43:16 0 782 0.64 0.00 18012 8704 0.22 systemd-logind
16:43:16 0 1063 0.20 0.00 6816 4352 0.11 su
16:43:16 1001 1100 0.84 0.00 19904 11008 0.28 systemd
16:43:16 1001 1112 0.03 0.00 21148 3520 0.09 (sd-pam)
16:43:16 1001 1156 0.12 0.00 2800 1664 0.04 sh
16:43:16 1001 1159 3.55 0.00 1352 768 0.02 ttyd
16:43:16 0 1169 0.07 0.00 3156 1792 0.05 tail
16:43:16 1001 1170 0.16 0.00 4884 3968 0.10 bash
16:43:16 1001 1172 0.08 0.00 3144 2176 0.06 script

11. Check for memory-related kernel messages = dmesg | grep -i memory

user@934cc9d6b341:~$ dmesg | grep -i memory

12. Historical memory usage statistics = sar -r 1 5

user@934cc9d6b341:~$ sar -r 1 5
Linux 6.5.0-1023-aws (934cc9d6b341) 01/17/25 _x86_64_ (2 CPU)

16:45:28 kbmemfree kbavail kbmemused %memused kbbuffers kbcached kbcommit %commit


kbactive kbinact kbdirty
16:45:29 324232 3066512 411908 10.63 151820 2585508 3875596 99.98 534928
2504052 48
16:45:30 324232 3066512 411908 10.63 151820 2585508 3875596 99.98 535004
2504052 40
16:45:31 324232 3066512 411908 10.63 151820 2585508 3875596 99.98 535068
2504052 44
16:45:32 324232 3066512 411908 10.63 151820 2585508 3875596 99.98 534432
2504052 72
16:45:33 324232 3066512 411924 10.63 151820 2585508 3875596 99.98 534524
2504052 8
Average: 324232 3066512 411911 10.63 151820 2585508 3875596 99.98 534791
2504052 42

13. Displays disk usage of files and directories = du -sh

user@934cc9d6b341:~$ du -sh
24K .

14. Shows available and used disk space for mounted filesystems = df -h

user@934cc9d6b341:~$ df -h
Linux Commands
Filesystem Size Used Avail Use% Mounted on
overlay 29G 12G 18G 39% /
tmpfs 64M 0 64M 0% /dev
tmpfs 64M 876K 64M 2% /run
tmpfs 4.0M 0 4.0M 0% /run/lock
shm 64M 0 64M 0% /dev/shm
/dev/root 29G 12G 18G 39% /var/log/amazon/ssm
tmpfs 1.9G 0 1.9G 0% /proc/acpi
tmpfs 1.9G 0 1.9G 0% /proc/scsi
tmpfs 1.9G 0 1.9G 0% /sys/firmware
tmpfs 52M 8.0K 52M 1% /run/user/1001

15. To Display CPU and I/O statistics = iostat -x

user@934cc9d6b341:~$ iostat -x
Linux 6.5.0-1023-aws (934cc9d6b341) 01/17/25 _x86_64_ (2 CPU)

avg-cpu: %user %nice %system %iowait %steal %idle


1.11 0.03 0.56 0.53 0.03 97.74

Device r/s rkB/s rrqm/s %rrqm r_await rareq-sz w/s wkB/s wrqm/s %wrqm w_await
wareq-sz d/s dkB/s drqm/s %drqm d_await dareq-sz f/s f_await aqu-sz %util
nvme0n1 11.68 589.20 1.49 11.33 5.31 50.46 43.90 4065.71 99.56 69.40 11.04
92.61 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.55 9.80

16. To Monitors I/O usage by processes =sudo iotop

user@934cc9d6b341:~$ sudo iotop


Netlink error: Operation not permitted (1)

The Linux kernel interfaces that iotop relies on now require root privileges
or the NET_ADMIN capability. This change occurred because a security issue
(CVE-2011-2494) was found that allows leakage of sensitive data across user
boundaries. If you require the ability to run iotop as a non-root user, please
configure sudo to allow you to run iotop as root.

17. Monitors and tests disk health (part of smartmontools) = sudo smartctl -a /dev/sda

user@934cc9d6b341:~$ sudo smartctl -a /dev/sda


smartctl 7.4 2023-08-01 r5530 [x86_64-linux-6.5.0-1023-aws] (local build)
Copyright (C) 2002-23, Bruce Allen, Christian Franke, www.smartmontools.org

Smartctl open device: /dev/sda failed: No such device


Linux Commands
Network and Logs Management
This section focuses on essential Linux commands for managing network interfaces, monitoring
connectivity, and analyzing system logs. Network management helps configure, troubleshoot, and
monitor network traffic, while log management is vital for tracking system events, debugging issues,
and ensuring security and performance.

📌 Topics Explained:

Network Management:

• ip a, ifconfig – Displays active network interfaces and their IP addresses.


• ping, traceroute – Tests network connectivity and traces route paths.
• netstat, ss – Shows network socket statistics and listening ports.
• hostname, ip r, route – Manages hostnames and routing information.
• nmcli, nmtui – Manages network interfaces using NetworkManager.
• dig, nslookup – Performs DNS lookups and domain query testing.
• iptables, ufw – Sets firewall rules and secures network access.

Logs Management:

• /var/log/ – The default directory where most system logs are stored.
• journalctl – Accesses logs from the systemd journal for modern systems.
• dmesg – Prints kernel messages, useful for boot and hardware diagnostics.
• tail -f, less, grep – Reads logs in real-time and filters content.
• logrotate – Manages automated log rotation and retention.
• rsyslog, syslog – System logging services used by many Linux distros.

1. Modern utility to manage network configurations = ip addr show

user@de5c3203801d:~$ ip addr show


1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen
1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
83: eth0@if84: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group
default
link/ether 02:42:ac:14:00:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 172.20.0.2/16 brd 172.20.255.255 scope global eth0
valid_lft forever preferred_lft forever
Linux Commands
2. Legacy command for interface management = ifconfig

user@de5c3203801d:~$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.20.0.2 netmask 255.255.0.0 broadcast 172.20.255.255
ether 02:42:ac:14:00:02 txqueuelen 0 (Ethernet)
RX packets 5107 bytes 28224528 (28.2 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4018 bytes 392433 (392.4 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536


inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

3. To view routing table = ip route show

user@de5c3203801d:~$ ip route show


default via 172.20.0.1 dev eth0
172.20.0.0/16 dev eth0 proto kernel scope link src 172.20.0.2
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.100
192.168.2.0/24 via 192.168.1.1 dev eth0

4. To delete a route = ip route del <route>

user@de5c3203801d:~$ ip route del 192.168.1.0/24


RTNETLINK answers: Operation not permitted

5. To test connectivity to a host = ping google.com

user@de5c3203801d:~$ ping google.com


PING google.com (142.250.70.46) 56(84) bytes of data.
64 bytes from pnbomb-aa-in-f14.1e100.net (142.250.70.46): icmp_seq=1 ttl=115 time=2.78 ms
64 bytes from pnbomb-aa-in-f14.1e100.net (142.250.70.46): icmp_seq=2 ttl=115 time=2.51 ms
64 bytes from pnbomb-aa-in-f14.1e100.net (142.250.70.46): icmp_seq=3 ttl=115 time=2.50 ms
64 bytes from pnbomb-aa-in-f14.1e100.net (142.250.70.46): icmp_seq=4 ttl=115 time=2.51 ms
64 bytes from pnbomb-aa-in-f14.1e100.net (142.250.70.46): icmp_seq=5 ttl=115 time=2.59 ms
64 bytes from pnbomb-aa-in-f14.1e100.net (142.250.70.46): icmp_seq=6 ttl=115 time=2.52 ms
^C
--- google.com ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5008ms
rtt min/avg/max/mdev = 2.499/2.568/2.779/0.098 ms
Linux Commands
6. To trace the route packets take to a destination = traceroute google.com

user@de5c3203801d:~$ traceroute google.com


traceroute to google.com (142.250.199.174), 30 hops max, 60 byte packets
1 ip-172-20-0-1.ap-south-1.compute.internal (172.20.0.1) 0.023 ms 0.009 ms 0.006 ms
2 ip-10-1-0-249.ap-south-1.compute.internal (10.1.0.249) 0.099 ms 0.146 ms 0.116 ms
3 240.2.196.13 (240.2.196.13) 2.371 ms 240.2.196.12 (240.2.196.12) 2.165 ms 240.2.196.13
(240.2.196.13) 2.407 ms
4 ***
5 99.82.178.53 (99.82.178.53) 2.600 ms 2.584 ms 2.567 ms
6 ***
7 216.239.46.136 (216.239.46.136) 2.459 ms 142.250.210.182 (142.250.210.182) 2.342 ms
192.178.86.246 (192.178.86.246) 2.762 ms
8 192.178.110.208 (192.178.110.208) 2.610 ms 108.170.234.157 (108.170.234.157) 2.627 ms
192.178.110.204 (192.178.110.204) 3.075 ms
9 bom07s37-in-f14.1e100.net (142.250.199.174) 2.248 ms 142.250.209.71 (142.250.209.71) 3.848
ms 142.251.77.69 (142.251.77.69) 2.344 ms

7. To view active connections (legacy) = netstat -tuln

user@de5c3203801d:~$ netstat -tuln


Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:7681 0.0.0.0:* LISTEN

8. Modern alternative to netstat = ss -tuln

user@de5c3203801d:~$ ss -tuln
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
tcp LISTEN 0 128 0.0.0.0:7681 0.0.0.0:*

9. Advanced packet filtering = sudo iptables -L

user@de5c3203801d:~$ sudo iptables -L


Chain INPUT (policy ACCEPT)
target prot opt source destination

Chain FORWARD (policy ACCEPT)


target prot opt source destination

Chain OUTPUT (policy ACCEPT)


target prot opt source destination
Linux Commands
10. Set Default Policies

user@de5c3203801d:~$ sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT


user@de5c3203801d:~$ sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT
user@de5c3203801d:~$ sudo iptables-save > /etc/iptables/rules.v4 # Save and Apply Rules

11. Checking the Policies assigned

user@de5c3203801d:~$ sudo iptables -L


Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:http
ACCEPT tcp -- anywhere anywhere tcp dpt:https

Chain FORWARD (policy ACCEPT)


target prot opt source destination

Chain OUTPUT (policy ACCEPT)


target prot opt source destination

12. Flush All Rules = sudo iptables -F

user@de5c3203801d:~$ sudo iptables -F


user@de5c3203801d:~$ sudo iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination

Chain FORWARD (policy ACCEPT)


target prot opt source destination

Chain OUTPUT (policy ACCEPT)


target prot opt source destination

13. Managing Services = systemctl restart <service_name>

user@de5c3203801d:~$ sudo systemctl restart NetworkManager


Failed to start NetworkManager.service: Unit NetworkManager.service not found.

14. To check for logs managed by systemd or Monitoring Logs in Real-Time = sudo journalctl -f

user@d82222fe8d50:~$ sudo journalctl -f


Jan 17 18:16:40 d82222fe8d50 usermod[1603]: add 'syslog' to shadow group 'adm'
Jan 17 18:16:40 d82222fe8d50 systemd[1]: Reloading requested from client PID 1744 ('systemctl')
(unit session-c1.scope)...
Jan 17 18:16:40 d82222fe8d50 systemd[1]: Reloading...
Linux Commands
Jan 17 18:16:40 d82222fe8d50 systemd[1]: Reloading finished in 286 ms.
Jan 17 18:16:40 d82222fe8d50 sudo[1215]: pam_unix(sudo:session): session closed for user root
Jan 17 18:16:43 d82222fe8d50 sudo[2000]: user : TTY=pts/1 ; PWD=/home/user ; USER=root ;
COMMAND=/usr/bin/systemctl status rsyslog
Jan 17 18:16:43 d82222fe8d50 sudo[2000]: pam_unix(sudo:session): session opened for user
root(uid=0) by (uid=1001)
Jan 17 18:16:43 d82222fe8d50 sudo[2000]: pam_unix(sudo:session): session closed for user root
Jan 17 18:17:23 d82222fe8d50 sudo[2025]: user : TTY=pts/1 ; PWD=/home/user ; USER=root ;
COMMAND=/usr/bin/journalctl -f
Jan 17 18:17:23 d82222fe8d50 sudo[2025]: pam_unix(sudo:session): session opened for user
root(uid=0) by (uid=1001)

15. Displays the entire content of a log file = cat /var/log/bootstrap.log

2024-08-01 11:59:37 URL:http://ftpmaster.internal/ubuntu/dists/noble/InRelease [255850/255850] ->


"/build/chroot/var/lib/apt/lists/partial/ftpmaster.internal_ubuntu_dists_noble_InRelease" [1]
gpgv: Signature made Thu Apr 25 15:11:21 2024 UTC
gpgv: using RSA key F6ECB3762474EDA9D21B7022871920D1991BC93C
gpgv: Good signature from "Ubuntu Archive Automatic Signing Key (2018) <[email protected]>"
2024-08-01 11:59:37 URL:http://ftpmaster.internal/ubuntu/dists/noble/main/binary-amd64/by-
hash/SHA256/2a6a199e1031a5c279cb346646d594993f35b1c03dd4a82aaa0323980dd92451
[1401160/1401160] ->
"/build/chroot/var/lib/apt/lists/partial/ftpmaster.internal_ubuntu_dists_noble_main_binary-
amd64_Packages.xz" [1]
Unpacking libidn2-0:amd64 (2.3.7-2build1) …
Preparing to unpack .../libnettle8t64_3.9.1-2.2build1_amd64.deb ...
Unpacking libnettle8t64:amd64 (3.9.1-2.2build1) ...
Preparing to unpack .../libnpth0t64_1.6-3.1build1_amd64.deb ...
Unpacking libnpth0t64:amd64 (1.6-3.1build1) ...
Preparing to unpack .../libp11-kit0_0.25.3-4ubuntu2_amd64.deb ...
Unpacking libp11-kit0:amd64 (0.25.3-4ubuntu2) ...
Preparing to unpack .../libseccomp2_2.5.5-1ubuntu3_amd64.deb ...
Unpacking libseccomp2:amd64 (2.5.5-1ubuntu3) ...
Preparing to unpack .../libstdc++6_14-20240412-0ubuntu1_amd64.deb ...
Unpacking libstdc++6:amd64 (14-20240412-0ubuntu1) ...
Preparing to unpack .../libtasn1-6_4.19.0-3build1_amd64.deb ...
Unpacking libtasn1-6:amd64 (4.19.0-3build1) ...
Setting up libunistring5:amd64 (1.1-2build1) ...
Setting up libffi8:amd64 (3.4.6-1build1) ...
Setting up libhogweed6t64:amd64 (3.9.1-2.2build1) ...
Setting up gpgv (2.4.4-2ubuntu17) ...
Setting up libxxhash0:amd64 (0.8.2-2build1) ...
Setting up libtasn1-6:amd64 (4.19.0-3build1) ...
Setting up libstdc++6:amd64 (14-20240412-0ubuntu1) ...
Setting up libidn2-0:amd64 (2.3.7-2build1) ...
Setting up libp11-kit0:amd64 (0.25.3-4ubuntu2) ...
Setting up libapt-pkg6.0t64:amd64 (2.7.14build2) ...
Setting up libgnutls30t64:amd64 (3.8.3-1.1ubuntu3) ...
Linux Commands
16. Displays the last few lines of a log file = tail -5 bootstrap.log

user@d82222fe8d50:/var/log$ tail -5 bootstrap.log


Setting up libp11-kit0:amd64 (0.25.3-4ubuntu2) ...
Setting up libapt-pkg6.0t64:amd64 (2.7.14build2) ...
Setting up libgnutls30t64:amd64 (3.8.3-1.1ubuntu3) ...
Setting up apt (2.7.14build2) ...
Processing triggers for libc-bin (2.39-0ubuntu8) …

17. Displays the first few lines of a log file = tail -5 bootstrap.log

user@d82222fe8d50:/var/log$ head -5 bootstrap.log


2024-08-01 11:59:37 URL:http://ftpmaster.internal/ubuntu/dists/noble/InRelease [255850/255850] ->
"/build/chroot/var/lib/apt/lists/partial/ftpmaster.internal_ubuntu_dists_noble_InRelease" [1]
gpgv: Signature made Thu Apr 25 15:11:21 2024 UTC
gpgv: using RSA key F6ECB3762474EDA9D21B7022871920D1991BC93C
gpgv: Good signature from "Ubuntu Archive Automatic Signing Key (2018) <[email protected]>"
2024-08-01 11:59:37 URL:http://ftpmaster.internal/ubuntu/dists/noble/main/binary-amd64/by-
hash/SHA256/2a6a199e1031a5c279cb346646d594993f35b1c03dd4a82aaa0323980dd92451
[1401160/1401160] ->
"/build/chroot/var/lib/apt/lists/partial/ftpmaster.internal_ubuntu_dists_noble_main_binary-
amd64_Packages.xz" [1]
Linux Commands
📝 Linux Commands Cheat Sheet

1. File & Directory Management

Command Detailed Description


ls Lists files and directories in the current working directory.
ls -l Lists files with detailed info: permissions, owner, size, modification
time.
ls -a Includes hidden files (those starting with a dot ., like .bashrc).
cd /path Changes current working directory to the specified path.
pwd Prints the full path of the current directory (present working directory).
mkdir dirname Creates a new directory with the specified name.
rmdir dirname Deletes an empty directory; won’t work if directory contains files.
rm file Deletes a specified file permanently.
rm -r dirname Deletes a directory and its entire contents recursively.
cp src dest Copies files or directories from source to destination.
mv src dest Moves or renames a file/directory from source to destination.
touch file Creates a new empty file or updates timestamp of existing file.
find / -name filename Searches entire filesystem for files matching name pattern.

2. File Viewing & Editing

Command Detailed Description


cat file Displays content of a file in terminal (not suitable for large files).
less file Opens file in a pager, allows scrolling forward/backward.
more file Similar to less, but less flexible (can only scroll forward).
head file Shows the first 10 lines of a file (use -n to customize).
tail file Shows the last 10 lines of a file (useful for log files).
tail -f file Continuously monitors file for changes in real time (e.g., logs).
nano file Opens the file in the Nano text editor, beginner-friendly.
vi file or vim file Opens the file in Vi/Vim editor; powerful and advanced.
Linux Commands
3. File Permissions & Ownership

Command Detailed Description


chmod 755 file Changes file permissions; 755 = owner rwx, group rx, others rx.
chown user:group file Changes file owner and group ownership.
ls -l Shows current permissions for each file and directory.
umask Displays or sets default permission mask for new files/directories.

4. User & Group Management

Command Detailed Description


adduser username Creates a new user account with home directory and settings.
userdel username Deletes a user account and optionally their home directory.
usermod -aG group user Adds a user to a supplementary group (e.g., sudo).
groupadd groupname Creates a new user group.
groupdel groupname Deletes an existing group.
passwd username Sets or changes password for a user account.
id username Shows user ID (UID), group ID (GID), and group memberships.

5. Disk & File System Management

Command Detailed Description


df -h Shows disk usage of mounted filesystems in human-readable format.
du -sh folder/ Displays total size of a directory and its contents.
mount /dev/sdX /mnt Mounts a disk or partition to a mount point.
umount /mnt Unmounts a mounted filesystem safely.
lsblk Lists block storage devices (disks and partitions).
fdisk -l Shows partition table and disk info (use with care).
mkfs.ext4 /dev/sdX Formats the disk or partition with ext4 filesystem.
blkid Displays UUIDs and file system types for devices.
Linux Commands
6. Memory & Process Management

Command Detailed Description


top Live view of CPU, memory, and process usage in real time.
htop Enhanced version of top with interactive UI (must be installed).
ps aux Lists all running processes with detailed info.
kill PID Sends termination signal to a process by its ID.
killall process Kills all processes with a given name.
nice, renice Sets or changes process priority (lower value = higher priority).
free -h Shows RAM and swap usage in human-readable form.

7. Networking Commands

Command Detailed Description


ip a Shows network interfaces and assigned IP addresses.
ifconfig Legacy tool to view and configure network interfaces.
ping host Checks connectivity and latency to another host.
traceroute host Shows path taken by packets to reach a host.
netstat -tuln Lists all active listening ports and services.
ss -tuln Replacement for netstat with faster output.
nmap IP Scans open ports and services on a target system.
nslookup domain Checks DNS resolution of a domain name.
dig domain Detailed DNS query tool (preferred over nslookup).

8. Package Management

Command Detailed Description


apt update Updates package list (Debian/Ubuntu-based systems).
apt upgrade Installs available updates for packages.
apt install pkg Installs a specific package.
apt remove pkg Removes an installed package.
yum install pkg Installs a package on RHEL/CentOS systems.
yum remove pkg Removes a package on RHEL/CentOS.
dnf update Newer alternative to yum in Fedora.
Linux Commands
apt list --installed List all the installed packages
dpkg -l List all the installed packages with their versions and description

9. Archive & Compression

Command Detailed Description


tar -cvf archive.tar dir/ Creates tar archive from directory.
tar -xvf archive.tar Extracts contents of a tar archive.
gzip file Compresses file using gzip algorithm.
gunzip file.gz Decompresses a gzipped file.
zip file.zip file Creates zip archive.
unzip file.zip Extracts zip file contents.

10. Searching & Filtering

Command Detailed Description


grep 'pattern' file Searches for a text pattern in a file.
grep -r 'pattern' dir/ Recursively searches in directories.
find / -name 'filename' Searches for files matching a pattern.
locate filename Searches files using a prebuilt index (needs updatedb).
which command Shows the full path of a command executable.

11. System Monitoring & Logs

Command Detailed Description


uptime Shows system uptime and load averages.
dmesg Displays boot and hardware messages.
vmstat Reports system performance (CPU, memory, I/O).
iostat Shows CPU usage and disk I/O stats.
journalctl Views logs managed by systemd.
tail -f /var/log/syslog Monitors log file changes in real time.
last Shows login/logout history of users.
Linux Commands
12. Permissions & Access Control

Command Detailed Description


chmod Sets file/directory permissions (read, write, execute).
chown Changes file/directory ownership.
umask Default permissions for new files/directories.
sudo Executes command as superuser/root.
su - Switches to another user (usually root).

13. Scheduling & Automation

Command Detailed Description


crontab -e Edits cron jobs for scheduling recurring tasks.
crontab -l Lists existing cron jobs.
at time Schedules a one-time task at a given time.
systemctl Manages services, daemons, and system states.

You might also like