Mastering Linux Commands: A Beginner-to-Advanced Guide
Linux is an immensely powerful operating system famous for flexibility and tuns of control through its command-line interface or CLI. This article will group essential Linux commands and provide some examples to help you better understand and use Linux commands.
1. File and Directory Management
Command | Description | Example |
| Prints the current working directory. |
|
| Lists files and directories. |
|
| Changes the current directory. |
|
| Creates a new directory. |
|
| Creates an empty file. |
|
| Copies files or directories. |
|
| Moves or renames files. |
|
| Deletes files or directories. |
|
| Searches for files/directories. |
|
| Displays directories in tree form. |
|
2. File Viewing and Editing
Command | Description | Example |
cat | Displays file content. | $ cat file1.txt → Outputs the content of file1.txt . |
more | Views file content one screen at a time. | $ more largefile.txt → Displays largefile.txt page by page. |
less | Similar to more but allows backward scrolling. | $ less largefile.txt → Lets you scroll back and forth. |
nano | Edits files with a simple text editor. | $ nano notes.txt → Opens notes.txt in the Nano editor. |
vim | Advanced text editor. | $ vim script.sh → Opens script.sh for editing in Vim. |
head | Displays the first lines of a file. | $ head -n 5 file1.txt → Shows the first 5 lines. |
tail | Displays the last lines of a file. | $ tail -n 10 file1.txt → Shows the last 10 lines. |
3. User Management
Command | Description | Example |
whoami | Displays the current user. | $ whoami → john_doe |
id | Shows user ID and group ID. | $ id → uid=1000(john_doe) gid=1000(john_doe) |
adduser | Adds a new user. | $ sudo adduser alice → Creates a new user named alice . |
passwd | Changes a user's password. | $ passwd → Prompts to change the password. |
chmod | Changes file permissions. | $ chmod 755 script.sh → Grants execute permissions. |
chown | Changes file ownership. | $ sudo chown alice:alice file1.txt → Changes ownership to user alice . |
4. Process Management
Command | Description | Example |
ps | Displays running processes. | $ ps → Lists active processes for the current user. |
top | Shows real-time system usage. | $ top → Displays running processes, CPU, and memory usage. |
kill | Terminates a process by PID. | $ kill 1234 → Stops the process with PID 1234 . |
jobs | Lists active jobs. | $ jobs → [1]+ Running sleep 100 & |
bg | Resumes a job in the background. | $ bg %1 → Resumes job 1 in the background. |
fg | Resumes a job in the foreground. | $ fg %1 → Brings job 1 to the foreground. |
5. Networking Commands
Command | Description | Example |
ping | Tests connectivity to a host. | $ ping google.com → Sends ICMP packets to google.com . |
curl | Transfers data from/to a server. | $ curl -O https://example.com/file.zip → Downloads file.zip . |
wget | Downloads files from the web. | $ wget https://example.com/file.zip → Downloads file.zip . |
ssh | Connects to a remote server. | $ ssh user@192.168.1.1 → Opens an SSH session. |
6. Disk Management
Command | Description | Example |
df | Displays disk space usage. | $ df -h → Shows disk usage in a human-readable format. |
du | Displays directory size. | $ du -sh /var/log → Shows the size of /var/log . |
lsblk | Lists block devices. | $ lsblk → Displays attached drives and partitions. |
7. Archiving and Compression
Command | Description | Example |
tar | Archives files. | $ tar -cvf archive.tar folder/ → Creates archive.tar from folder/ . |
gzip | Compresses files. | $ gzip file1.txt → Creates file1.txt.gz . |
gunzip | Extracts .gz files. | $ gunzip file1.txt.gz → Restores file1.txt . |
8. Advanced Commands
Command | Description | Example |
grep | Searches for text in files. | $ grep "error" logs.txt → Finds "error" in logs.txt . |
awk | Processes text patterns. | $ awk '{print $1}' file.txt → Displays the first column. |
sed | Edits text streams. | $ sed 's/old/new/g' file.txt → Replaces "old" with "new". |
Conclusion
Using examples, the participants will master the necessary commands and gain greater confidence while dealing with Linux systems. Would you like to know more about an extended use of a definite command? Let us know in the comments!