Command Line Interface (CLI) Essentials for Every Linux User

Unix

It is a family of operating systems" MacOS, Android, IOS , Linux etc. The core of unix os is called Kernel.

  1. Kernel controls and Manages everything in the system.

  2. the shell is interface between the user and the Kernel.

  3. It takes and interprets commands through CLI, also Called terminal.

  4. There are many types of shells like Bash, shell etc.

  5. Applications are the top layer. The GUI which we see

CLI(Command line Interface)

Computers understand the language of zeros and ones known as binary language. In the early days of computing, instructions were provided using binary language, which is difficult for all of us to read and write. Therefore, in an operating system, there is a special program called the shell. The shell accepts human-readable commands and translates them into something the kernel can read and process.


What Is a Shell?

  • The shell is a user program or it is an environment provided for user interaction.

  • It is a command language interpreter that executes commands read from the standard input device such as a keyboard or from a file.

  • The shell gets started when you log in or open a console (terminal).

  • Quick and dirty way to execute utilities.

  • The shell is not part of the system kernel but uses the system kernel to execute programs, create files, etc.

  • Several shells are available for Linux including:

  • BASH ( Bourne-Again SHell ) - The most common shell in Linux. It's Open Source.

  • CSH (C SHell) - The C shell's syntax and usage are very similar to the C programming language.

  • KSH (Korn SHell) - Created by David Korn at AT & T Bell Labs. The Korn Shell also was the base for the POSIX Shell standard specifications.

  • TCSH - It is an enhanced but completely compatible version of the Berkeley UNIX C shell (CSH).


