🚀
🖥️ Terminal Basics
DevOps

Linux & Terminal Commands

A shell is a command-line interface which allows to perform certain tasks using command

Mar 202510 min read

Linux & Terminal Commands

A shell is a command-line interface which allows to perform certain tasks using command

Basic Commands

  • cd → change directory 800
    • cd .. → goes back a single directory 800
  • mkdir → make new folder 800
    • mkdir -p → makes directories and sub-directories too. 800
  • touch → creates a new file 800
  • ls/dir → lists all the files in the current directory 800 800
    • ls -a → displays all the hidden files 800
    • ls -l → shows more information like size, date about the files in working directory. 800
    • ls -R → show files, directories and sub-directories as well. 800
  • xdg-open / open → opens the graphical interface of the present working directory.
  • pwd → Print Working Directory 800
  • cp → creates a copy of a file or a folder 800
    • cp -R → copies directories and also the sub-directories 800
  • mv → moves files 800 If names of two files are given, then the file gets renamed.
  • rm → removes only files permanently. 800
    • rm -R → removes directories permanently. 800
    • rm -rf → force remove of files or directories. 800
  • sudo → Super User Do gives system administrator privileges. 800 sudo apt update && sudo apt upgrade is used to download and install updates.

File Commands

  • echo → displays

  • cat stands for concatenate, it is used to display the contents of a file 800

    • cat > creates a file.
  • vi <file_name> allows editing the file in the console.

    800 800

    • press i to enter insert mode and Esc to enter command mode.
      • I - Insert text at the beginning of the current line
      • A – Write at the end of the line (goes into insert mode)
      • b → Go to the beginning of the word
      • e → Go to the ending of the word
      • u – Undo last change
      • U – Undo all changes to the entire line
      • o – Open a new line (goes into insert mode)
      • dd – Delete line
      • 3dd – Delete 3 lines.
      • D – Delete contents of the line after the cursor
      • C – Delete the contents of a line after the cursor and insert new text.
      • dw – Delete word
      • 4dw – Delete 4 words
      • cw – Change word
      • x – Delete the character at the cursor
      • ~ – Change case of individual character
    • :wq → writes and quit the file in command mode
    • :q! → quit without saving the changes in command mode
    • :w → save and continue editing
    • yy → Yank (copy a line of text)

    An introduction to the vi editor (opens in a new tab)

  • head → displays the first 10 lines of a file

    • head -n 1 → displays the first line of a file
  • tail → displays the lasts 10 lines of a file

    • tail -n 1 → displays the last line of a file
  • diff → compares files and displays lines which does not match

  • tr → translate

  • grep → searches Strings in files.

    • grep -w → searches Strings of a complete word in files.
    • grep -i → [ignore cases] searches non-case sensitive Strings in files.
    • grep -n → searches Strings in files and also displays the line no.
    • grep -win → search non-case sensitive Strings in words in files and also displays the line no.
    • grep -B 3 → also displays 3 lines before the searched Strings.
    • grep -r → searches Strings in files recursively.
    • grep -l → displays list of filenames only.
    • grep -c → display the no of times the search string is present in a file
    • grep -p → is used to search regular expressions
  • sort → displays lines of file sorted alphabetically.

    • sort -r → displays lines of files sorted in reverse
    • sort -b → ignores blacks while sorting
    • sort -f → ignores cases while sorting
    • sort -n → sorts numerical value
  • lsof → lists all the opened files

    • lsof -u driptanil → displays all the opened files by ‘driptanil’ user
  • cut → remove sections from each line of files

    • cut -b → removes only bytes
    • cut -c → removes only characters
  • locate "*.txt" → will display location of all the .txt files.

  • find . → displays all the files and folder in the working directory.

    • find . -type d → displays all the folders in the working directory.
    • find . -type f → displays all the files in the working directory.
    • find -name → displays all files and folders with the name in working directory.
    • find -iname → displays all files and folders with the name [not case sensitive] in the working directory.
    • find -mmin -15 → displays all the files and folders modified less than 15 mins ago.
    • find -mmin +30 → displays all the files and folders modified more than 30 mins ago.
    • find -mtime -10 → displays all the files and folders modified less than 10 days ago.
    • find -maxdepth 1 → displays files and folders in working directory.
    • find -mindepth 2 → displays files and folders in the folders in working directory.
    • find -size +1k → displays files and folders more than 1 Kb size.
    • find -empty → displays files and folders which are empty.
    • find -perm 777 → displays files and folders with -rwxrwxrwx permissions.
    • find . -type f -name "name*" -exec rm -rf {'{}'} +exec : execute the files and folder found by find command with another command, {} : place holder, + : add all the files.

