Basic Linux Commands: A Beginner-Friendly Guide with Examples

Linux is one of the most widely used operating systems in software development, cloud computing, DevOps, cybersecurity, networking, and server administration.

Unlike graphical operating systems where most tasks can be performed by clicking menus, Linux provides a powerful command-line interface (CLI) that allows users to interact with the operating system by typing commands.

Learning a few basic Linux commands can make everyday tasks such as navigating directories, creating files, managing processes, checking system information, and working with permissions much easier.

This beginner-friendly guide explains the most useful Linux commands with practical examples.


What is Linux?

Linux is an open-source operating system kernel that forms the foundation of many Linux distributions.

Popular Linux distributions include:

  • Ubuntu
  • Debian
  • Fedora
  • Arch Linux
  • Linux Mint
  • Rocky Linux
  • AlmaLinux

    Linux is widely used for servers, cloud infrastructure, development environments, containers, embedded systems, and many other computing applications.

    One of its most important features is the command line.


    What is the Linux Command Line?

    The Linux command line is a text-based interface through which users can communicate with the operating system.

    Instead of opening a file manager and clicking through folders, you can type:

    cd Documents

    Instead of manually checking the contents of a directory, you can use:

    ls

    Commands can also be combined to perform more advanced tasks.

    For developers, learning the command line is particularly useful when working with:

    • Git
    • Docker
    • Kubernetes
    • SSH
    • Web servers
    • Cloud platforms
    • CI/CD pipelines
    • Backend applications


      Basic Linux Command Syntax

      A typical Linux command follows this structure:

      command [options] [arguments]

      For example:

      ls -l /home

      Here:

      • ls is the command.
      • -l is an option.
      • /home is an argument.

        Many Linux commands support multiple options.

        For example:

        ls -la

        lists files, including hidden files, in a detailed format.


        1. pwd – Print Working Directory

        The pwd command displays the directory you are currently working in.

        Syntax

        pwd

        Example

        $ pwd
        /home/user/Documents

        This is useful when you are navigating through multiple directories and want to confirm your current location.


        2. ls – List Files and Directories

        The ls command displays the contents of the current directory.

        Basic usage

        ls

        Example:

        Documents
        Downloads
        Pictures
        projects
        notes.txt

        Detailed listing

        ls -l

        The -l option provides additional information such as:

        • File permissions
        • Owner
        • Group
        • File size
        • Modification time
        • File name

          Show hidden files

          ls -a

          Linux hidden files normally begin with a ..

          For example:

          .bashrc
          .config
          .profile

          Detailed listing including hidden files

          ls -la

          3. cd – Change Directory

          The cd command is used to move from one directory to another.

          Example

          cd Documents

          Move to the parent directory:

          cd ..

          Return to your home directory:

          cd ~

          Go directly to the root directory:

          cd /

          You can also use an absolute path:

          cd /home/user/projects

          4. mkdir – Create a Directory

          mkdir stands for make directory.

          It creates a new directory.

          Example

          mkdir projects

          You can create multiple directories:

          mkdir frontend backend database

          To create nested directories that do not yet exist:

          mkdir -p project/src/components

          The -p option creates the required parent directories.


          5. touch – Create a File

          The touch command can be used to create an empty file.

          touch notes.txt

          You can create several files at once:

          touch index.html style.css script.js

          touch can also update a file's timestamp if the file already exists.


          6. cat – Display File Contents

          The cat command is commonly used to display the contents of a text file.

          cat notes.txt

          If the file contains:

          Learning Linux commands

          the command displays:

          Learning Linux commands

          You can also combine multiple files:

          cat file1.txt file2.txt

          7. cp – Copy Files and Directories

          The cp command copies files or directories.

          Copy a file

          cp notes.txt backup.txt

          This creates backup.txt containing the same content.

          Copy a file to another directory

          cp notes.txt Documents/

          Copy a directory

          Use the recursive option:

          cp -r project project_backup

          8. mv – Move or Rename Files

          The mv command can be used to move files and directories.

          mv notes.txt Documents/

          It can also rename files.

          mv oldname.txt newname.txt

          This makes mv useful for both moving and renaming files.


          9. rm – Remove Files

          The rm command removes files.

          rm notes.txt

          To remove a directory and its contents:

          rm -r project

          Be careful when using rm, particularly with administrative privileges. Files removed using rm generally do not go to a graphical recycle bin.


          10. rmdir – Remove Empty Directories

          The rmdir command removes an empty directory.

          rmdir old_project

          If the directory contains files, rmdir will not remove it.

          For directories containing files, rm -r is commonly used, but it should be used carefully.


          11. echo – Display Text

          The echo command prints text to the terminal.

          echo "Hello Linux"

          Output:

          Hello Linux

          It can also be used with shell variables:

          echo $HOME

          You can redirect output to a file:

          echo "Linux is powerful" > message.txt

          The > operator creates or replaces the file contents.

          To append instead:

          echo "Another line" >> message.txt

          12. clear – Clear the Terminal

          When the terminal becomes crowded, use:

          clear

          This clears the visible terminal screen.

          A common keyboard shortcut is:

          Ctrl + L

          13. man – Linux Manual Pages

          Linux provides built-in documentation for many commands through man.

          For example:

          man ls

          This opens the manual page for ls.

          You can use:

          man cp

          to learn about the cp command.

          To leave a manual page, press:

          q

          14. whoami – Find the Current User

          The whoami command displays the username of the currently logged-in user.

          whoami

          Example output:

          user

          This is particularly useful when working on remote servers.


          15. date – Display Date and Time

          Use:

          date

          to display the current system date and time.

          Example:

          Thu Sep 24 14:30:00 IST 2026

          The exact output depends on the system's configured date, time, and timezone.


          16. cal – Display a Calendar

          On systems where the cal utility is installed, you can use:

          cal

          to display a calendar.

          You can also request a specific month and year:

          cal 9 2026

          17. history – View Previous Commands

          The history command displays commands previously entered in the shell.

          history

          You might see:

          101  pwd
          102  ls
          103  cd projects
          104  git status

          This can be useful when you want to reuse a command you executed earlier.


          18. head – Display the Beginning of a File

          The head command displays the first part of a file.

          head file.txt

          By default, it commonly displays the first 10 lines.

          To display the first 5 lines:

          head -n 5 file.txt

          This is useful when inspecting large log or data files.


          19. tail – Display the End of a File

          The tail command displays the last part of a file.

          tail file.txt

          To continuously monitor a file as new lines are added:

          tail -f application.log

          This is particularly useful for monitoring application and server logs.


          20. grep – Search for Text

          grep searches text for a specified pattern.

          Suppose users.txt contains:

          Ravi
          Rahul
          Rupesh
          Anil

          You can search for Rupesh using:

          grep "Rupesh" users.txt

          To ignore case:

          grep -i "rupesh" users.txt

          You can also search recursively through files:

          grep -r "TODO" project/

          This is extremely useful for developers working with large codebases.


          21. find – Search for Files

          The find command searches for files and directories.

          For example:

          find . -name "notes.txt"

          The . means to start searching from the current directory.

          Find all JavaScript files:

          find . -name "*.js"

          Find files by type:

          find . -type f

          Find directories:

          find . -type d

          22. wc – Count Lines, Words and Characters

          The wc command provides counts for text files.

          wc file.txt

          To count lines:

          wc -l file.txt

          To count words:

          wc -w file.txt

          To count characters:

          wc -m file.txt

          23. sort – Sort Text

          The sort command sorts lines of text.

          For example:

          sort names.txt

          If the file contains:

          Zebra
          Apple
          Mango
          Banana

          the output will be sorted alphabetically.

          Apple
          Banana
          Mango
          Zebra


          24. chmod – Change File Permissions

          Linux uses file permissions to control access.

          The three basic permission categories are:

          • User/owner
          • Group
          • Others

          Common permission symbols are:

          r = read
          w = write
          x = execute

          For example:

          chmod +x script.sh

          adds execute permission to the script.

          Numeric permissions are also common:

          chmod 755 script.sh

          The exact permission you should use depends on what the file needs to do.


          25. ps – View Running Processes

          The ps command displays information about running processes.

          ps

          A commonly used form is:

          ps aux

          This displays processes belonging to users and provides additional information such as:

          • Process ID
          • CPU usage
          • Memory usage
          • Process owner
          • Command


          26. top – Monitor Processes

          The top command provides a continuously updating view of system processes.

          top

          It can help you inspect:

          • CPU usage
          • Memory usage
          • Running processes
          • Process IDs
          • System load

          Press:

          q

          to exit.

          Some Linux systems also provide tools such as htop, which offer a more interactive interface when installed.


          27. df – Check Disk Space

          The df command displays available disk space on mounted filesystems.

          df

          For human-readable values:

          df -h

          Example:

          Filesystem      Size  Used Avail Use%
          /dev/sda1        50G   30G   18G  63%

          The -h option makes sizes easier to read.


          28. du – Check Directory Size

          The du command shows how much disk space files and directories consume.

          du -h

          For a summary of the current directory:

          du -sh .

          This is useful when trying to identify which directories are consuming significant disk space.


          29. free – Check Memory Usage

          The free command displays information about system memory.

          free

          For easier-to-read units:

          free -h

          It can show information about:

          • Total memory
          • Used memory
          • Available memory
          • Swap memory


          30. uname – Display System Information

          The uname command provides information about the operating system environment.

          uname

          For more detailed information:

          uname -a

          Depending on the system, this can show details such as the kernel name, hostname, kernel release, and architecture information.


          31. ping – Test Network Connectivity

          The ping command can be used to test network connectivity to a host.

          For example:

          ping example.com

          On many Linux systems, you can stop the command using:

          Ctrl + C

          The results can provide information about whether responses are being received and the round-trip time.

          Note that firewalls or server configurations can block ICMP traffic, so failure to receive a ping response does not by itself prove that a host or service is unavailable.


          32. curl – Transfer Data from a URL

          curl is a versatile command-line tool for transferring data over network protocols.

          For example:

          curl https://example.com

          This retrieves the response from the specified URL.

          Developers frequently use curl to test APIs.

          For example:

          curl https://api.example.com/users

          A POST request can be made with appropriate options:

          curl -X POST https://api.example.com/users

          When working with real APIs, additional headers or request data may be required.


          33. sudo – Execute Commands with Elevated Privileges

          sudo allows an authorized user to execute a command with elevated privileges.

          For example:

          sudo apt update

          On Ubuntu and Debian-based systems, this can be used when updating package information.

          Because commands executed through sudo can make system-wide changes, you should understand the command before running it.


          Linux Absolute Paths vs Relative Paths

          Understanding paths is essential when working with Linux commands.

          Absolute path

          An absolute path starts from the root directory:

          /home/user/Documents/file.txt

          Relative path

          A relative path starts from your current directory:

          Documents/file.txt

          Two particularly useful path shortcuts are:

          .   Current directory
          ..  Parent directory
          ~   Home directory
          /   Root directory

          For example:

          cd ..

          moves to the parent directory.


          Linux Command Chaining

          Linux commands can be combined to create powerful workflows.

          For example:

          mkdir project && cd project

          The second command executes if the first command succeeds.

          Another example:

          cat users.txt | grep "Rupesh"

          The pipe | sends the output of the first command to the second command.

          This allows small commands to be combined into more useful operations.


          Redirection in Linux

          Linux provides operators for redirecting command output.

          > – Overwrite a file

          echo "Hello" > output.txt

          >> – Append to a file

          echo "Welcome" >> output.txt

          < – Use a file as input

          command < input.txt

          Redirection is particularly useful when working with logs, scripts, and automation.


          Useful Linux Commands Cheat Sheet

          Command Purpose Example
          pwd Show current directory pwd
          ls List files ls -la
          cd Change directory cd Documents
          mkdir Create directory mkdir project
          touch Create file touch app.js
          cat Display file cat app.js
          cp Copy cp a.txt b.txt
          mv Move/rename mv old.txt new.txt
          rm Remove rm file.txt
          rmdir Remove empty directory rmdir test
          echo Print text echo "Hello"
          clear Clear terminal clear
          man Read documentation man ls
          whoami Show current user whoami
          date Show date/time date
          history Show command history history
          head Show beginning of file head file.txt
          tail Show end of file tail file.txt
          grep Search text grep "error" log.txt
          find Find files find . -name "*.js"
          wc Count text wc -l file.txt
          sort Sort text sort names.txt
          chmod Change permissions chmod +x app.sh
          ps Show processes ps aux
          top Monitor processes top
          df Check disk space df -h
          du Check directory size du -sh .
          free Check memory free -h
          uname System information uname -a
          ping Test connectivity ping example.com
          curl Transfer data curl https://example.com
          sudo Run with elevated privileges sudo command

          10 Linux Commands Beginners Should Practice First

          If you are completely new to Linux, don't try to memorize every command at once.

          Start with these:

          1. pwd
          2. ls
          3. cd
          4. mkdir
          5. touch
          6. cat
          7. cp
          8. mv
          9. rm
          10. grep

          Once these become comfortable, move on to:

          find
          chmod
          ps
          top
          df
          du
          curl
          sudo

          Then start learning shell scripting and command pipelines.


          A Simple Linux Practice Exercise

          You can practice the commands above by creating a small project directory.

          Step 1: Create a project

          mkdir linux-practice

          Step 2: Enter the directory

          cd linux-practice

          Step 3: Create files

          touch index.html app.js README.md

          Step 4: Check the files

          ls -l

          Step 5: Add text

          echo "Linux Practice Project" > README.md

          Step 6: Read the file

          cat README.md

          Step 7: Create a backup

          cp README.md README-backup.md

          Step 8: Rename the backup

          mv README-backup.md backup.md

          Step 9: Search for JavaScript files

          find . -name "*.js"

          Step 10: Return to the parent directory

          cd ..

          This small exercise lets you practice several fundamental Linux commands in a realistic workflow.


          Common Linux Command Mistakes Beginners Make

          1. Forgetting spaces

          Incorrect:

          cdDocuments

          Correct:

          cd Documents

          2. Using the wrong path

          Always check your current location with:

          pwd

          3. Accidentally deleting files

          Be especially careful with:

          rm

          and particularly commands that recursively remove directories.

          4. Running everything with sudo

          sudo should be used when elevated privileges are actually required, not automatically for every command.

          5. Ignoring command documentation

          When unsure, check:

          man command

          or:

          command --help

          For example:

          ls --help

          Why Learn Linux Commands?

          Linux commands are useful far beyond basic operating-system administration.

          Developers regularly encounter Linux while working with:

          • Backend servers
          • Cloud platforms
          • Docker containers
          • Git repositories
          • CI/CD systems
          • Web hosting
          • Databases
          • SSH
          • DevOps tools
          • Kubernetes
          • Automation scripts

            For example, a developer may connect to a remote server using SSH and then use commands such as:

            pwd
            ls
            cd
            cat
            grep
            ps
            df

            to inspect an application and troubleshoot problems.

            Therefore, learning Linux commands is a practical skill for anyone entering software development or IT.


            Frequently Asked Questions

            What are basic Linux commands?

            Basic Linux commands are command-line utilities used for common tasks such as navigating directories, creating and managing files, searching data, checking system information, and managing processes.

            Examples include pwd, ls, cd, mkdir, cp, mv, rm, cat, and grep.

            Which Linux command lists files?

            The ls command lists files and directories.

            ls

            For detailed information:

            ls -l

            To include hidden files:

            ls -la

            Which command is used to change directories?

            The cd command changes the current working directory.

            cd Documents

            How do I create a directory in Linux?

            Use mkdir:

            mkdir myfolder

            How do I create a file in Linux?

            One simple method is:

            touch filename.txt

            How do I delete a file in Linux?

            Use:

            rm filename.txt

            Use this command carefully because the file may not be recoverable through a normal recycle-bin workflow.

            How do I search for text in Linux?

            The grep command can search for text:

            grep "keyword" file.txt

            How do I find a file in Linux?

            Use the find command:

            find . -name "filename.txt"

            How can I learn Linux commands quickly?

            The most effective approach is to practice commands directly in a Linux environment rather than memorizing them. Start with file navigation and management, then learn searching, permissions, processes, networking, and shell scripting.


            Final Thoughts

            Linux commands provide a fast and flexible way to interact with an operating system. You don't need to memorize hundreds of commands to get started.

            Begin with the fundamentals:

            pwd
            ls
            cd
            mkdir
            touch
            cat
            cp
            mv
            rm
            grep

            After becoming comfortable with these commands, gradually learn permissions, process management, disk usage, networking, shell scripting, and automation.

            The important thing is consistent practice. Even 15–20 minutes of command-line practice each day can make Linux much more comfortable over time.