DEV Community

Cover image for 🖥️ Advanced Linux Commands
Kasim Hussain
Kasim Hussain

Posted on

🖥️ Advanced Linux Commands

Advanced Linux commands for System Management

  1. 🔐 Advanced File Permissions & Ownership File Permissions in Linux:

r: Read (4) 📖

w: Write (2) ✍️

x: Execute (1) ▶️

Permissions are added together to set them.

🔧 Modify File Permissions (chmod)
✅ Give full permission to the owner, read-execute to others:

Copy

chmod 755 script.sh
Enter fullscreen mode Exit fullscreen mode

7 → Owner permission: Read (4) + Write (2) + Execute (1) = 7

5 → Group permission: Read (4) + Execute (1) = 5

5 → Others permission: Read (4) + Execute (1) = 5

❌ Make a file read-only for everyone:

Copy

chmod 444 important.txt
Enter fullscreen mode Exit fullscreen mode

🔒 No one can modify the file because Write (2) is removed.
🚫 Remove execute permission from a file:

Copy

chmod -x file.sh
Enter fullscreen mode Exit fullscreen mode

The -x removes execute permission from the file.
👤 Change File Ownership (chown & chgrp)
👤 Change the file owner:

Copy

sudo chown newuser file.txt
Enter fullscreen mode Exit fullscreen mode

newuser becomes the owner of file.txt.
👥 Change both owner and group:

Copy

sudo chown newuser:newgroup file.txt
Enter fullscreen mode Exit fullscreen mode

newuser is the new owner.

newgroup is the new group.

  1. 🌐 Network Monitoring & Troubleshooting 🔍 Check Open Network Connections (netstat, ss) 📶 List all open ports and services:

Copy

netstat -tulnp
Enter fullscreen mode Exit fullscreen mode

t: Shows TCP connections.

u: Shows UDP connections.

l: Shows listening ports.

n: Displays numeric addresses.

p: Shows process ID (PID).

🌍 Check listening ports (alternative to netstat):

Copy

ss -tulnp
Enter fullscreen mode Exit fullscreen mode

⚡ Faster alternative to netstat.
🛠️ Network Diagnostics (ping, nslookup, traceroute)
🔄 Test network connectivity:

Copy

ping google.com
Enter fullscreen mode Exit fullscreen mode

Sends ICMP echo requests to check if google.com is reachable.
🌐 Get DNS information of a domain:

Copy

nslookup google.com
Enter fullscreen mode Exit fullscreen mode

Resolves the IP address of google.com using DNS lookup.
🏃 Trace the route packets take to a destination:

Copy

traceroute google.com
Enter fullscreen mode Exit fullscreen mode

Shows each hop (router) a packet takes to reach google.com.

  1. 💽 Transfer Files Over SSH (scp) 📂 Copy a file to a remote server:

Copy

scp file.txt user@remote:/path/
Enter fullscreen mode Exit fullscreen mode

Securely copies file.txt from your local machine to /path/ on the remote server.

  1. 🔑 SSH Command for Remote Access 🚀 Access a remote server using SSH:

Copy

ssh user@remote
Enter fullscreen mode Exit fullscreen mode

ssh: Securely logs you into a remote server.

user: Replace with the username on the remote server.

remote: Replace with the server's IP address or hostname (e.g., 192.168.1.10).

  1. ⏳ Automation & Scheduling Tasks (cron) ⌚ Schedule Jobs with Cron 📝 Edit the cron table:

Copy

crontab -e
Enter fullscreen mode Exit fullscreen mode

Opens the cron job editor.
💾 Schedule a backup every day at midnight:

Copy

0 * * * * /home/user/backup.sh
Enter fullscreen mode Exit fullscreen mode

This cron job will run /home/user/backup.sh at the start of every hour.

Top comments (0)