This guide lists out all the top most used basic Linux commands every day on your Linux system. You can use the following commands on any Linux distributions like Ubuntu, Debian, CentOS, Fedora, RedHat, ArcLinux.
The following commands are executed in Command Line which is referred as Linux-shell. Let’s get to the common commands used everyday.
Basic Linux Commands
You can get help for any command using the following syntax.
command_name --help
There is a manual for each command, you can use the man command to get more details about the command.
man command_name
1. pwd – Print Working Directory
pwd
command is used to find the path the current directory you were currently working on.
pwd Output /home/username
2. ls – List
ls
command outputs all the directories, files that are located on the current directory.
ls
Output
file1.txt folder-1
file2.txt folder-2
3. cd – Change Directory
cd
command is used to navigate to a new directory. When used without any arguments it will take you to your home directory.
# takes you to your home directory cd # To navigate to the parent directory cd ../ # To change to previous working directory cd ~
4. mkdir – Make Directory
mkdir
command is used to create new directories in a specific location.
# Create new directory mkdir directory_name # Create nested directories mkdir -p directory_name/child_directory_name
5. touch – Timestamps
touch
command is used to update timestamps of an existing file or create a new file with the current timestamp.
touch file1.txt
6. mv – Move
mv
command is used to move a file or directory to another location or change the directory name to a different one.
# Renaming a file mv file1.txt file2.txt # Renaming a directory mv folder1 folder2 # move file from one directory to another directory mv folder1/test.txt folder2/test.txt
7. cp – Copy
cp
command is used to copy file to another file on same location or another location.
You can use the -R
option copy all files from one location to another location.
# copy file to a new file cp file1.txt file2.txt # copy file to new loaction cp file.txt /home/username # copy all contents of directories to another directory cp -R directory /home/username/public
8. rm – Remove
rm
command is used to remove a specific file or set of files with specific extension or remove a directory with all contents.
You need to be careful while using this command.
# remove a specific file rm /home/username/filename.txt # remove files with specific extension rm -rf *.txt # remove a directory with contents in it rm -rf directory_name
9. chmod – Change Mode
chmod
command is used to change mode of an object so that it can have read, or read write or read write and execute permissions.
- The first number stands for the user who is associated with the file.
- The second number is for the group associated with the file.
- The third number is associated with everyone else who is not a part of the user or group.
Octal Notation | Permission | Symbolic Representation |
---|---|---|
0 | No Permission | — |
1 | Execute Permission Only | –x |
2 | Write Permission Only | -w- |
3 | Write and Execute Permissions (1+2)=3 | -wx |
4 | Read Permission Only | r– |
5 | Read and Execute Permissions (1+4)=5 | r-x |
6 | Read and Write Permissions (2+4)=6 | rw- |
7 | Read, Write and Execute Permissions, Means Full Permissions (1+2+4)=7 | rex |
chmod 644 private-key.pem
10. cat – Concatenate
cat
command is one of the most commonly used command to create single or multiple files, view contents of file, concatenate files and redirect output in terminal or files.
cat file.txt
This command will outputs the content of the file.
Prepare yourself for a role working as an Information Technology Professional with Linux operating system
Conclusion
Now you have learned the basic commands that are used every day.
Thanks for your time. If you face any problem or any feedback, please leave a comment below.