Bash is a Unix shell, which is a command-line interface for interacting with an operating system. It is the default shell on most Linux distributions. In this guide, we will cover the top 15 Linux bash commands along with examples to help you understand how to use them effectively.
Contents
Recommended Books
I can highly recommend these books on Linux Administration if you want to go further.
- The Linux Bible 10th Edition
- The Linux Command Line, 2nd Edition: A Complete Introduction
- Linux Administration: The Linux Operating System and Command Line Guide for Linux Administrators
Top 15 Linux bash commands with examples:
pwd
(print working directory): Displays the current directory you are in.- Example:
pwd
will output/home/user/documents
.
- Example:
ls
(list directory contents): Lists the files and directories in the current directory.- Example:
ls
will outputfile1.txt file2.txt folder1 folder2
.
- Example:
cd
(change directory): Changes the current directory to the specified directory.- Example:
cd /home/user/downloads
will change the current directory to/home/user/downloads
.
- Example:
mkdir
(make directory): Creates a new directory.- Example:
mkdir newfolder
will create a new folder namednewfolder
.
- Example:
rmdir
(remove directory): Deletes an empty directory.- Example:
rmdir oldfolder
will delete the folder namedoldfolder
.
- Example:
touch
(create a file): Creates an empty file.- Example:
touch newfile.txt
will create a new file namednewfile.txt
.
- Example:
rm
(remove file): Deletes a file.- Example:
rm oldfile.txt
will delete the file namedoldfile.txt
.
- Example:
cp
(copy files and directories): Copies a file or directory to a specified location.- Example:
cp file1.txt /home/user/downloads
will copyfile1.txt
to the/home/user/downloads
directory.
- Example:
mv
(move or rename files): Moves a file to a different location or renames a file.- Example:
mv file1.txt file2.txt
will renamefile1.txt
tofile2.txt
.
- Example:
cat
(concatenate files and display them on the standard output): Shows the contents of a file.- Example:
cat file.txt
will display the contents offile.txt
.
- Example:
head
(display the first few lines of a file): Shows the first 10 lines of a file.- Example:
head file.txt
will display the first 10 lines offile.txt
.
- Example:
tail
(display the last few lines of a file): Shows the last 10 lines of a file.- Example:
tail file.txt
will display the last 10 lines offile.txt
.
- Example:
sort
(sort lines of text files): Sorts the lines of a file.- Example:
sort file.txt
will sort the lines offile.txt
.
- Example:
uniq
(display the unique lines in a sorted file): Shows the unique lines of a sorted file.- Example:
sort file.txt | uniq
will sort and show the unique lines offile.txt
.
- Example:
grep
(search for a pattern in a file): Searches for a specified pattern in a file.- Example:
grep pattern file.txt
will search forpattern
infile.txt
.
- Example:
Conclusion
In conclusion, the top 15 Linux bash commands are a powerful tool for managing your operating system through the command-line interface. These commands provide you with the ability to navigate directories, create and delete files and directories, copy and move files, and manipulate the contents of files. Whether you’re a beginner or an experienced Linux user, these commands are essential to have in your toolkit. We hope this guide has been helpful in introducing you to these commands and providing examples to help you understand their usage.
If you are interested in exploring further, there are many resources available online to help you deepen your knowledge of Linux and bash commands. Happy exploring!
See Also
- Install Ubuntu 22.04 Server Edition on Raspberry Pi
- Easily Unzip Files in Linux
- Set permanent DNS nameservers on Ubuntu/Debian with resolv.conf
- How to install Debian Linux – Complete Guide
Comments
There are currently no comments on this article.
Comment