# Linux & Bash

Hello, this is a detailed blog about Linux and Bash commands and shortcuts which is useful for anyone who uses Linux or Bash for day-to-day work.

* `man`: This command shows details about a command when used in prefix with any command like `man clear`. This is useful for learning more about a command or checking details before using it.
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1654861525619/t8uXVxUoZ.png align="left")

* `clear`: This clears the terminal. It is very useful if you have a lot going on in your terminal.
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1654861984581/kZIQDjU7h.png align="left")

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1654862123708/MvwacJU6W.png align="left")

* `lsd_release -a`: Displays distribution details.
    
* `lscpu`: Display CPU information.
    
* `updatedb`: Updates the file system.
    
* `du`: Shows disk file space usage. Also, `df` shows system disk usage. Add `du -sh` for summary and human-readable.
    
* `tar`: To create or extract zip files. `tar -czf` and `tar -xzf` to create and extract. `z` for tar.gz files.
    
* `pwd`: Sometimes you forget where you are in the file system. This tells you the current directory you are in. It stands for 'Print Working Directory'.
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1654862175812/kt2li--Lj.png align="left")

* `ls`: It shows the list of files in a directory. ls + directory name also shows a list without going into the directory. `ls -a` is used to see hidden files. Hidden files are '.filename'. `-al` display files permissions. `-R` to display of contents of directories.
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1654862226645/_VNGak818.png align="left")

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1654862416625/xIMC1esNe.png align="left")

* `cd`: It stands for 'change directory'. 'cd (name of the directory)' to go to a directory. `cd ..` to go back to a directory. `cd ../..` to go two directories back. `cd` goes back to the home directory.
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1654862544388/wBXQ7wW-h.png align="left")

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1654862744985/Sc5b9Hyal.png align="left")

* `sudo`: It is used before any command. If you want root permission for a command you can do it.
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1654862853905/SXIl6Hhu-.png align="left")

* `mkdir`: This is used for creating a directory. `mkdir directory-name` creates a directory. `mkdir -p` if the base folder doesn't exist and you want to create one more directory in it.
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1654863105323/q3IYW-kPx.png align="left")

* `rmdir`: It is useful to remove a directory. It removes the directory only if it is empty. For directories that are not empty use `rm -rf`.
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1654863154368/xDU4G6aYV.png align="left")

* `cp`: This command is used to cp files and directories. `cp filename new location` general method. `cp filename new filename` to make a version of the file to back if you mess something up. `cp -r` for directories.
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1654863457998/C0tf1Jd4j.png align="left")

* `mv`: There are uses for this command. The first one is to move files. The second is to rename files.
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1654863698057/z9qRw7YII.png align="left")

* `rm`: This is used to remove directories and files. `rm -rf *` to remove all the files in a directory.
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1654863799047/yR3gdPbrM.png align="left")

* `touch`: This command creates an empty file.
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1654863881942/pG8f2W2CY.png align="left")

* `find`: It is very useful when you can't find the file you want. `find * -name filename` to search your file in the file system. An alternative to this is `locate`.
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1654864081024/6HyH2N88l.png align="left")

* `chmod`: It is one of the best-known commands, and it changes the permissions of a specific file directory through a quick argument.
    
    W is used for writing permissions R is used for reading permissions X is used for the execution ‘+’ is used to add permissions ‘-’ is used to remove permissions.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1672240564406/7b34ddb4-8fe5-49dc-bbd9-d2b5b76a9d80.png align="center")
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1654864466288/sDnyA0jCo.png align="left")

* `chown`: Change the owner of the file.
    
* `ps`: Displays all the running processes with PID(process IDs).
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1654864611081/GeqG2p28I.png align="left")

* `kill`: To kill a process with the process ID. `kill PID` to kill the process.
    
* `sleep`: It controls and manages processes in scripts as well. It delays the elements of a process processing till a specified time. The time can be specified using seconds, minutes, or even days.
    
* `alias`: This is very useful to create shortcuts for long commands. `alias name=command` to set an alias for a command. This is a temporary solution but you can make it permanent by entering it in the '.bashrc' file.
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1654866387268/IQU2jKe89.png align="left")

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1654866788140/O2y7hmeS-.png align="left")

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1654866605380/62MO1JVJe.png align="left")

* `cat`: This command prints the contents of a file in the terminal. `cat filename` displays it.
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1654866837672/VwA_Q6u3O.png align="left")

* `curl`: To download files or information from any URL. `curl+URL` is used for it. Some distributions don't have but you can install it.
    
* `mousepad`: Simple text editor.
    
* `df`: The df command shows the size, used space, and available space on the mounted filesystems.
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1655043543844/euUo4s3UA.png align="left")

* `diff`: This command compares two files and directories.
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1655043737391/kTi3tgqzN.png align="left")

* `exit`: The exit command will close a terminal window, end the execution of a shell script, or log you out of an SSH remote access session.
    
* `finger`: Display the information about the user.
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1655043905930/wWKiA6C_kl.png align="left")

* `free`: Display memory usage information in the terminal. `free -h` for human-readable format.
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1655044080968/Yqif5dod-.png align="left")

