Linux is famous for its easily accessible commands. By using the Linux command line, users can navigate the file system, view and edit files, create directories, and run scripts. Every Linux user should know a few basic commands while using this operating system.
Before we begin, please note:
- Linux commands are case-sensitive.
- “$” indicates the start of a command
- “#” indicates the end of a command and the start of a comment
Top Linux commands you can use:
- ls – The ls command is used to list all the files and directories in the current directory. You can run this command without any parameters.
Syntax:
ls
This can be useful if you need to find a particular file or if you want to know what files are in the current directory. Additionally, this command can also be used to get information about the files and directories, such as the size, type, and timestamp.
Example:
- cd – change the current working directory
This can quickly and easily switch between different directories, allowing you to access the files you need swiftly.
Syntax:
cd <directory name>
Example:
- pwd – print the current working directory
Syntax:
pwd
Example:
- mkdir – create a new directory in the current working directory.
Syntax:
mkdir <directory name>
Example:
- rmdir – To delete a directory, use the rmdir command.
Syntax:
rmdir <directory name>
Example:
- touch – The touch command is used to create a new or empty file. It can also be used to create multiple empty files at once.
Syntax:
touch <file name>
touch <file1> <file2>
Example:
- cat – cat or Concatenate allows you to display the contents of a file, create a file, copy the content of one file to another file, etc.
Syntax:
To display the content of the file:
cat <file name>
To create a file:
cat > [file name]
To copy content from an old to a new file:
cat [oldfile] > [newfile]
Tip: You can save the file by pressing “CTRL+D”
Example:
- tac – As its name suggests, tac is the reverse of cat. The file content is displayed in reverse order from the last line.
Syntax:
tac <file name>
Example:
- cp – The cp helps you to copy a file or directory
Syntax:
To copy the source file to Destination, execute it as follows:
cp [option] Source Destination
To copy the source file to Directory, run the following command:
cp [option] Source Directory
Example:
- wc – Using the wc command, you can count the lines, words, and characters in a file.
Syntax:
wc <file name>
Example:
- mv – The mv command allows you to move a file from one location to another, rename a file or directory
Syntax:
mv <file name> <directory path>
Example:
- rm – This command allows you to remove a file
Syntax:
rm <file name>
Example:
- sort – Use the sort command in order to sort files alphabetically.
Syntax:
sort <file name>
Example:
- head – The head command displays the content of a file. You can view the first 10 lines of a file.
Syntax:
head <file name>
Example:
- tail – Similar to the head command, the tail command allows you to view the last 10 lines of a file.
Syntax:
tail <file name>
Example:
- more – Similar to the cat command, you can use the more command to display the contents of the file. The key difference is that more command displays a full-screen output at a time.
Syntax:
more <file name>
Example:
- less – As the name suggests, the less command is used to display the contents of a file one screen at a time. Due to the fact that it accesses files page by page, it is useful when dealing with large text files.
Syntax:
less <file name>
Example:
- find – You can use it to find files and directories.
Syntax:
find / -name
Example:
- time – You can display the time it takes to run a command with this command.
Syntax:
time
Example:
- su – The su command helps you to provide administrative access to another user.
Syntax:
su <user name>
Example:
- useradd – Using useradd, you can add or remove users on Linux servers.
Syntax:
useradd username
Example:
- passwd – With the help of the passwd command, you can create and change the password for a user.
Syntax:
passwd <username>
Example:
- sudo – sudo (superuser do)
elevates a user’s permissions to execute a command as the superuser (root)
Syntax:
sudo <command>
Example:
- grep – The grep (global regular expression print) command is the most powerful command and filter there is. With it, you can search for a pattern/content in a file.
Syntax:
grep <search string> <filename>
- tr – You can use the tr command to translate the file content.
Syntax:
tr -cds STRING1 STRING2
- df – The df (disk free) command displays the amount of free disk space available on the file system.
Syntax:
df
- du – Using the du command (disk usage), you can determine how much space a file or directory takes up.
Syntax:
du
- uniq –
The uniq command creates a sorted list in which every word appears only once.
Syntax:
command <file name> | uniq
- ssh: You can use the ssh command to connect to a remote server over a secure shell (SSH) protocol
Syntax:
ssh user_name@host(IP/Domain_name)
- history – You can use the history command to view the list of previously executed commands.
Syntax:
history
- man – The man command displays the user manual for any command you execute. It is an inbuilt manual for all commands on Linux.
Syntax:
man [option] [section number] [command name]
Linux has many more commands, but these are some of the most commonly used.
Bonus: What are manual pages in Linux?
The purpose of man pages is to help users understand how the Linux commands are used. The pages are installed by default alongside the commands. Whenever a software developer creates a man page, it will serve as an explanation of how to use that specific command.
You can learn more about each command by using the manual pages. Simply type “man command_name” in the terminal, and there you have it!
Hope our article helped you know more about the Basic Linux Commands. Save this article to your bookmarks for future reference!
Is it your dream to have your own website? Agaetis is here to help you! Contact us today!