Today I want to bring you a summary of top Bash commands. Bash is a very popular shell program. It stands for 'Bourne Again Shell'. There are also other types of shells, but Bash is the most widely available and used shell.
Anything inside [ ] means that it's optional.
ls is one of the most common commands. It is used to list the contents of a directory.
Syntax: ls [options][files]
Common options: -a, -l
ls -a shows hidden(dot) files
ls -l shows file details
echo prints text to the terminal window. It is used widely for printing status texts and values of environment variables.
Syntax: echo [option(s)] [string(s)]
Common options: -e, -n
bash-3.2$ echo "hello" hello
touch can be used to create an empty file quickly. It can also be used to modify file timestamps.
Syntax: touch [option(s)] file_name(s)
Common options: -a, -m, -r, -d
bash-3.2$ touch a b bash-3.2$ ls a b
mkdir is used to create new directories. You can create multiple directories simultaneously.
Syntax: mkdir [option(s)] directory_name(s)
Common options: -m, -p, -v
bash-3.2$ ls a b bash-3.2$ mkdir c bash-3.2$ ls a b c
grep is used for finding text in files. It comes in handy when you're tasked to find a particular string or pattern within a file.
grep [option(s)] pattern [file(s)]
-iperforms a case-insensitive search
-ndisplays the lines containing the pattern along with the line numbers
-cdisplays the count of the matching patterns.
man command to bring up a manual for any command. For example, if you don't know what
mkdir does, then use the
man command to see its manual.
Syntax: man [option(s)] keyword(s)
Common options: -w, -f, -b
bash-3.2$ man mkdir
pwd command prints the working directory you are currently in.
You can change to a different directory with
cd command. Use
cd .. to go to the parent directory.
mv is used to move or rename directories. Without this command, you would have to individually rename each file which is tedious.
Syntax: mv [option(s)] argument(s)
Common options: -i, -b
rmdir will remove empty directories. This can help clean up space on your computer and keep files and folders organized. There are two ways to remove directories: rm and rmdir.
rm will remove directories and files even if it's not empty whereas
rmdir will only delete empty directories.
Syntax: rmdir [option(s)] directory_names
Common options: -p
It is the simplest way to find a file or directory. It searches a cached list of files to find the location of a specified file.
Syntax: locate [option(s)] file_name(s)
Common options: -q, -n, -i
less command allows you to view files without opening an editor. It’s faster to use, and there’s no chance of you inadvertently modifying the file.
Syntax: less file_name
Common options: -e, -f, -n
compgen is a bash built-in command which is used to list all the commands that could be executed in the Linux system.
Syntax: compgen [option(s)]
Common options: -a, -c, -d
This takes the output from the preceding command that you’d normally see in the terminal and sends it to a file that you give it. As an example, take echo “test” > dev1. Here it creates a file called dev1 and puts the echoed string into it.
head command allows you to read the first few lines of a file. The default number is 10.
Syntax: head [option(s)] file(s)
Common options: -n, can be used to specify the number of lines to show
tail outputs the last few lines of a file. And, just like the
head command, the default is 10.
Syntax: tail [option(s)] file_names
Common options: -n
cat, short for concatenate, is one of the most commonly used commands. It allows you to create single or multiple files, view file inclusions, concatenate files and redirect output in a terminal or file.
Syntax: cat [option(s)] [file_name(s)] [-] [file_name(s)]
Common options: -n
A pipe takes the standard output of one command and passes it as the input to another.
chmod command is used to change the access mode of a file. The name is an abbreviation of change mode.
Syntax: chmod [reference][operator][mode] file...
Common options: -f, -v
References are used to distinguish the users to whom the permissions apply. Operator is used to specify how the modes of a file should be adjusted. The modes indicate which permissions are to be granted or removed from the specified classes.
exit command is used to exit any kind of shell.
history command prints out your recent commands, one command per line. It also prints the history number for each command. Each command is associated with a number for easy reference. You can truncate the output by specifying a number after the command.
Common options: -c, -d
This command is used to clear all previous commands and output from consoles and terminal windows. This keeps your terminal clean and removes the clutter so you can focus on subsequent commands and their output.
cp stands for copy. This command is used to copy files or groups of files or directory.
Syntax: cp [option(s)] current_name new_name
Common options: -r, -i, -b
kill command allows you to terminate a process from the command line. You do this by providing the process ID (PID) of the process to kill. You can use the
ps command to find the PID.
kill is a built-in command of the bash shell.
Syntax: kill [option(s)] PID(s)
sleep command is used in shell scripts to take a pause before the execution of the next command. For example, it can be used inside a script to pause before retrying a failed operation or inside a loop.
Syntax: sleep number [suffix]
Suffix is used to specify the unit of time and can be:
You can change your account password using
passwd command. It will ask for your old password and then ask to enter your new password twice.
df command is used to get a detailed report on the system’s disk space usage. When used without any argument, the df command will display information about all mounted file systems.
Syntax: df [options]... filesystem...
You can use
comm command to compare two sorted files line by line. To compare two sorted files using 'comm', you have to pass their names as arguments.
Syntax: comm [OPTION]... FILE1 FILE2
I hope you enjoyed this summary and learned something new. I will be coming up with more such notes soon.
Please give me a follow if you liked it. 🙌
Currently building SigNoz - an open-source APM & observability tool 💙
SigNoz is an open-source APM. It helps developers monitor their applications & troubleshoot problems, an open-source alternative to DataDog, NewRelic, etc. 🔥 🖥. 👉 Open source Application Performance Monitoring (APM) & Observability tool
Monitor your applications and troubleshoot problems in your deployed applications, an open-source alternative to DataDog, New Relic, etc.
Documentation • ReadMe in Chinese • ReadMe in German • ReadMe in Portuguese • Slack Community • Twitter
SigNoz helps developers monitor applications and troubleshoot problems in their deployed applications. SigNoz uses distributed tracing to gain visibility into your software stack.
Join our Slack community
Come say Hi to us on Slack
- Application overview metrics like RPS, 50th/90th/99th Percentile latencies, and Error Rate
- Slowest endpoints in your application
- See exact…