Linux commands are very important for Linux Beginners. These 20 important Linux Commands will be very useful for you.
In this article, I will show you the 10 basic Linux commands and 10 advanced commands that every beginner must know.
- pwd – Print Working Directory
- ls – List files and directories
- cd – Change directory
- mkdir – Make a new directory
- cp – Copy a file or directory
- mv – Move or rename a file or directory
- rm – Remove a file or directory
- rmdir – Remove an empty directory
- man – Display the manual for a command
- exit – Exit the shell
Advanced Linux commands:
Get Your Free Linux training!
Join our free Linux training and discover the power of open-source technology. Enhance your skills and boost your career! Learn Linux for Free!- grep – Search for a pattern in a file
- find – Find files
- sort – Sort lines of text files
- uniq – Report or filter out repeated lines
- wc – Print byte, word, and line counts
- cut – Select portions of lines
- paste – Merge lines of files
- tr – Translate, delete, or squeeze characters
- dd – Copy and convert files
- tar – Store and extract files from a tarfile archive
These are just some of the basic commands that you need to know in order to get started with Linux. If you want to learn more, there are plenty of resources available online and in books. Just remember to keep practicing and you’ll be a Linux expert in no time!
Table of Contents
Basic Linux Commands
1. ls
The “ls” command is used to list the contents of a directory. For example, the following command will list the contents of the current directory:
ls
You can also use the “ls” command to list the contents of a specific directory. For example, the following command will list the contents of the “/etc” directory:
ls /etc
By default, the output will be in a simple list format, showing the names of files and directories in alphabetical order.
Command | Description |
---|---|
ls | Lists the contents of the current directory. |
ls /path/to/directory | Lists the contents of a specific directory. |
ls -l | Lists the contents of a directory in long format, including detailed information. |
ls -r | Lists the contents of a directory in reverse order. |
ls -a | Lists the contents of a directory, including hidden files. |
ls -lh | Lists the contents of a directory with human-readable file sizes. |
ls -la | Lists the contents of a directory with detailed file information, including hidden files. |
ls -lt | Lists the contents of a directory sorted by modification time, with the newest files first. |
ls -d */ | Lists only directories in a directory. |
2. cd
The “cd” command is used to change the current working directory. For example, the following command will change the current working directory to the “/etc” directory:
cd /etc
Command | Description |
---|---|
cd | Changes the current directory to the user’s home directory. |
cd /path/to/directory | Changes the current directory to the specified directory path. |
cd .. | Moves up one directory level (to the parent directory). |
cd – | Returns to the previous directory (the previous working directory). |
cd ~ | Changes the current directory to the user’s home directory. |
cd ~/directory | Changes the current directory to a subdirectory within the home directory. |
cd / | Changes the current directory to the root directory. |
3. pwd
The “pwd” command is used to print the current working directory. For example, the following command will print the current working directory:
pwd
4. mkdir
The “mkdir” command is used to create a new directory. For example, the following command will create a new directory called “mydirectory”:
mkdir mydirectory
Command | Description |
---|---|
mkdir directory | Creates a new directory with the specified name. |
mkdir -p directory/subdirectory | Creates a directory and any necessary parent directories. |
mkdir -m 755 directory | Creates a directory with specific permissions (in octal format). |
mkdir -v directory | Creates a directory and displays a message for each created directory. |
mkdir –help | Displays the help manual for the mkdir command. |
mkdir –version | Displays the version information of the mkdir command. |
5. rmdir
The “rmdir” command is used to remove an empty directory. For example, the following command will remove the “mydirectory” directory:
rmdir mydirectory
Command | Description |
---|---|
rmdir directory | Removes an empty directory with the specified name. |
rmdir -p directory/subdirectory | Removes a directory and its parent directories if they are empty. |
6. cp
The “cp” command is used to copy files and directories. For example, the following command will copy the “/etc/passwd” file to the “/tmp” directory:
cp /etc/passwd /tmp
Command | Description |
---|---|
cp source_file destination | Copies a file to the specified destination. |
cp file1 file2 | Copies file1 to file2. |
cp -r source_directory destination | Copies a directory and its contents recursively to the destination. |
cp -a source destination | Copies files and directories while preserving their attributes. |
7. mv
The “mv” command is used to move files and directories. For example, the following command will move the “/etc/passwd” file to the “/tmp” directory:
mv /etc/passwd /tmp
8. rm
The “rm” command is used to delete files. For example, the following command will delete the “/tmp/passwd” file:
rm /tmp/passwd
9. man
The “man” command is used to display the manual pages for a command. For example, the following command will display the manual pages for the “ls” command:
man ls
10. grep
The “grep” command is used to search for a text pattern in a file. For example, the following command will search for the text pattern “hello” in the “/etc/passwd” file:
grep hello /etc/passwd
Advanced Linux Commands
1. chmod
The “chmod” command is used to change the permissions of a file. For example, the following command will give the user read and write permissions for the “/tmp/passwd” file:
chmod u+rw /tmp/passwd
2. chown
The “chown” command is used to change the owner of a file. For example, the following command will make the user “bob” the owner of the “/tmp/passwd” file:
chown bob /tmp/passwd
3. find
The “find” command is used to search for files. For example, the following command will search for all files in the “/tmp” directory:
find /tmp -type f
4. ps
The “ps” command is used to display information about the currently running processes. For example, the following command will display information about all running processes:
ps aux
5. top
The “top” command is used to display information about the currently running processes. For example, the following command will display information about all running processes:
top
6. kill
The “kill” command is used to kill a process. For example, the following command will kill the process with the ID “12345”:
kill 12345
7. ssh
The “ssh” command is used to connect to a remote machine using SSH. For example, the following command will connect to the machine with the IP address “192.168.1.100”:
ssh 192.168.1.100
8. scp
The “scp” command is used to copy files over SSH. For example, the following command will copy the “/etc/passwd” file from the local machine to the machine with the IP address “192.168.1.100”:
scp /etc/passwd 192.168.1.100:/tmp
9. wget
The “wget” command is used to download files from the web. For example, the following command will download the “/etc/passwd” file from the local machine to the machine with the IP address “192.168.1.100”:
wget http://192.168.1.100/passwd
10. curl
The “curl” command is used to download files from the web. For example, the following command will download the “/etc/passwd” file from the local machine to the machine with the IP address “192.168.1.100”:
curl http://192.168.1.100/passwd -o /tmp/passwd
These are just a few of the most commonly used Linux commands. There are many more that can be used to perform various tasks. Experiment with different commands and see what they do. Also, check out the man pages for each command (e.g., “man ls”) to learn more about them.