CLI Commands

  1. man :

    The man command in Linux is used to display the manual (help documentation) of other commands, explaining their purpose, usage, options, and examples.

    Example: man ls

  2. cd :

    The cd command is used to change the current working directory in the Linux terminal. It allows the user to move from one directory (folder) to another.

    • Common Flags and Special Uses of cd:

      • cd /path/to/directory
        Moves you to the specified absolute path.

      • cd ..
        Moves one directory up (to the parent directory).

      • cd -
        Switches to the previous directory you were in.

      • cd ~
        Shortcut to go to the home directory.

      • cd ~/foldername
        Moves directly into a folder inside your home directory.

      • cd /
        Moves you to the root directory.

  3. mkdir:
    The mkdir command is used to create a new directory (folder). It enables the creation of a directory with the specified name in the current working directory.
    Example: mkdir myfolder

  4. mv:
    The mv command is used to move or rename files and directories. It can move files from one location to another or rename a file or directory.
    Example: mv file.txt /home/user/Documents/

  5. cp:
    The cp command is used to copy files or directories. It allows you to duplicate a file or folder to a different location.

    Recursive flag for this command : -r :- used to copy recursively.
    Example: cp -r source_folder/ destination_folder/

  6. ls:
    The ls command is used to list the contents of a directory, displaying files and subdirectories within it.

    • Common Flags and Special Uses of ls:

      • ls -a

        Shows hidden files as well.

      • ls -l

        Shows detailed list of directory content.

  7. pwd:The pwd command stands for "print working directory." It shows the absolute path of the current directory you are in.
    Example: pwd

  8. rm:
    The rm command is used to remove files or directories. It permanently deletes them from the file system.
    Example: rm file.txt

  9. chmod:
    The chmod command is used to change the permissions of a file or directory. It determines who can read, write, or execute a file.
    Example: chmod 755 script.sh

  10. chown:
    The chown command is used to change the owner and group of a file or directory.
    Example: chown user file.txt

  11. sudo:
    The sudo command is used to execute commands with superuser (administrator) privileges. It is typically required for administrative tasks.
    Example: sudo apt update

  12. apt:
    The apt command is used for handling packages in Ubuntu and other Debian-based Linux distributions. It can install, update, or remove software packages.
    Example: sudo apt install nginx

  13. touch:
    The touch command is used to create a new empty file or update the timestamp of an existing file.
    Example: touch newfile.txt

  14. cat:
    The cat command is used to display the contents of a file on the terminal. It can also concatenate files.
    Example: cat file.txt

  15. less:
    The less command is used to view the contents of a file one page at a time. It is similar to more, but allows both forward and backward navigation.
    Example: less file.txt

  16. more:
    The more command is used to view the contents of a file one page at a time. It only allows forward navigation.
    Example: more file.txt

  17. tail:
    The tail command is used to view the last few lines of a file. It’s often used to monitor logs in real-time.
    Example: tail file.txt

  18. rsync:
    The rsync command is used to synchronize files and directories between two locations, whether on the same system or remote systems.
    Example: rsync -av source/ destination/

  19. grep:
    The grep command is used to search for patterns within files. It prints lines in the file that match a specified pattern.
    Example: grep "hello" file.txt

  20. find:
    The find command is used to search for files and directories in a specific location based on conditions like name, type, or modification time.
    Example: find /home/user -name "file.txt"

  21. sort:
    The sort command is used to arrange the lines in a file in either ascending or descending order, based on specified criteria.
    Example: sort file.txt

  22. date:
    The date command is used to display or set the system’s date and time. It can also format the output according to the user’s specifications.
    Example: date

  23. tree:
    The tree command is used to display the directory structure of a given directory in a tree-like format. This command is useful for visualizing the hierarchy of directories and files. This package needs to be installed using : sudo apt install tree
    Example: tree

  24. wc:
    The wc (word count) command is used to count the number of lines, words, and characters in a file or input stream.
    Example: wc file.txt

  25. ps:
    The ps command is used to display information about currently running processes on the system.
    Example: ps aux

  26. top:
    The top command is used to show a real-time, dynamic view of the system’s running processes and their resource usage.
    Example: top

  27. df:
    The df command is used to report the amount of available disk space and used space on the file system.
    Example: df -h

  28. uname:
    The uname command is used to display system information like the operating system name, version, and hardware details.
    Example: uname -a

  29. free:
    The free command is used to show the amount of free and used memory in the system, including RAM and swap space.
    Example: free -h

  30. lspci:
    The lspci command is used to list all PCI (Peripheral Component Interconnect) devices attached to the system, like graphics cards and network adapters.
    Example: lspci

  31. kill:
    The kill command is used to terminate a running process by sending it a signal. By default, it sends the TERM (terminate) signal.

    • Common Flags and Special Uses of kill:

      • kill -9 pid

        force quit.

      • kill -15 pid

        graceful quit.

  32. ping:
    The ping command is used to check the network connectivity between your machine and another device or server.
    Example: ping google.com

  33. ifconfig:
    The ifconfig command is used to configure or display the network interfaces on a Linux system.
    Example: ifconfig

  34. ssh:
    The ssh command is used to securely connect to a remote machine over a network using the Secure Shell (SSH) protocol.
    Example: ssh user@remote_server_ip

  35. xargs:
    The xargs command is used to build and execute command lines from standard input. It is often used to handle output as input for another command.
    Example: find . -name "*.txt" | xargs cat

  36. printenv:
    The printenv command is used to display the current environment variables of the system.
    Example: printenv

  37. nano:
    The nano command is used to open the Nano text editor, a simple terminal-based text editor to create or edit files.
    Example: nano file.txt

  38. awk:
    The awk command is a powerful text-processing tool used to manipulate and analyze text files or streams by pattern scanning and processing.
    Example: awk '{print $1}' file.txt

  39. sed:
    The sed command is a stream editor used to perform basic text transformations on an input stream (like replacing text inside files).
    Example: sed 's/old/new/' file.txt

  40. | (Pipe operator):
    The pipe operator (|) is used to pass the output of one command as input to another command, chaining commands together.
    Example: cat file.txt | grep "searchword"


Conclusion

Mastering the Command Line Interface (CLI) is a fundamental skill for anyone working with Linux or other Unix-based systems.
It allows users to perform complex tasks efficiently, automate operations, and manage systems at a deeper level than graphical interfaces permit.

Whether it’s navigating the filesystem, managing processes, monitoring system performance, or configuring networks, the commands we discussed are essential building blocks.
As you become more comfortable with these commands, you’ll find that CLI offers unmatched speed, flexibility, and control over your computing environment.

Keep practicing, explore beyond the basics, and soon the terminal will feel like a powerful extension of your own hands.

Happy Learning and Happy Coding!


0
Subscribe to my newsletter

Read articles from Chaitanya Aggarwal directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Chaitanya Aggarwal
Chaitanya Aggarwal