Basic SSH Commands for Linux

1. File and Directory Management

  • ls – Lists files and directories.
  • ls -al

    Shows all files, including hidden ones, with details.

  • cd – Changes directories.
  • cd /usr/local/apache

    Moves to the Apache directory.

    cd ~

    Moves to the home directory.

    cd ..

    Moves up one directory level.

  • cat – Displays file contents.
  • cat filename.txt
  • more – Views file content one screen at a time.
  • more /etc/userdomains

2. File Permissions and Ownership

  • chmod – Changes file permissions.
  • chmod 644 index.html

    Common permission for HTML files.

    chmod 755 script.cgi

    Common permission for CGI scripts.

  • chown – Changes file ownership.
  • chown root file.txt

    Sets the owner to root.

    chown user.group file.txt

    Changes owner and group.

3. File Manipulation

  • cp – Copies files.
  • cp file1.txt file1_backup.txt
  • mv – Moves or renames files.
  • mv oldname.txt newname.txt
  • rm – Deletes files.
  • rm -rf /tmp

    Be careful: This deletes the entire directory recursively!

  • touch – Creates an empty file.
  • touch newfile.txt

4. Disk Usage and Monitoring

  • du – Shows disk usage.
  • du -sh

    Summarizes total disk usage.

  • wc – Counts words, lines, characters.
  • wc -l filename.txt

    Shows line count of a file.

5. Process and System Monitoring

  • top – Displays real-time system processes.
  • top
    Shift + M

    Sorts by memory usage.

  • ps – Lists running processes.
  • ps aux
  • kill – Terminates processes.
  • kill -9 PID

    Force-kills a process using its PID.

  • netstat – Shows network connections.
  • netstat -an

    Displays active connections.

6. User and Login Information

  • w – Shows currently logged-in users.
  • w
  • who – Lists users connected to the server.
  • who
  • last – Shows login history.
  • last -20

    Displays the last 20 logins.

7. Archiving and Compression

  • tar – Creates and extracts tar archives.
  • tar -zxvf file.tar.gz

    Extracts a .tar.gz file.

    tar -cf archive.tar directory/

    Creates an archive.

  • gzip – Compresses files.
  • gzip file.txt

    Compresses file.txt into file.txt.gz.

  • unzip – Extracts .zip files.
  • unzip file.zip

8. Firewall and Security

  • iptables – Configures the firewall.
  • iptables -I INPUT -s 192.168.1.100 -j DROP

    Blocks an IP.

    iptables -L

    Lists firewall rules.

9. Web Server Commands

  • Apache Commands
  • service httpd restart

    Restarts Apache.

    httpd -v

    Displays Apache version.

  • MySQL Commands
  • mysqladmin processlist

    Shows active MySQL queries.

    mysql -u user -p database < backup.sql

    Restores a MySQL database.

    mysqldump -u user -p database > backup.sql

    Backs up a MySQL database.

10. Advanced Shell Command Combinations

  • Piping Data
  • grep User /usr/local/apache/conf/httpd.conf | more

    Filters results and displays them page-by-page.

  • Redirecting Output
  • ls -al > directory_list.txt

    Saves output to a file.

    ls -al >> directory_list.txt

    Appends output to an existing file.

Need a Reliable Linux Server? Choose UnderHost!

If you're managing a Linux server, you'll need a robust hosting provider. UnderHost's dedicated servers come with full root access, advanced security, and 24/7 support. Whether you need Offshore VPS for privacy or high-speed 10Gbps Dedicated Servers, we have you covered.

Get expert support at UnderHost Customer Panel anytime.