Every developer should learn how to use the command line and include it in their regular activities. This article will explore Bash Shell (Bourne Again Shell), which is the most extensively used command-line interface (CLI) and some basic bash commands. You will discover the most commonly used and crucial commands, when to use them, and how to customise them with options.

What is Bash?

BASH stands for Bourne Again Shell, a witty term that pays homage to Bourne Shell (i.e., invented by Steven Bourne). Bash is a shell project designed by Brian Fox as an update to the Bourne Shell application 'sh.' 

It's an open-source GNU project that was first launched in 1989 as one of the most popular GNU/Linux shell distributions. It is more functional than Bourne Shell in terms of programming and interactive use. It comes with command-line editing, key bindings, a complete command history, and more.

Bash is a command-line interpreter that operates in a text window and allows users to interpret commands to perform a variety of tasks. A Shell Script is a sequence of these commands contained within a single file, and these scripts can be read and executed using Bash shell.

20 Most Crucial Bash Commands 

Ls- Listing directory content 

The ls command is arguably the most commonly used one. You'll frequently be working in a directory and need to know what files are contained within it. The ls command helps in rapidly viewing all files in the specified directory.

Options available: -a, -l

echo — Printing texts to the terminal window 

Linux echo writes text to the terminal window and is commonly used to publish status text towards the screen or a computer file in shell scripts and batch files.

Echo is also handy for displaying the contents of environmental variables, which instruct the shell how to act when a user types command or writes scripts.

Options available: -e, -n

touch — Creating files 

Touch is the simplest way to create new files, but it may also be used to update the timestamps on existing files and directories. You can make as many files as you like in one command without worrying about overwriting files with a similar name.

Options available: -a, -m, -r, -d

mkdir — Creating directories 

The mkdir command is used to create folders. A large number of directories can be established at the same time, substantially speeding up the process.

Options available: -m, -p, -v

grep — Searching texts 

Grep is a command that searches for patterns in text that the users specify. It's one of the most useful and effective commands available that is executed every time you're entrusted with finding a specific string or pattern within a file but don't know where to start looking.

Options available: -i, -c, -n

man — Printing manuals for help 

The man command serves as your manual and is quite helpful when determining what a command does. For example, if you didn't know what the command rmdir does, you could look it up with the man command.

Options available: -w, -f, -b

pwd — Displaying running directories 

The command pwd is used to display the current directory. If you have many terminals open and need to remember which directory you're working in, pwd will help you.

Options available: options aren't typically used with pwd.

cd — Changing directories 

Cd changes the directory you're in, allowing you to access, manipulate, and read the various files and directories on your system.

Options available: options aren't typically used with the cd

mv — Moving or renaming a directory 

Mv is a command for moving or renaming directories. You would have to rename each file separately if you didn't use this command, which is time-consuming. You can rename batch files with mv, which can save you a lot of time.

Options available: -i, -b

rmdir — Removing a directory

Empty directories get removed using rmdir. This might help you free up space on your computer and organise your files and folders. It's worth noting that rm and rmdir are the two commands for removing directories.

The difference between the two is that rmdir only deletes empty directories, whereas rm deletes all directories and files, whether or not they contain data.

Options available: -p

locate — Locating a single file or directory 

This is by far the most straightforward method of locating a file or directory. If you're not sure what you're looking for, you can keep your search broad or narrow it down by using wildcards or regular expressions.

Options available: -q, -n, -i

less — View the text of a file 

You can view files without opening an editor with the less command. It's easier to use, and there's no risk of accidentally changing the file.

Options available: -e, -f, -n

compgen — Displays commands, aliases, and functions

compgen is used when the users require to view all the available commands, aliases, and functions.

Options available: -a, -c, -d

cat — Reads/ creates/ concatenate files

Cat is one of the more versatile commands, with three primary uses: showing, combining copies, and making new ones.

Options available: -n

head — Read the start of a file

The head program will display the first 10 lines of a file by default. You may need to glance at a few lines in a file rapidly at times, and the head allows you to do so.

Options available: -n

tail — Read the end of a file

The tail program will display the last 10 lines of a file by default. There are occasions when you may need to glance at a few lines in a file fast, and tail makes this possible.

Options available: -n

chmod — Sets the file permissions flag on a file or folder

There will be times when you're trying to upload a file or alter a document and obtain an error message because you don't have permission. Using chmod is an easy fix for this.

Permissions can be set using alphanumeric characters (u, g, o), and access can be assigned using w, r, and x. You can use octal numbers (0-7) instead to modify the permissions.

Options available: -f, -v

exit — Exit out of a directory

Exit closes a terminal window, stops a shell script from running, or logs you out of an SSH remote access window.

Options available: n/a

clear — Clear your terminal window

All prior commands and output from consoles and terminal windows get cleared with this command. This maintains your terminal clean and clutter-free, allowing you to focus on the commands that follow and their results.

Options available: n/a

kill — terminate stalled processes

You can kill a program from the command line with the kill command. This is accomplished by supplying the process ID (PID). You can use the ps command with the -aux parameters to find the PID.

Options available: -p

Conclusion 

By this stage, you might have a strong idea of how to navigate around using the command line, move raw files, and make modest changes In Linux bash. This beginner-level lesson on bash commands will help you gain basic fluency and confidence.