Mastering Linux CLI Commands: Boost Your Productivity and Efficiency!

Table of contents

No heading

No headings in the article.

  1. To print the word, we entered the echo command. This command is usually used for printing environmental variables.

  2. To list all the contents of the directory –

    ls

  3. To change directory –

    cd

  4. To print the directory, you are currently in –

    pwd

  5. To create a new directory –

    mkdir < new-directory>

  6. To use multiple commands together, done by separating each command with a semicolon. For example,

    cd new_dir; mkdir blues; pwd

  7. To make Directory Hierarchy like this /tmp/Asia/India/Bangalore

    Instead of doing this:-

    mkdir /tmp/Asia

    mkdir /tmp/Asia/India

    mkdir /tmp/Asia/India/Bangalore

    We can create it in a single shot by:-

    mkdir -p /tmp/Asia/India/Bangalore

  8. To remove a directory,

    rm -r

  9. To copy a directory from one location to another

    cp -r my_dir1 /path-of/my_dir1

  10. To create a new file with no contents

    touch new_file.txt

  11. Add contents to the file.

    cat > new_file.txt To exit and save the file use CTRL + D

  12. To view the contents of the file

    cat new_file.txt

  13. To copy a file

    cp new_file.txt copy_file.txt

  14. To move or rename the file.

    mv new_file.txt sample_file.txt

  15. To remove or delete a file.

    rm new_file.txt

  16. To check free space in Linux df -h ( For a more human-readable format)

  17. to check the free space for the root file system ("/"), you can run: df /

  18. To know which user, you are – whoami

  19. To know more info about user – id

  20. To search for a specific pattern in files - grep

  21. To switch from one user to another – su

  22. If you are accessing one system from another system using ssh & want to login to another system using a different user than the current user - ssh <username>@<hostname>

  23. Every Linux system has a super user known as the root user. The root user has no restrictions on the system. When we use the command : ls /root, it will show permission denied.

  24. A root user can grant regular users some sudo privileges by making an entry into the sudoers file. When we use sudo ls/root after putting the right password you will see the output i.e., in this case is snap.

  25. Remember to add sudo prefix when writing the command. WHENEVER YOU GET A PERMISSION DENIED ERROR ON LINUX, IT MIGHT BE CAUSED BY NOT USING THE SUDO PREFIX BEFORE THE COMMAND.

  26. To download files from the internet, commands that will be used are:- curl http:// www.some-site.com/some-file.txt -O Here -O is used to save the result to a file.

  27. Another way to download files from the internet

    wget -O some-file.txt Here some-file.txt is used to store files locally.

  28. To check on which O.S. you are working use this

    ls /etc/release

  29. To see more details about the OS

    cat /etc/release