Skip to content

25 Basic Linux Commands

A resourceful person should know how to use Linux commands. Here are some of the most important ones for everyday use.

We’ve compiled a list of 25 basic Linux commands for you to become more familiar with. Each command has a brief description below it, and there is also a link for you to learn more about the command on the web if you want to.

1. ls Command

The ls command is used to list files and directories that exist within another directory. It can also be combined with other parameters to view additional information, for example -l. 

Examples:

  • ls-l
    Shows the list by columns and with details.
  • ls / directory-name
    Lists the contents of the specified directory.

2. cd command

With the cd command we can change the directory in which we are in the terminal. On a desktop operating system, this would be the equivalent of double-clicking on a folder to open it and view its contents. 

Examples:

  • cd ..
    We go up one level directly with respect to the directory in which we are.
  • cd / directory-name
    Opens the directory specified in the path.

3. pwd command

With the pwd command we can see the name of the directory in which we are in the terminal. It would be like asking the system Where am I? , something very useful in a system managed from the command line.

4. Cat command

The cat command is used primarily to view the contents of a file or to create a file to write to. 

Examples:

  • cat file-name.txt
    This will display the contents of the file in the terminal.
  • cat> file-name.txt
    When using > we create the file with the indicated name to edit it and add the text we want.
  • cat file1 file2> file3.txt
    Copies the contents of multiple files to a third party.

5. mkdir command

The mkdir command is used to create the directories we need from the command line. To use it you must put the command mkdir followed by the name of the directory you want to create. You can also use / to create a directory within another directory. 

Examples:

  • mkdir Directory1
    This will create a directory with the set name.
  • mkdir Directory1 / Directory2
    This will create Directory2 within Directory1.

6. rmdir command

If you have created a directory, you can also delete it by using the rmdir command You can only delete directories that have no content inside and it does not ask for confirmation, when you use the rmdir command , it will delete it. Examples:

  • rmdir Directory1
    Removes Directory1, as long as it is empty.
  • rmdir Directory1 / Directory2
    Deletes Directory2.

7. Touch Command

The touch command allows us to create a document with the name we assign it, ready for editing. Its use is very simple, but remember that then you have to add the content to the file, it does not copy any information. 

Examples:

  • touch file1.txt
    To create a simple file with the name and extension that we want.
  • touch file1.txt file2.txt file3.txt
    This creates all the files that we indicate at once.

8. rm command

If what you need is to delete a file, the rm command you have to use. The delete action with rm is irreversible, so you must be careful with its use. 

Examples:

  • rm file1.txt
    To delete the indicated file completely.
  • rm -r
    This switch removes all files and subdirectories.

9. cp Command

When you want to copy a file into a directory, you can do it with the cp command. You just have to indicate the name of the file, within the directory in which you are, and the full path of the other directory. The file will be copied with the same name.

Examples:

  • cp example.txt / home / directory1
    This will copy the file example.txt to directory1.
  • cp * home / directory1
    Using the wildcard *, we can copy all the files from the current directory to the indicated directory (directory1)

10. sudo command

The sudo command grants SuperUser privileges to the current user to perform specific tasks for which they do not have the right to do so. Be careful when using this command, since irreversible damage can be caused by accessing with SuperUser permissions 

Example:

  • sudo apt-get update
    This updates the system packages. If you don’t have root premises and don’t use the sudo command , you won’t be able to update it.

11. Top command

With the top command we can see a list with all the active processes that the system is executing. It also shows the consumption of RAM and CPU and everything in real time. This information is very useful when we have performance problems in the system. 

Examples:

  • top
    The simple command displays the indicated list.
  • top -d 20 I would
    set a refresh rate of 25 seconds to show the list with the results.

12. man command

If you are starting with Linux, the man command is probably one of the most used. With this command we can see a manual on the functions available for a specific command. 

Example:

  • man top
    This shows all the functions available to the top command.

13. zip / unzip command

Zip files are widely used to compress and decompress files and reduce their size, especially in the Windows environment. On Linux you can use the zip command to compress a file and unzip to unzip it. 

