Table of contents

No heading

No headings in the article.

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

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

image.png

image.png

  • 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

  • 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

image.png

  • 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

image.png

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

image.png

  • 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

  • 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

  • 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

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

image.png

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

image.png

  • touch: This command creates an empty file.

image.png

  • 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

  • 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.

image.png

  • chown: Change the owner of the file.

  • ps: Displays all the running processes with PID(process IDs).

image.png

  • 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

image.png

image.png

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

image.png

  • 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

  • diff: This command compares two files and directories.

image.png

  • 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

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

image.png

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

image.png

  • 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

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

image.png

  • 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

  • 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

image.png

  • gunzip: It is used to unzip files.

image.png

  • which: This commands outputs the full path of shell commands.

image.png

  • whatis: Displays single-line info about the command.

image.png

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

image.png

  • whoami: It displays the username in use.

image.png

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

image.png

  • passwd: It lets you change the password of the user.

image.png

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

image.png

  • 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

  • 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

  • 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

  • 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

image.png

  • 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.