It doesn’t matter if you are a beginner, intermediate, or advanced Linux user. This Basic command you should know.
Just bookmark this page because you require this command to work for daily use.
Let’s start the Basic command journey
Table of Contents
1. pwd Command
We use the pwd command when we want to know the name of the current working directory.
Syntax
trendoceans@LINUX:~$ pwd
Output
/home/trendoceans
When you pass the pwd command in the terminal, you will get the full path of the current working directory.
It will always start from the forward Slash (/) after that directory name.
2. cd Command
When you want to navigate or switch back to another directory or folder, we use the cd command, and the cd command stands for Change Directory.
Syntax
trendoceans@LINUX:~$ cd /DirectoryName
How to use the CD command? For example, I want to go inside the Download folder, and I have checked my current working directory using the pwd command. From that, I know my current directory is “/home/trendoceans”.
So, what I need to do go inside the download folder. I’ll type “cd /Downloads”, and now I’m inside the Download folder.
trendoceans@LINUX:- $ cd Downloads
If the current working directory is “/usr/share”, I need to go to the download folder for that type the command.
trendoceans@LINUX:/usr/share$ cd /home/trendoceans/Downloads/
Now verify the current Directory using pwd command.
trendoceans@LINUX:~/Downloads$ pwd
/home/trendoceans/Downloads
It will only go to the next directory if the directory is present and type the correct directory name; otherwise, you will get an error.
I’ll provide you useful shortcuts that you can use while working on directories.
- [cd or cd –]:- If you want directly jump to the home folder, then simply type cd or cd — and you will back to your home directory. It doesn’t matter what your current directory is. There are many shortcuts to go back to the home directory.
- [cd..]:- When you want to go back one step to the previous directory, then pass command cd… you will back to the last directory.
- [cd-]:-If you want to go back to the last working directory, then type command cd-.
To get more information about cd command pass man cd in terminal.
Read this:- How To Install Steam On Ubuntu-based Distribution?
3. ls Command
The ls command is used mostly when we want to know the contents or file present in the current working directory. An ls command stands for the list directory.
Syntax
trendoceans@LINUX:~/$ ls
How to use the ls command? For example, If you want to check what is the file available in the/Download folder, then type the command.
trendoceans@LINUX:~/Downloads$ ls
Output
File.....1
File.....2
File.....
File.....
File.....N
An ls command accepts several parameters such as ls -a, ls -al, ls -g, and many more.
I’ll explain you few ls – with parameters.
- [ls -a]:- This will list all the hidden files. In Linux, all the hidden files or directories starting with .filename.
- [ls -al]:- This command will show all the information about files or directories like permissions, the number of files in a directory, username, group name, size, Date & time, and last Filename.
- [ls -g]:- It will list the according to the group name, including file information such as file permissions, number of the file in a directory, group name, size of file, Date & Time, and last Filename.
To get more information about cd command pass man ls in terminal.
4. cp Command
We use the cp command to copy files or directories from the current working directory to a different location. A cp command stands for copy files and directories.
Syntax
trendoceans@LINUX:~/$ cp file /destination_directory
How to use the cp command? For example, If you want to copy a file from the home directory to the Download folder, then type the command.
trendoceans@LINUX:~/$ cp demo.txt /home/trendoceans/Downloads
The same command will not work if you want to copy a directory or folder to another folder. For that, you need to pass the parameter – r.
trendoceans@LINUX:~/$ cp -r demo /home/trendoceans/Downloads
A cp command accepts several parameters such as cp -a, cp -b, cp -f, and many more.
To get more information about cp command pass man cp in terminal.
5. mv Command
We use the mv command to move files or directories from the current working directory to a different location. An mv command stands for the move or renames files and directories.
Syntax
trendoceans@LINUX:~/$ mv file /destination_directory
How to use the mv command? For example, If you want to move a file from the home directory to the Download folder, type it.
trendoceans@LINUX:~/$ mv demo.txt /home/trendoceans/Downloads
To rename file name pass command.
trendoceans@LINUX:~/$ mv oldfilename newfilename
An mv command accepts a number of parameters such as mv -b, mv -f, mv-v, and many more.
To get more information about cp command pass man mv in terminal.
6. mkdir Command
The mkdir command is used mostly when we want to create a folder or directory in the current working directory. A mkdir command stands for make directory.
Syntax
trendoceans@LINUX:~/$ mkdir filename
How to use the mkdir command? For example, If you want to create a new file in the current directory, then type the command.
trendoceans@LINUX:~/$ mkdir demofile
A mkdir command accepts many parameters such as mkdir -m, mkdir -p, mkdir -v, and many more.
To get more information about the mkdir command pass man mkdir in the terminal.
Read this Permission Command in Linux: chmod
7. rmdir Command
We use the rmdir command mostly when we want to remove a folder or directory from the directory. A rmdir command stands for remove empty directory.
Syntax
trendoceans@LINUX:~/$ rmdir filename
How to use the rmdir command? For example, If you want to remove the file from the current directory then type the command.
trendoceans@LINUX:~/$ rmdir demofile
Note:- This command only work when selected directory is empty.
A rmdir command accepts a number of parameters such as rmdir -m, rmdir -p, rmdir -v, and many more.
To get more information about the rmdir command pass man rmdir in the terminal.
8. rm Command
The rm command is used mostly when we want to remove a file or directory from the current working directory. An rm command stands for remove files or directory.
Syntax
trendoceans@LINUX:~/$ rm filename
How to use the rm command? For example, If you remove to file from the current directory, then type the command.
trendoceans@LINUX:~/$ rm demofile
Note:- If you want to remove a directory containing a file, use the rm -r filename.
An rm command accepts a number of parameters such as rm -f, rm -r, rm -d, and many more.
To get more information about rm command type man rm in a terminal.
9. df command
We use the df command to get a complete report about disk usage When you run the command it shows the report like Filesystem name, Block size by default used data will be shown in KB and percentage, Available space, and the last it will show mount location.
A df command stands for the Disk free.
Syntax
trendoceans@LINUX:~/$ df
How to use the df command? For example, If you want to get the complete disk usage in human-readable format (1024), then type the command.
trendoceans@LINUX:~/$ df -h
A df command accepts a number of parameters such as df -a, df -m, df –l, and many more.
To get more information about df command type man df in a terminal.
10. du command
A du command is used to check the file, and directories size in a recursive manner and It stands for Disk usage.
When you pass the du command without any parameters it will list out the current directory file size in KBs.
Syntax
trendoceans@LINUX:~/$ df {directory-name or filename}
How to use the du command? For example, If you want to know how much space utilized by “demofile”, type the command.
trendoceans@LINUX:~/$ du demofile
A df command accepts a number of parameters such as du-a, du -c, du -h, and many more.
To get more information about du command type man du in a terminal.
11. touch Command
The touch command is used when we want to create a blank file in the current directory or update the timestamp of an existing document. A touch command stands for change file timestamps.
Syntax
trendoceans@LINUX:~/$ touch filename.txt
How to use the touch command? For example, If you want to create a blank file in the current directory, then type the command.
trendoceans@LINUX:~/$ touch demofile.txt
A touch command accepts a number of parameters such as touch -f, touch -a, touch -d, and many more.
To get more information about the touch command type man touch in a terminal.
12. cat Command
The cat command is used when we want to read any file in the terminal. A cat command stands for concatenating files and print on the standard output.
Syntax
trendoceans@LINUX:~/$ cat filename.extension
How to use the cat command? For example, If you want to read a text file from the current directory, then type the command.
trendoceans@LINUX:~/$ cat demofile.txt
A cat command accepts a number of parameters such as cat -A, cat -E, cat -n, and many more.
To get more information about the cat command type man cat in a terminal.
I hope so you able to understand this basic command which every linux user should know.
If you face any issue please let me know in comment section and bookmark this page.I’ll post more command in upcoming days.
13. grep command
A grep command is used when we want to search any specific word or file from the large set of data grep will find and print on the terminal.
The grep command stands for “Global regular expression print”.
Syntax
trendoceans@LINUX:~/$ grep "enter_keyword"
How to use the grep command? For example,I have type the command top this will list all the running process, and from this I want to check wheter chrome is running or not, To check I’ll use the following command.
trendoceans@LINUX:~/$ top | grep "chrome"
A grep command accepts a number of parameters such as grep -e, grep -f, grep -i, and many more.
To get more information about the grep command type man grep in a terminal.
14. locate command
A locate command is used basically to search the location of a specific file, benefits of using the locate command it is case-insensitive, In case you don’t the exact name then also you can search easily.
The locate command according to man page it mean “locate -find files by name“.
Syntax
trendoceans@LINUX:~/$ locate "enter_filename"
How to use the locate command? For example, I want to find the location where I stored my books, To check I’ll use the following command.
trendoceans@LINUX:~/$ locate books
This command will list all the books are available on my disk.
A locate command accepts a number of parameters such as locate -A, locate -i, locate -r, and many more.
To get more information about the locate command type man grep in a terminal.
A man with a tech effusive who has explored some of the amazing technology stuff and is exploring more. While moving towards, I had a chance to work on Android development, Linux, AWS, and DevOps with several open-source tools.