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โ Copyoldfiletonewfile. ๐
๐๏ธ 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โ Renameoldfilenametonewname. โ๏ธ
๐ต๏ธ 24. comp: Compare Files
-
comp file1 file2โ Show differences betweenfile1andfile2. ๐
๐ 25. conm: Show Common Data
-
conm file1 file2โ Show common data betweenfile1andfile2. ๐
๐ 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.