# Command Line Interface

### INTRODUCTION

The Command Line Interface is a text-based interface that allows users to interact with their operating system by typing commands. The reason to choose CLI over interacting with our computer through Apps and all is that it offers us more speed , power and control on our computer. We can make more than 100 files or folders by just writing one single command, we can extract each and every information about different process running on our system through a single commands. We can perform multiple operations with the help of Pipe commands. We can change the permission for our files and folders for users, groups and all others. Below are some very useful commands that I have come through while learning CLI :-

### NORMAL COMMANDS/FILE FOLDER COMMANDS

These commands are useful while we have to perform some operations like creating/deleting/upgrading of files and folders :-

1. **pwd** :- This command tells us in which directory we are currently present.
    
    ```bash
    pwd 
    
    /home/username/Documents/project
    ```
    
2. **ls** :- This command lists all the files and folders that are inside of a directory we are currently present in.
    
    ```bash
    ls 
    
    Documents Downloads Music Pictures Videos notes.txt
    ```
    
    This command comes with many sub-commands such as :-
    
    1) **ls -a** : presents all directories as well as hidden directories.
    
    2) **ls -l** : shows every detail of each file and folder.
    
    3)**ls -t** : sorts the files according to their time.
    
3. **mkdir** : - This command is used for making a folder. ‘rmdir’ command is used for deleting it ( If the folder doesn’t have any contents present in it).
    
    Eg :- Input :- mkdir abc
    
    Output :- It will create a folder with the name abc.
    
    Similarly, there are also other commands like mv for moving or renaming a file or a folder, cp for copying a file or folder, cat file.txt for viewing a file.
    
4. **xargs** :- This command is used as a combination between two commands .i.e it takes the output from first command and give it to the second command as an arguments.
    
    Eg :- ls | args echo
    
    This will take the names of files and folders from ls command as an argument and give it to the echo command which will print those names as its output.
    

One great use of xargs argument that I found is we can take the output from files which includes names of anything and we can make files of those names (If there are 100 names in that file, we can make 100 files of that name using only one command ).

Eg : cat names.txt | xargs touch

This command reads names from names.txt and create files of those names.

### INSTALLATION/UNINSTALLATION OF APPS

We can install and uninstall apps using these commands like :-

1. **sudo apt install APP\_NAME** :- This command is used for installation of apps on our computer system.
    
    Eg :- sudo apt install vim
    
    This instruction will install vim app on our system.
    
    Similarly there is an instruction for uninstallation of app which is : **sudo apt remove APP\_NAME**
    
2. ‘**sudo apt update APP\_NAME**’ to uptate an app and ‘**sudo apt upgrade APP\_NAME**’ for upgradation of app.
    

### SYSTEM INFORMATION

With the help of CLI , we can use commands to know various details about our system such as :-

1. **df** :- Shows the disk space usage of all mounted filesystems.
    
2. **free** :- Display available and used memory (RAM and swap) on the system.
    
3. **du -sh** :- Shows the total size of the current directory in a human readable format (like KB, MB).
    
4. **lscpu** :- Prints detailed CPU architecture information (cores, threads, model, etc.).
    
5. **lsblk** :- Lists all block devices (like hard drives, SSDs, partitions) in a tree structure.
    
6. **lsusb** :- Shows all USB devices connected to the system.
    
7. **lspci** :- Lists all PCI devices (like graphic cards, network cards) attached to the motherboard.
    
8. **hardinfo** :- Launches a system information tool that provides a detailed hardware and system report (needs to be installed separately on some systems).
    
    Apart from these , there are many system commands to know information of our PC.
    

### NETWORKING COMMANDS

With the help of networking commands ,we can manage, monitor, troubleshoot, and configure network settings. There are various networking commands that we can use such as :-

1. **ping** :- Check if a remote server is reachable.
    
2. **traceroute** :- Find the path taken by packets to reach a server.
    
3. **netstat** :- List network connections, ports, and network statistics.
    
4. **ip** :- Manage IP addresses and routing.
    
5. **curl** :- Download data from a server.
    
6. **nmap** :- Scan networks and check open ports.
    
7. **scp** :- Copy files securely over a network.
    
    Besides these there are many networking commands such as hostname,arp,route,nslookup,dig etc.
    

### COMBINING MULTIPLE COMMANDS

One powerful feature of CLI is that we can combine multiple commands in a single line. This feature helps us in saving a lot of time. With the help of Pipe command in CLI , we can give output of one command as input to other command and we can use multiple pipes in a single line. Here are some of the examples :-

1. For counting the number of files and folders in a directory :-
    
    ```bash
    ls -1 | wc -l
    ```
    

### Step-by-Step:

🔹 `ls -1`

* `ls` lists files and folders.
    
* `-1` forces **one entry per line** — so every file/folder is printed on its own line.
    
* 🔹 `|` (pipe)
    
    * Sends the **output** of `ls -1` as **input** to the next command `wc -l`.
        
    
    🔹 `wc -l`
    
    * `wc` stands for **word count**.
        
    * `-l` means **count the number of lines**.
        
    
    So it **counts how many files/directories** are listed by `ls -1`.
    

2. Combining 2 files and sorting it alphabetically :-
    
    ```bash
    cat a.txt b.txt | sort
    ```
    

Step-by-Step:

🔹 `cat a.txt b.txt`

* `cat` displays the contents of **a.txt** and **b.txt** **one after another** (concatenates them).
    

🔹 `|` (pipe)

* Passes the **combined output** of `cat` into the `sort` command.
    

🔹 `sort`

* Sorts the lines **alphabetically** (by default) and prints the sorted output to the terminal.
    

---

3. To see only 30 -37 lines of a file :
    
    ```bash
    cat names.txt | head -37 | tail -7    
    ```
    

### Step-by-Step:

🔹 `cat names.txt`

* Displays the **entire content** of the file `names.txt`.
    

🔹 `|` (pipe)

* Passes the output (all lines) into the next command.
    

🔹 `head -37`

* Shows only the **first 37 lines** from `names.txt`.
    

🔹 **another** `|` pipe

* Passes those **first 37 lines** into the next command.
    

🔹 `tail -7`

* Shows the **last 7 lines** from those first 37 lines.
    

### CONCLUSION

The CLI may seem intimidating at first, but it quickly becomes a superpower for anyone who learns it. Whether you're managing servers, automating tasks, or just working faster, mastering the command line opens up a whole new world of possibilities.