* `groups`: The groups' command tells you which groups a user is a member of.
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1655044235853/dJ98iWfd-.png align="left")

* `echo`: It can be put into the output status text to the main screen or any required file. It is also helpful in depicting environmental variables in the system.
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1655044310326/fJQHevqWy.png align="left")

* `nano`: A text editor opens in the terminal. `nano filename` opens the file in the terminal.
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1655044365057/j6YwhRezv.png align="left")

* `grep`: It is a command to search for text files and performs the search through specific keywords. `grep -c 'Linux' filename` searches the word 'Linux' word in the file.
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1655044489580/b9yO0aYW9.png align="left")

* `gzip`: This is used to compress files. By default, it removes the original file and leaves you with the compressed version. To retain both the original and the compressed version, use the `-k`(keep) option.
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1655044604985/fd4TXkgcR.png align="left")

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1655045268497/QlnYfphPe.png align="left")

* `gunzip`: It is used to unzip files.
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1655045204176/8PI_zoOSK.png align="left")

* `which`: This commands outputs the full path of shell commands.
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1655045317841/gn09X_QrD.png align="left")

* `whatis`: Displays single-line info about the command.
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1655045372934/gkQKL3yFF.png align="left")

* `shred`: It is useful if you want your file to be impossible to recover. `-u` deletes it right away.
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1655045496533/IDC8sm6Ls.png align="left")

* `whoami`: It displays the username in use.
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1655045536940/lRvKy0k09.png align="left")

* `apt``yum``pacman`: These are package managers. Depends on the distribution in use.
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1655045767517/uscI6uFPH.png align="left")

* `passwd`: It lets you change the password of the user.
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1655045884810/McLkOLOQh.png align="left")

* `ping`: This command lets you verify if you have internet connectivity.
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1655045963011/iricHhrmT.png align="left")

* `shutdown`: Lets you shut down the system at a specific time.
    
* `netstat`: Print network connections, routing tables, interface statistics, masquerade connections and multicasts memberships.
    
* `ip a`: Similar to `ifconfig` to configure a network interface.
    
* `iwconfig`: Configure wireless network interface.
    
* `ufw`: Stands Uncomplicated Firewall. `ufw enable` and `ufw disable` for starting and stopping it. `ufw allow/deny [Name]` to edit the rules of the firewall. `ufw status numbered` to list all the rules in a numbered list.
    
* `ssh`: You can log in to a remote system with this command.
    
* `uname`: You can obtain some system information regarding the Linux computer you’re working on.
    
* `tree`: This is useful if you want to see the tree version(visualize version) of files and directories. Not all distributions have this but install it.
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1655046164514/4gjnyyrW5.png align="left")

* `history`: This is used to see the history of commands used on the system. This is useful forget about a command you used before. If you put space before the command system doesn't save the command in history. This is useful if you are not using your personal computer.
    
* `wc`: It is used to display the word count of the file.
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1655046363310/OBmORvrIs.png align="left")

* `tail`: This commands prints the last n number of lines in a file. `tail -n 25` to print 25 lines. `-n` is used to see the n number of lines and `-c` to display the number of bytes used by the file.
    
* `head`: This command is the opposite of tail. It is used to display the first n numbers of lines.
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1655046413218/ZfMiP9Nyp.png align="left")

* `htop`: It is an interactive process viewer. More feature-heavy with differing views and the ability to kill processes without needing their PIDs. There is also a slimmed-down version of this called `top`.
    

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1654865803423/x4yqNo6cG.png align="left")

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1654865845784/QE3_zoirI.png align="left")

* `wget`: To retrieve any content from the internet.
    
* `traceroute`: It displays network hops to reach a destination.
    
* `useradd`: To add a new user to the system. `adduser` does the same thing.
    
* `usermod`: To edit user permissions.
    
* `cal`: To display the calendar in the terminal.
    
* `ctrl+a`: If you want to edit something at the beginning of the line. `home` button also moves the cursor to the beginning of the line.
    
* `ctrl+e`: This is the opposite of `ctrl+a` it moves the cursor to the end of the line. `end` button is an alternate for it.
    
* `ctrl+u`: This shortcut is used to delete everything before the cursor.
    
* `ctrl+c`: This stops the current process in the terminal.
    
* `ctrl+k`: This shortcut is the opposite of `ctrl+u` it deletes everything after the cursor.
    
* `ctrl+y`: It is used as undo shortcut.
    
* `alt+backspace`: It is similar to `ctrl+backspace` in Windows. It deletes the entire word in one click.
    
* `ctrl+x+e`: If you want to run a command from history and edit it before running then you can use this shortcut. This opens the command in the editor and then runs it.
    
* `ctrl+r`: This is used to search commands from the history.
    
* `sudo !!`: If want to run the last command with Sudo privileges.
    
* `tab`: This is useful to autocomplete the command.
    
* `tab+tab`: This displays options for autocomplete.
    
* `&&`: Add multiple commands at once.
    
* `|`: Add one or more commands on the previous one.
