
The terminal is the heart of the Linux operating system. You can manage your entire Linux system with a terminal. From navigating the file system to managing software, everything can be done through a terminal. If you are a new Linux user, the terminal seems to be overwhelming. But it is easy to use, and you should use the terminal.
You can use the terminal in many different ways using Linux commands. If you want to install or remove software or update your system, you need the terminal. You can do these with a GUI tool but a terminal is the quickest and the easiest way to do it. Before we dive into the basic commands, first we should know what a Linux command is.
What Is A Linux Command?
A Linux command is a command that is entered into the command-line interface (CLI) of a Linux operating system. These commands are used to perform various tasks such as managing files and directories, managing packages, monitoring system processes, etc. They are the primary means of interacting with the Linux kernel.
They can be used to perform a wide range of tasks, from simple ones like listing the contents of a directory, to complex ones like configuring network settings or installing software.
Commands are typically composed of a command name and one or more options or arguments. The command name specifies the action to be taken, and the options and arguments provide additional information that is required to perform the task.
For example, the “ls” command is used to list the contents of a directory, and the “-l” option can be used to display additional information such as permissions and file sizes.
Linux commands are typically entered into the command-line interface, also known as the terminal. It is a text-based interface that allows users to interact with the operating system.
Users can enter commands by typing them into the terminal and pressing the Enter key. Once a command is entered, the operating system will execute it, and the results will be displayed in the terminal.
Overall, Linux commands are a powerful tool for managing and interacting with your Linux system.
1. sudo – Run Command As Root User
sudo
is used to run commands as the root user. It is necessary for performing tasks that require root privileges, such as installing or removing packages. The syntax is:sudo [command]
2. ls – List The Contents Of A Directory
ls
is used to list the contents of a directory. It is a very basic command, but it is used frequently when navigating the file system. It can also be used with various options to display additional information about the files and directories.ls
is:ls [options] [directory]
ls
include:-a
to show hidden files in linux.-l
to display the contents in a long format-h
to display file sizes in human-readable format
3. cd – Change The Current Working Directory
cd [directory]
Command | Description |
---|---|
cd ~ |
Change to the home directory |
cd / |
Change to the root directory |
cd .. |
Change to the parent directory |
4. cp – Copy Files And Directories
cp
command in the terminal. It can be used to copy a single file or multiple files at once. The syntax is:cp [file_name] [new_location]
To copy a directory, you need to use the -r
option to copy directories recursively. The syntax is:
cp -r [source_dir] [dest_dir]
5. mv – Move Files And Directories
mv [source] [destination]
6. rm – Remove Files
rm
command to remove files within a directory. The basic syntax is:rm [options] [file]
-r
option when removing directories and the -f
option when removing write-protected files.You can see the options list using the following command in the terminal.
rm --help
7. mkdir – Create A New Directory
mkdir [options] [directory]
The mkdir command accepts many options, such as:
-p
or–parents
create a directory between two existing folders.-m
sets the file permissions.-v
prints a message for each created directory.--help
display this help and exit.--version
output version information and exit.
8. rmdir – Remove A Directory
rmdir [options] [directory]
The rmdir command accepts many options, such as:
--ignore-fail-on-non-empty
ignore each failure solely because a directory is non-empty.-p
,--parents
remove DIRECTORY and its ancestors.-v
,--verbose
output a diagnostic for every directory processed.--help
display this help and exit.--version
output version information and exit.
9. nano – A Simple Text Editor
nano [file_name]
10. cat – Concatenate Files
The cat
(concatenate), a command is used to display the contents of a file in the terminal. You can use it to view the contents of any plain text file, such as a configuration file or a script. It can also be used to concatenate multiple files together and display them in the terminal.
It is a simple and versatile command that is commonly used for quick file viewing, troubleshooting, and debugging. You can also create new files by redirecting the output of other commands to a new file using the “>” operator.
Command | Description |
---|---|
cat > file1.txt |
Creates a new file named “file1.txt“ |
cat file1.txt file2.txt > file3.txt |
Merges file1.txt and file2.txt and saves the output in file3.txt. |
tac file.txt |
Displays content in reverse order. |
You can see the options list using the following command in the terminal.
cat --help
11. grep – Finds Words In A File
The grep
(Global Regular Expression Print), a command is used to search for specific patterns or text within one or more files. It can be used to search for a specific word or phrase or to search for a regular expression pattern. The grep command returns all lines of text that match the search criteria, making it a useful tool for troubleshooting and debugging.
Command | Description |
---|---|
grep Ubuntu file1.txt |
It will display lines that contain Ubuntu in file1.txt in the terminal. |
egrep 'Ubuntu|Linux' file1.txt |
You can search multiple keywords like this. |
You can see the options list using the following command in the terminal.
grep --help
12. find – Search Files And Directories
The find
command is used to search for files and directories on a Linux system. You can search for files based on various criteria such as name, type, size, and date modified. Here is a great blog post from Tecmint describing the Find Command with examples.
Command | Description |
---|---|
find . -name file1.txt |
Find the file named file.txt in the current directory. |
find /home -name file1.txt |
Find the file named file.txt in the Home directory. |
find /home -type d -name BLD |
Find the directory named BLD in the Home directory. |
You can see the options list using the following command in the terminal.
find --help
13. tar – Archive And Extract Files
The tar
command is used to create, extract, and manage archive files on a Linux system. To create an archive of one or more files or directories and compressed them, you can use this tar command.
It can also extract the contents of an archive file, which is useful for restoring backups or extracting files from an archive created by another system. You can read this blog post to see the usage with examples.
Syntax:
tar [options] [archive-file] [file or directory to be archived]
Option | Description |
---|---|
-c |
Creates an archive. |
-x |
Extract an archive. |
-f |
Creates an archive with a given filename. |
-u |
Archives and adds to an existing archive file. |
-v |
Displays Verbose Information. |
-t |
Display the contents of an archive file. |
-A |
Concatenates the archive files. |
-z |
Filter the archive through gzip |
-j |
Filter the archive through bzip2 |
-r |
Appends files to the end of an archive |
-W |
Attempts to verify the archive after writing it. |
You can see the options list using the following command in the terminal.
tar --help
14. killall – Terminate Running Processes
The killall
command is used to terminate one or more running processes on a Linux system. You can kill processes by name, rather than by their process ID, which can be useful when multiple instances of a process are running.
Syntex:
killall [option] [program_name]
You can see the options list using the following command in the terminal.
killall --help
15. wget
The wget
command is used to download files from the internet. You can download a single file, or download multiple files in a batch with this command. It can also be used to download entire directories or to download files over secure connections (HTTPS).
The wget command is a powerful and versatile tool that can be used to automate the process of downloading files, and it is commonly used in scripts and other automated tasks.
Syntex:
wget [option] [URL]
You can see the options list using the following command in the terminal.
wget --help
16. reboot – Reboot The System
reboot
17. poweroff – Shutdown The System
poweroff
18. man – View The Manual Pages Of A Command
man command_name
19. chmod – Setup Permissions Of A File Or Directory
chmod 600 demo.txt
20. top – Shows The Current Running Processes
top
21. ps – Shows The Running Processes
ps
22. lsof – To View The Files That Are Currently Open By Processes On The System
lsof
Conclusion
These are just a few of the basic commands that every Linux user should know. Knowing these commands will allow you to perform basic tasks on your system and make your experience with Linux much more enjoyable.
Leave a Reply