๐Ÿง Some Linux Commands You May Need to Know: Part 1

dibyataruchakraborty

Dibyataru Chakraborty

Posted on July 28, 2024

๐Ÿง Some Linux Commands You May Need to Know: Part 1

๐ŸŒ Introduction to Linux

Linux is an extremely common operating system. An astounding 90% of all cloud computing systems run on Linux. Most servers and technology-embedded devices rely on Linux. Itโ€™s Linux that manages and orchestrates the computing power in most of the cloud.

๐Ÿ› ๏ธ What is Linux?

Linux is an operating system kernel created by Linus Torvalds from scratch. As a free and open-source platform, you can modify anything in Linux and redistribute it under your own name! There are several popular Linux distributions, commonly called "distros":

  • Ubuntu Linux
  • Red Hat Enterprise Linux
  • Linux Mint
  • Debian
  • Fedora

๐Ÿ–ฅ๏ธ Understanding the Linux Shell
A Linux Shell is a program that receives commands from the user, passes them to the OS for processing, and displays the output. The Shell is the interface that allows you to interact with the Linux operating system efficiently.


Exploring Linux commands can be both fun and educational! Hereโ€™s a collection of handy commands to boost your terminal skills. ๐Ÿš€

๐Ÿ” 1. grep: Search Text in Files

  • grep "search-name" filename โ€“ Find lines with "search-name" in a file. ๐Ÿ•ต๏ธโ€โ™‚๏ธ
  • grep -v search-name filename โ€“ Show all lines except those with "search-name". ๐Ÿšซ
  • grep -n -v search-name filename โ€“ Show all lines except those with "search-name", including line numbers. ๐Ÿ”ข
  • grep -c search-name filename โ€“ Count occurrences of "search-name". ๐Ÿ“Š
  • grep -l search-name filenames โ€“ List files containing "search-name". ๐Ÿ“‚
  • grep -e 'search-name' -e 'search-name' filename โ€“ Show lines with either "search-name". ๐Ÿ”„
  • grep "^startwith" filename โ€“ Show lines starting with "startwith". ๐ŸŒŸ
  • grep "endstart-withโ€ฆ$" filename โ€“ Show lines ending with "endstart-with". ๐Ÿ“Œ
  • grep -E "searchname1|searchname2" filename โ€“ Show lines with either "searchname1" or "searchname2". ๐Ÿ”„
  • grep -l "search-name" * โ€“ List all files containing "search-name". ๐Ÿ—‚๏ธ

๐Ÿ“„ 2. cat: Concatenate and Display Files

  • cat > filename โ€“ Create or overwrite a file. โœ๏ธ
  • cat >> filename โ€“ Append content to a file. ๐Ÿ“
  • cat -n filename โ€“ Show line numbers in a file. ๐Ÿ”ข
  • cat previous-filename > new-filename โ€“ Copy contents from one file to another. ๐Ÿ“‹

๐Ÿ“‚ 3. ls: List Directory Contents

  • ls *.search-extension-name โ€“ List all files with a specific extension. ๐Ÿ”
  • ls -l โ€“ Detailed listing of files. ๐Ÿ“œ
  • ls -l | grep "^d" โ€“ Show directories. ๐Ÿ“
  • ls -l | grep "^- " โ€“ Show regular files. ๐Ÿ“„
  • ls -l | grep "^-" | wc -l โ€“ Count regular files. ๐Ÿ“ˆ
  • ls -l | grep "^d" | wc -l โ€“ Count directories. ๐Ÿ“

๐Ÿ“‘ 4. File Names & Permissions

  • Max Length: 256 characters. ๐Ÿ“
  • File Types:
    • -: Regular file
    • d: Directory
  • Permissions:
    • r w x โ€“ User
    • r - - โ€“ Group
    • r - - โ€“ Other

๐Ÿ“… 5. cal: Display Calendar

  • cal โ€“ Show the current month. ๐Ÿ“…
  • cal month-name/month-number year โ€“ Show a specific month. ๐Ÿ“†

โฐ 6. date: Show Date and Time

  • date โ€“ Current date. ๐Ÿ“…
  • date +%m โ€“ Month ID. ๐Ÿ—“๏ธ
  • date +%M โ€“ Minute. โฒ๏ธ
  • date +%h โ€“ Month name. ๐Ÿ—“๏ธ
  • date +%H โ€“ Hour. ๐Ÿ•’
  • date +%d โ€“ Date. ๐Ÿ“†
  • date +%D โ€“ Full date. ๐Ÿ“…
  • date +%y โ€“ Year (e.g., 23). ๐Ÿ—“๏ธ
  • date +%Y โ€“ Full year (e.g., 2023). ๐Ÿ—“๏ธ
  • date +%T โ€“ Full time. โฑ๏ธ
  • date +%S โ€“ Seconds. โฑ๏ธ
  • date +%s โ€“ Nanoseconds. โฑ๏ธ

๐Ÿ–ฅ๏ธ 7. uname: System Information

  • uname โ€“ Display OS name. ๐Ÿ–ฅ๏ธ
  • uname -s โ€“ Kernel name. ๐Ÿ› ๏ธ
  • uname -r โ€“ Kernel release. ๐Ÿ› ๏ธ
  • uname -n โ€“ Network node hostname. ๐ŸŒ
  • uname -v โ€“ Kernel version. ๐Ÿ› ๏ธ
  • uname -m โ€“ Machine hardware name. ๐Ÿ–ฅ๏ธ
  • uname -p โ€“ Processor type. ๐Ÿ–ฅ๏ธ
  • uname -i โ€“ Hardware platform. ๐Ÿ–ฅ๏ธ
  • uname -o โ€“ Operating system. ๐Ÿ–ฅ๏ธ
  • uname -a โ€“ Show all info. ๐ŸŒ

