Basic Linux Commands


If you run a Linux distribution, and you only using the GUI, you are missing out. The Linux terminal is very powerful than normal GUI. Learning commands or using Linux terminal is not that difficult, however it might look scary at the beginning.

Some important information about Linux Terminal:



Linux commands are case-sensitive
It is to be noted that everything you write in the terminal is case-sensitive.

For eg: When the command is "clear", neither "Clear", "CLEAR", nor "cLeAR" will work.
And, the Linux commands are lowercase. Some commands may use capitalized switches such as: "chown -R"
The file and directory names are also case-sensitive. "file1" and "FILE1" are not same, even if both the files are in same directory.

Watch out spaces
For eg: "fdisk-l" will not return any output, rather it will give an error because the current syntax contains space between fdisk and -l. (fdisk -l)

Finding the previous Linux commands
You don't need to type again the commands everytime. You can use the up arrow key from keyboard to find all the previous typed commands.

Use Tab to autocomplete
The "Tab" button in your keyboard is a huge time saver on Linux Terminals, as it will automatically fill in the names of files, directories and even Linux Commands.

For eg: if you created a file with name "jintrnfinrtungmfu"
You don't need to type in the whole name.
Just type "rm j" and pressing Tab will automatically detect the filename and complete it.

Copying and pasting the Linux commands
To copy or paste on the terminal, Ctrl+C and Ctrl+V won't work.
Instead, Ctrl+Shift+C and Ctrl+Shift+V should be used for copying and pasting.


BASIC LINUX COMMANDS


1. pwd command

This command prints the location of current working directory. In other words, it gives you the information about where you are in the system.

2. ls command

The ls command lists all the files and directory present in your current working directory.


3. cal command

Typing the "cal" command will display the calender of the current month.


4. date command

Displays the "date and time" of the system including the weekdays and GMT.


5. history command

This command shows all the commands that you have entered in the terminal.


6. whoami command

Displays the username of the logged in user.



7. uname -a command

Displays the hardware and software information (architecture, kernel etc.)


8. cd command

cd <dirname>    --------   Change the working directory to new one.
cd or cd~         --------          Move to the user's home directory.
cd ..                  --------          Move back to the parent directory.
cd /              --------              Change to the root directory.


9. clear command

This commands clears the terminal screen.


10. man command

The man command is the most useful commands in Linux. It shows the manual pages of a command. The argument to the man command can be a program, a utility or a function.

For e.g. if you want to bring up the "man" page of ls command,         simply type: # man ls 


11. mkdir command

Whenever we need to create a directoy, we use "mkdir". In order to create the directory anywhere on the system, we need to specify the full pathname.

Creating directories with "sudo mkdir" does not let you to create files or directories inside that directory without administrative rights.


12. rmdir command

This command is used to remove the empty directory. If the directory is not empty, this command cannot be used to remove it.


13. touch command

Used for creating empty files.
Let's create an empty file inside the NewDir that we previously created in Desktop. Or you can create a NewDir and create a file inside it.


14. rm command

This command is used for removing the files and directories.
Just type  # rm -r <dirname>  to remove any directory.
Or,  # rm <filename>  to remove any file.


15. Create a file:

 To create a file, there are various methods we can apply:
    • using cat command
                       # cat > <filename>
                                ................
                                ...............
                                  Text........
                      CTRL + D ---------->  (To save and exit.)


    • using 'vi' editor (MOST POPULAR METHOD)
                      vi <filename> 
                      Press 'i' before typing anything. (i ----------> INSERT)


                     Then, press 'Esc' and ':wq' ----------> To save and exit
          OR, press 'Esc' and  ':q!' ----------> To exit without saving


    • using 'nano' editor
                    # nano <filename>  
                    CTRL + X  ----------> Save and Exit
                    Save? Y (Y ---------->Yes)
                    filename? (Press Enter)

    • using 'gedit' (Graphical editor like notepad)
                    # gedit <filename> 
                   CTRL + S   ----------> To save the change then close the app.


16. Viewing content of a file

     To view the content of your file on terminal, type the following command:
         # cat <filename> 


17. Modifying content of a file

     To modify the content of a file, we may use various commands like vi, gedit, nano, cat. We prefer 'vi', because it is the best one among all.
        # vi <file to be modified> 
 
Then, press 'Esc' and ':wq' ----------> To save and exit                     
OR, press 'Esc' and  ':q!' ----------> To exit without saving


18. df command

The command is used to check disk space usage on a linux system. The most common usage is along with the -h flag.


19. free command

The free command is used as : # free -h 


20. fdisk command

fdisk is a tool for getting the partition information, and for adding and removing partitions. To list all the partitions of all the hard drives available:


21. ping command

The ping command is used for testing and troubleshooting the network connectivity.
It works by sending ICMP (Internet Control Message Protocol) Echo Requests.

The general syntax for ping command is: # ping <destination ip/name> 

By default, the ping command goes endless and to stop it you need to press Ctrl + C to exit.

You can limit the number of attempts by using the "-c" switch as follows:

You can also set deadline of how long to run the ping command by using the "-w" switch.
This sets a deadline for the ping to last for 5 seconds. 


22. ifconfig command

ifconfig stands for interface configuration, and it is used to perform many network related things.
Some basic use for begineers could be like checking which network interfaces are connected and their respective IP address.
Or you can find out how much data passed through a specific interface, all could be done just by running the ifconfig command.


23. echo command

The echo command is used to display the line of text in the terminal. You can also move some text data into a file using the echo command.


24. stat command

This command is used to check the status of the file. This provides the more detailed information about the file.
The general syntax for stat command is : # stat <filename> 


25. wc command

This command counts the number of lines, words and letters of the file given to it.

CONCLUSION

So that's all about basic linux commands that you should know.
Hope you guys enjoyed this very long yet useful tutorial.

Post a Comment

0 Comments