What are the Basic Linux Commands and How to use

Today, We will learn what are the basic Linux command and how to use this. Read: nmcli – Linux command

1. pwd — pwd command is used to show the current working directory of the user. To know which directory you are in, you can use the “pwd” command. It gives us the absolute path, which means the path that starts from the root. The root is the base of the Linux file system. It is denoted by a forward slash( / ). Read more: PWD – Linux command to check current working directory

Let’s see the example below:

Last login: Mon Oct  4 08:22:49 2021 from 192.168.0.20
[root@localhost ~]# pwd
/root
[root@localhost ~]#

2. ls — Use the “ls” command to know what files are in the directory. “ls” command is used to list the files and directory in the directory. You can see all the hidden files by using the command “ls -a”. Let’s see the example below. Read more ls command

[root@localhost ~]# ls
anaconda-ks.cfg                 Documents  Public             www.w3schools.com
anydesk-6.1.0-1.el7.x86_64.rpm  Downloads  Templates
Desktop                         Music      thinclient_drives
dialer-key.pem                  Pictures   Videos
[root@localhost ~]#

[root@localhost ~]# ls -a
.                               Desktop         .ssh
..                              dialer-key.pem  .tcshrc
anaconda-ks.cfg                 Documents       Templates
.anydesk                        Downloads       thinclient_drives
anydesk-6.1.0-1.el7.x86_64.rpm  .ICEauthority   Videos
.bash_history                   .local          .viminfo
.bash_logout                    .mozilla        .vnc
.bash_profile                   Music           www.w3schools.com
.bashrc                         .mysql_history  .Xauthority
.cache                          Pictures        .xsession-errors
.config                         .pki
.cshrc                          Public

You can see from the above example that the “ls” command is showing all the files and folders in the current directory. Also “ls -a” is showing all the files including hidden files and folders in the current directory.

3. cd — Use the “cd” command to go to a directory. For example, if you are in the home folder, and you want to go to the downloads folder, then you can type in “cd Downloads”. Remember, this command is case-sensitive, and you have to type in the name of the folder exactly as it is. Read more cd : linux command

[root@localhost ~]# cd Downloads/
[root@localhost Downloads]# pwd
/root/Downloads
[root@localhost Downloads]#

4. mkdir & rmdir — Use the “mkdir” command when you need to create a folder or a directory. For example, if you want to make a directory called “DIY”, then you can type “mkdir DIY”. Read more mkdir : linux command

Remember, as told before, if you want to create a directory named “DIY Hacking”, then you can type “mkdir DIY\ Hacking”. Use rmdir to delete a directory. But “rmdir” can only be used to delete an empty directory. To delete a directory containing files, use rm.

[root@localhost Downloads]# mkdir DIY
[root@localhost Downloads]# ls
chl.pem  dialer-key.pem  DIY
[root@localhost Downloads]# rmdir DIY
[root@localhost Downloads]# ls
chl.pem  dialer-key.pem
[root@localhost Downloads]#

5. rm – Use the rm command to delete files and directories.  Use “rm -r” to delete just the directory. It deletes both the folder and the files it contains when using only the rm command. To delete the files and directory forcefully, use “rm-rf“. Read more rm command to delete files in linux

6. touch — The touch command is used to create a file. It can be anything, from an empty text file to an empty zip file. For example, “touch new.txt”.

7. man & –help — To know more about command and how to use it, use the man command. It shows the manual pages of the command. For example, “man cd” shows the manual pages of the cd command. Typing in the command name and the argument helps it show which ways the command can be used (e.g., cd –help).

8. cp — Use the cp command to copy files through the command line. It takes two arguments: The first is the location of the file to be copied, the second is where to copy. Use “cp -r” to copy the file recursively. Read more CP : Linux Command

9. mv — Use the mv command to move files through the command line. We can also use the mv command to rename a file. For example, if we want to rename the file “text” to “new”, we can use “mv text new”. It takes the two arguments, just like the cp command. Read more Rename Multiple Files In Linux using mmv command

10. locate — The locate command is used to locate a file in a Linux system, just like the search command in Windows. This command is useful when you don’t know where a file is saved or the actual name of the file. Using the -i argument with the command helps to ignore the case (it doesn’t matter if it is uppercase or lowercase). So, if you want a file that has the word “hello”, it gives the list of all the files in your Linux system containing the word “hello” when you type in “locate -i hello”. If you remember two words, you can separate them using an asterisk (*). For example, to locate a file containing the words “hello” and “this”, you can use the command “locate -i *hello*this”. Read more Find Linux Command : Basic

11. df — Use the df command to see the available disk space in each of the partitions in your system. You can just type in df in the command line and you can see each mounted partition and their used/available space in % and in KBs. If you want it shown in megabytes, you can use the command “df -m”. Read more du and df Command : Find Size of a directory & Free disk space in linux

12. du — Use du to know the disk usage of a file in your system. If you want to know the disk usage for a particular folder or file in Linux, you can type in the command df and the name of the folder or file. For example, if you want to know the disk space used by the documents folder in Linux, you can use the command “du Documents”. You can also use the command “ls -lah” to view the file sizes of all the files in a folder.

13. chmod — Use chmod to make a file executable and to change the permissions granted to it in Linux. Imagine you have a python code named numbers.py on your computer. You’ll need to run “python numbers.py” every time you need to run it. Instead of that, when you make it executable, you’ll just need to run “numbers.py” in the terminal to run the file. To make a file executable, you can use the command “chmod +x numbers.py” in this case. You can use “chmod 755 numbers.py” to give it root permissions or “sudo chmod +x numbers.py” for root executable. Read more Unix File Permissions

 14. hostname — Use hostname to know your name in your host or network. Basically, it displays your hostname and IP address. Just typing “hostname” gives the output. Typing in “hostname -I” gives you your IP address in your network. Read more change server hostname on linux/centos

[root@localhost Downloads]# hostname
localhost.localdomain

15. ping — Use ping to check your connection to a server. Wikipedia says, “Ping is a computer network administration software utility used to test the reachability of a host on an Internet Protocol (IP) network”. Simply, when you type in, for example, “ping google.com”, it checks if it can connect to the server and come back. It measures this round-trip time and gives you the details about it. The use of this command for simple users like us is to check your internet connection.

[root@localhost Downloads]# ping google.com
PING google.com (142.250.193.46) 56(84) bytes of data.
64 bytes from del11s15-in-f14.1e100.net (142.250.193.46): icmp_seq=1 ttl=120 time=4.20 ms
64 bytes from del11s15-in-f14.1e100.net (142.250.193.46): icmp_seq=2 ttl=120 time=3.56 ms

Point to be noted while Using Linux Command Line

  • You can use the clear command to clear the terminal if it gets filled up with too many commands.
  • TAB can be used to fill up in terminal. For example, You just need to type “cd Doc” and then TAB and the terminal fills the rest up and makes it “cd Documents”.
  • Ctrl+C can be used to stop any command in terminal safely. If it doesn’t stop with that, then Ctrl+Z can be used to force stop it.
  • You can exit from the terminal by using the exit command.

One thought on “What are the Basic Linux Commands and How to use

Leave a Reply