Examples:

  • zip file-name.pdf
    This compresses the file indicated in .zip.
  • zip Example.zip file1.txt file2.pdf
    This would compress the files indicated in a .zip called Example.zip.
  • unzip Example.zip
    To unzip the .zip file in the directory where we are.

14. Tar command

In the Linux environment, the most common command to compress files is tar. It has many functions and possibilities, which makes it one of the preferred options for users. 

Examples:

  • tar cvf
    compressed d.tar Directory1 This would compress Directory1 into tar with the name compressed d.tar.
  • tar xvf dcompressed.tar -C / home / Directory2
    Unzip the file dcompressed.tar into Directory2.

15. The locate command

The locate command comes from location and we can use it to find a certain file. The search is done through the entire file system, so if you put something very generic, the list of results can be very long. 

Examples:

  • locate file1
    Will find all files with the text archive1 on the system.
  • locate -r file1
    Will do the search case insensitive, so you will get results from file1, File1, file2, etc.

16. find command

The find command is also used to find files and folders, but we can narrow the search to a specific directory. With find we can also perform searches by date, size, permissions, etc. 

Examples:

  • find. -name file1.txt
    This way we can look for file1.txt in the current directory.
  • find. -type f -iname “* .txt”
    With this command and parameter we will find all the files with a txt extension in the directory.

17. Command mv

The mv command is what we have to use when we want to move a site file, although you can also use it to rename a file. 

Examples:

  • mv /Directory1/file1.txt / Directory2 /
    With this command we would move file1.txt from Directory1 to Directory2.
  • mv /Directory1/file1.txt /Directory1/file2.txt
    And with this command the file1.txt would be renamed to file2.txt.

18. Command cp

If instead of copying a file we want to copy it, the command we have to use is cp. Its use is similar to the mv command , so we must specify the file followed by the name of the directory. Example: Thus we would copy file1.txt from the current directory to Directory2.

Examples:

  • cp file1.txt / Directory2 /
    Thus we would copy file1.txt from the current directory to Directory2.

19. df command

If you need to know the space of the storage unit you are using, the df command shows you all the information you need about the disk space.

20. Command du

To find out how much space a file or directory is occupying on the system, the du command will tell you. We can also see the size of the files in the directory. 

Examples:

  • du -h / Directory1
    Displays the size of Directory1 in human format (kilobyte, megabyte, etc.)
  • du -a / Directory1
    With the -a switch we can see the size of the files included in Directory1

21. chmod command

chmod is the command we use in Linux to manage file and directory permissions. Changing the permissions of a directory or file in the wrong way can cause problems, so use it with caution. 

Example:

  • chmod 644 file1.txt
    Sets read and execute permissions to file owner. It also establishes read permissions to the rest of the users.

22. Command kill

To close applications in Linux use the kill command . If the program does not respond or does not do it correctly and we have to close it, kill will do it. 

Example:

  • kill -9 52661
    We kill process 52661 with the SIGKILL signal.

23. ping command

The ping command is used to verify that a server or website is connected to the Internet and is responding. You can use the ping command followed by any domain to see if it responds and with what IP address it responds.

24. grep command

The grep command can be used to find a text within one or more files. 

Example:

  • grep -w schedule /home/file1.txt We
    would look for the exact word ‘schedule’ within file1.

25. wget command

With the wget command we can download a file from a URL or FTP. It has different modifiers that make it a very versatile and powerful tool for any Linux user. 

Examples:

  • wget https://url-example.com/file1.txt We
    download file1.txt from the indicated domain.
  • wget https://url-example.com/*.txt We
    download all the .txt files from the indicated URL.

conclusion

Linux has many more commands than those exposed here, but to begin with, knowing these basic commands will be very helpful in your new journey in Linux.

Share this post on social

About us

“As a Linuxguidehq.com website, we are proud to offer expert advice and guidance on all things Linux.

Copyright 2022 Linuxguidehq.com. All rights reserved. No part of this website may be reproduced, distributed, or transmitted in any form or by any means, including photocopying, recording, or other electronic or mechanical methods, without the prior written permission of the copyright owner.