Other Commands

  • where/whereis → displays the location of the environment variables.
  • .bashrc file consists of the commands which are automatically executed when bash terminal is opened.
    • It also has alias, which is a short user-defined command that the shell translates to another command. The variables in capitals are environmental variables.
    • temporary alias
    • permanent alias [adding it in ~/.bashrc file
  • .profile file consist of all the environmental variable paths.
  • $PATH → consists all directories of the environmental variables
  • export is used to set temporary environmental variable
  • chmod → used to change the access permissions of file.
    • Types of file permissions:
      1. Read(r) [value = 4]
      2. Write(w) [value = 2]
      3. Execute(x) [value = 1]
    • Types of users:
      1. User[u]
      2. Guest[g]
      3. Other[o]
    • chmod 777 → -rwxrwxrwx
    • chmod 124 → --x-w-r--
    • chmod 000 → ---------
  • chown → change owner

Terminal Shortcuts:

  • Ctrl + A → move to the beginning of the line
  • Ctrl + E → move to the end of the line
  • Ctrl + U → remove the whole command
  • Ctrl + K → removes everything to right of the cursor.
  • Ctrl + L → clears the terminal like clear command
  • Tab → used to auto-complete
  • ; → many commands together

Network Commands

  • ping → allows to request website server and displays all the statistics
  • wget → download files from the internet.
  • nslookup → displays the IP address of a particular domain
  • netstat → displays the ports that are listening
  • curl ifconfig.me -s → displays the IP address of the user

User Commands

  • whoami → displays the username
  • hostname → displays the name of the Hostname
    • hostname -i → displays the IP Address
  • useradd → adds new user
    • passwd → adds new password
    • userdel → deletes existing users
  • uname → displays the kernel name
    • uname -o → displays the type
    • uname -m → displays the architecture
    • uname -r → displays the kernel version
  • id → displays the group IDs
  • getent group driptanil → checks if ‘driptanil’ group exists

System Information Commands

  • df → shows the disk size and usage details
    • df -h → displays the size and usage details in human readable format.
  • du → shows the disk usage statistics in working directory
    • du -h → shows the disk usage statistics in working directory in human readable format.
  • cat /etc/os-release → displays the operation system information
  • lscpu → displays the CPU details
  • free → displays the memory statistics
  • vmstat → displays the virtual memory statistics

Managing Tasks Commands

  • top → shows all the processes running
  • kill → kills the process with the specified process ID.
  • jobs → displays the running commands
  • ps aux → the processes and the process ID
  • htop → shows the processes which are using the resources

Operators

  • Ampersand & → This command sends a process/script/command to the background.

    • to kill this background process use ps and kill command.
  • Pipe | → The output of the first command acts as input to the second command

  • && → executes the second command if and only if the first command is executed successfully.

  • || → executes the second command if and only if the first command fails.

  • ! → not operator

  • >> → append

  • > → over-write

  • Combination (...) → group commands using ;

© 2026 Driptanil Datta. All rights reserved.

Software Developer & Engineer

Disclaimer:The content provided on this blog is for educational and informational purposes only. While I strive for accuracy, all information is provided "as is" without any warranties of completeness, reliability, or accuracy. Any action you take upon the information found on this website is strictly at your own risk.

Copyright & IP:Certain technical content, interview questions, and datasets are curated from external educational sources to provide a centralized learning resource. Respect for original authorship is maintained; no copyright infringement is intended. All trademarks, logos, and brand names are the property of their respective owners.

System Operational

Built with Love ❤️ | Last updated: Mar 16 2026