๐Ÿ–ฅ๏ธ Advanced Linux Commands

Mohammad KasimMohammad Kasim
3 min read

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
    
    • 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
    
    • ๐Ÿ”’ No one can modify the file because Write (2) is removed.
  • ๐Ÿšซ Remove execute permission from a file:

    Copy

        chmod -x file.sh
    
    • The -x removes execute permission from the file.

๐Ÿ‘ค Change File Ownership (chown & chgrp)

  • ๐Ÿ‘ค Change the file owner:

    Copy

        sudo chown newuser file.txt
    
    • newuser becomes the owner of file.txt.
  • ๐Ÿ‘ฅ Change both owner and group:

    Copy

        sudo chown newuser:newgroup file.txt
    
    • newuser is the new owner.

    • newgroup is the new group.


2. ๐ŸŒ Network Monitoring & Troubleshooting

๐Ÿ” Check Open Network Connections (netstat, ss)

  • ๐Ÿ“ถ List all open ports and services:

    Copy

        netstat -tulnp
    
    • 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
    
    • โšก Faster alternative to netstat.

๐Ÿ› ๏ธ Network Diagnostics (ping, nslookup, traceroute)

  • ๐Ÿ”„ Test network connectivity:

    Copy

        ping google.com
    
    • Sends ICMP echo requests to check if google.com is reachable.
  • ๐ŸŒ Get DNS information of a domain:

    Copy

        nslookup google.com
    
    • Resolves the IP address of google.com using DNS lookup.
  • ๐Ÿƒ Trace the route packets take to a destination:

    Copy

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

3. ๐Ÿ’ฝ Transfer Files Over SSH (scp)

  • ๐Ÿ“‚ Copy a file to a remote server:

    Copy

        scp file.txt user@remote:/path/
    
    • Securely copies file.txt from your local machine to /path/ on the remote server.

4. ๐Ÿ”‘ SSH Command for Remote Access

  • ๐Ÿš€ Access a remote server using SSH:

    Copy

        ssh user@remote
    
    • 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).


5. โณ Automation & Scheduling Tasks (cron)

โŒš Schedule Jobs with Cron

  • ๐Ÿ“ Edit the cron table:

    Copy

        crontab -e
    
    • Opens the cron job editor.
  • ๐Ÿ’พ Schedule a backup every day at midnight:

    Copy

        0 * * * * /home/user/backup.sh
    
    • This cron job will run /home/user/backup.sh at the start of every hour.
0
Subscribe to my newsletter

Read articles from Mohammad Kasim directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Mohammad Kasim
Mohammad Kasim

Tech enthusiast | Code craftsman | DevOps explorer | Turning bugs into features one line at a time ๐Ÿš€