๐Ÿง‘โ€๐Ÿ’ป 8. whoami: Display Current User

  • whoami โ€“ Show your username. ๐Ÿง‘โ€๐Ÿ’ป

๐Ÿ“Ÿ 9. tty: Terminal Identifier

  • tty โ€“ Display terminal number. ๐Ÿ–ฅ๏ธ

๐Ÿ“‚ 10. pwd: Present Working Directory

  • pwd โ€“ Show current directory. ๐Ÿ“‚

๐Ÿ“š 11. whatis 'command': Command Details

  • whatis 'command' โ€“ Show details about a command. ๐Ÿ“–

๐Ÿ”„ 12. cd..: Navigate to Previous Directory

  • cd.. โ€“ Move up one directory level. โฌ†๏ธ

โœ‚๏ธ 13. head: Show Beginning of File

  • head filename โ€“ Show the first 10 lines. ๐Ÿ“œ
  • head -n number filename โ€“ Show the first specified number of lines. ๐Ÿ“œ
  • head -n number1 filename | tail -n number2 โ€“ Show the last number2 lines of the first number1 lines. ๐Ÿ“œ

๐Ÿ“œ 14. tail: Show End of File

  • tail filename โ€“ Show the last 10 lines. ๐Ÿ“„
  • tail -n number filename โ€“ Show the last specified number of lines. ๐Ÿ“„

๐ŸŽฅ 15. script: Record Terminal Session

  • script โ€“ Start recording your terminal session. ๐ŸŽฅ

๐Ÿšช 16. exit: Exit Terminal

  • exit โ€“ Exit the terminal session. ๐Ÿšช

๐Ÿงน 17. clear: Clear Terminal Screen

  • clear โ€“ Clear the terminal screen. ๐Ÿงน

๐Ÿงฎ 18. bc: Calculator Environment

  • bc โ€“ Start the calculator environment. ๐Ÿงฎ

๐Ÿ“‚ 19. cp: Copy Files

  • cp oldfile newfile โ€“ Copy oldfile to newfile. ๐Ÿ“‚

๐Ÿ—‘๏ธ 20. rm: Remove Files

  • rm filename โ€“ Remove a file. ๐Ÿ—‘๏ธ

๐Ÿ“ 21. rmdir: Remove Directory

  • rmdir directory-name โ€“ Remove a directory. ๐Ÿ“

๐Ÿ”„ 22. rm -d: Remove Directory

  • rm -d directory-name โ€“ Remove a directory. ๐Ÿ“

โœ๏ธ 23. mv: Move or Rename Files

  • mv oldfilename newname โ€“ Rename oldfilename to newname. โœ๏ธ

๐Ÿ•ต๏ธ 24. comp: Compare Files

  • comp file1 file2 โ€“ Show differences between file1 and file2. ๐Ÿ”

๐Ÿ” 25. conm: Show Common Data

  • conm file1 file2 โ€“ Show common data between file1 and file2. ๐Ÿ”

๐Ÿ” 26. chmod: Change File Permissions

  • chmod a+x filename โ€“ Add execute permission for all. ๐Ÿ”‘
  • chmod a-x filename โ€“ Remove execute permission for all. ๐Ÿšซ
  • chmod =r filename โ€“ Give read permission to all. ๐Ÿ“œ
  • chmod =rw filename โ€“ Give read/write permission to user. ๐Ÿ“
  • chmod =x filename โ€“ Give execute permission to all. ๐Ÿ”‘
  • chmod go+w filename โ€“ Give write permission to group and others. ๐Ÿ“
  • chmod -R a+x directory-name โ€“ Add execute permission recursively. ๐Ÿ”‘
  • chmod a-rwx filename โ€“ Remove all permissions. ๐Ÿšซ
  • chmod 421 filename โ€“ Set specific permissions. ๐Ÿ”’

๐Ÿ“œ 27. Octal Permissions

  • Binary โ†’ Octal โ†’ Permissions
    • 000 โ†’ 0 โ†’ --- โ€“ No permission. ๐Ÿšซ
    • 001 โ†’ 1 โ†’ --x โ€“ Executable only. ๐ŸŽฏ
    • 010 โ†’ 2 โ†’ -w- โ€“ Writable only. โœ๏ธ
    • 011 โ†’ 3 โ†’ -wx โ€“ Writable and executable. ๐Ÿ”„
    • 100 โ†’ 4 โ†’ r-- โ€“ Readable only. ๐Ÿ“–
    • 101 โ†’ 5 โ†’ r-x โ€“ Readable and executable. ๐Ÿ“–๐ŸŽฏ
    • 110 โ†’ 6 โ†’ rw- โ€“ Readable and writable. ๐Ÿ“–โœ๏ธ
๐Ÿ’– ๐Ÿ’ช ๐Ÿ™… ๐Ÿšฉ
dibyataruchakraborty
Dibyataru Chakraborty

Posted on July 28, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

ยฉ TheLazy.dev

About