This content originally appeared on DEV Community and was authored by Dibyataru Chakraborty
๐ 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
โ Copyoldfile
tonewfile
. ๐
๐๏ธ 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
โ Renameoldfilename
tonewname
. โ๏ธ
๐ต๏ธ 24. comp
: Compare Files
-
comp file1 file2
โ Show differences betweenfile1
andfile2
. ๐
๐ 25. conm
: Show Common Data
-
conm file1 file2
โ Show common data betweenfile1
andfile2
. ๐
๐ 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. ๐โ๏ธ
-
This content originally appeared on DEV Community and was authored by Dibyataru Chakraborty
Dibyataru Chakraborty | Sciencx (2024-07-28T18:13:29+00:00) ๐ง Some Linux Commands You May Need to Know: Part 1. Retrieved from https://www.scien.cx/2024/07/28/%f0%9f%90%a7-some-linux-commands-you-may-need-to-know-part-1/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.