Table of contents
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 likeman clear
. This is useful for learning more about a command or checking details before using it.
clear
: This clears the terminal. It is very useful if you have a lot going on in your terminal.
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. Adddu -sh
for summary and human-readable.tar
: To create or extract zip files.tar -czf
andtar -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'.
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.
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.
sudo
: It is used before any command. If you want root permission for a command you can do it.
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.
rmdir
: It is useful to remove a directory. It removes the directory only if it is empty. For directories that are not empty userm -rf
.
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.
mv
: There are uses for this command. The first one is to move files. The second is to rename files.
rm
: This is used to remove directories and files.rm -rf *
to remove all the files in a directory.
touch
: This command creates an empty file.
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 islocate
.
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.
chown
: Change the owner of the file.ps
: Displays all the running processes with PID(process IDs).
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.
cat
: This command prints the contents of a file in the terminal.cat filename
displays it.
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.
diff
: This command compares two files and directories.
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.
free
: Display memory usage information in the terminal.free -h
for human-readable format.
groups
: The groups' command tells you which groups a user is a member of.
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.
nano
: A text editor opens in the terminal.nano filename
opens the file in the terminal.
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.
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.
gunzip
: It is used to unzip files.
which
: This commands outputs the full path of shell commands.
whatis
: Displays single-line info about the command.
shred
: It is useful if you want your file to be impossible to recover.-u
deletes it right away.
whoami
: It displays the username in use.
apt``yum``pacman
: These are package managers. Depends on the distribution in use.
passwd
: It lets you change the password of the user.
ping
: This command lets you verify if you have internet connectivity.
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 toifconfig
to configure a network interface.iwconfig
: Configure wireless network interface.ufw
: Stands Uncomplicated Firewall.ufw enable
andufw 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.
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.
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.
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 calledtop
.
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 ofctrl+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 ofctrl+u
it deletes everything after the cursor.ctrl+y
: It is used as undo shortcut.alt+backspace
: It is similar toctrl+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.