Skip to main content

Command Palette

Search for a command to run...

πŸ–₯️ Advanced Linux Commands

Published
β€’3 min readβ€’View as Markdown
πŸ–₯️ Advanced Linux Commands
M

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

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.

More from this blog

Untitled Publication

78 posts