Linux web hosting is turning heads these days and being a Linux system admin, it is essential to know and have various commands of Linux on your fingertips for faster execution of any task. You can not only use commands of Linux to provide output faster but also to fetch correct and fancy output by piping two or more commands. So it helps Linux admins to do their work smartly.

There are thousands of commands in Linux, but today I am going to explain the most commonly used Linux commands which are used to manage Linux server having cPanel/WHM control panel. Although cPanel itself provides GUI to manage hosting account as well as server but a hardcore system admin who loves to work in command line, prefers using commands to manage the server. 🙂
Lets start with the commands now !

Basic Linux commands with examples

  • Top

    Top is a real-time reporting system for uptime, number of logged users, load average, Task status, CPU status, memory status as well as process status. It is first preferred command of Linux admins to check load of server.

    top-comds
    There are many switches in top commands but mostly used switch is “-c” which shows the full command line for each process.
    # top -c

  • Ownership and Permission command (chown and chmod)

    Most of the time website doesn’t work or throws “Internal Server Error” due to wrong permissions or because of ownership of files/directories being placed in home directory of website. In cPanel, website home directory is /home/<cPanel_user> so correct ownership is:

    # chown <cPanel_user>:nobody /home/<cPanel_user>/public_html

    But all the files/directories within public_html directory will get <cPanel_user> ownership and the command is as below:

    # chown -R <cPanel_user>:<cPanel_user> /home/<cPanel_user>/public_html/*

    Here, Option -R is used for Recursive.Permission of cPanel user is 750 so the command is:

    # chmod 750 /home/<cPanel_user>/public_html

    And the correct permission of files is 644 and 755 for directory in public_html directory. As said earlier, Linux admin uses two or more commands for smart work. For this, find command is mostly used to effect the changes in all the files or directories.

    1. For directory permission:
      # find /home/<cPanel_user>/public_html -type d -exec chmod 755 {} ;
    2. For files permission:
      # find /home/<cPanel_user>/public_html -type f -exec chmod 644 {} ;
  • Tail

    Tail command is used to print last 10 lines of a file to standard output. With switch “-n”, it is used to print number of last line from a file and with switch “-f”, it prints the real-time last lines.

    # tail –n 1000 /var/log/message
    And
    # tail –f /var/log/message

    In cPanel server, tail is used to check various logs like error_logs, access_logs etc.

    1. Commands that can be used to check error and access logs of cPanel:
      # tail –f /usr/local/cpanel/logs/error_log
      # tail –f /usr/local/cpanel/logs/access_log
    2. Command to check Apache logs for a particular cPanel user:
      #tail –f /usr/local/apache/logs/access_log |grep <cPanel_user>
      # tail –f /usr/local/apache/logs/error_log | grep <cPanel_user>
    3. Command to get Exim mail logs of a particular email ID:
      # tail –f /var/log/exim_mainlog |grep <email id>
    4. Command to get FTP logs of a particular cPanel user:
      # tail –f /var/log/message |grep <cPanel_user>
    5. Command to find PHP mail script directory:
      # tail –f /var/log/exim_mainlog |grep cwd
  • Exim

    cPanel uses exim for SMTP service. So Linux admins should have knowledge of exim command to check and manage mails on the server. Below are the exim commands used commonly:

    1. Total number of mail queue:
      # exim –bpc
    2. List all messages in queue:
      # exim -bp
    3. View the header of the message:
      # exim –Mvh <Message_ID>
    4. View the body of the message:
      # exim –Mvb <Message_ID>
    5. Remove all frozen messages:
      # exim -bp | exiqgrep -i | xargs exim –Mrm
      or
      # exiqgrep -z -i | xargs exim -Mrm
    6. Delete mail queue of a particular sender’s email ID:
      # exim -bpr | grep <sender_email_id> | awk {‘print $3 ‘} | xargs -n1 exim -Mrm
  • Netstat

    Netstat command shows network status like network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.

    Below are the most used netstat commands in cPanel server:

    1. Check port listening
      # netstat –punta |grep :<port_number>
    2. Connection status
      # netstat -nap | awk ‘/tcp/ {print $6}’| sort | uniq –c

    five-top-comdds

    1. Command to show the connections from a certain IP on port 80:
      # netstat -plan|grep :80|awk {‘print $5’}|cut -d: -f 1|sort|uniq -c|sort -nk 1

    five-top-comdds2

  • Tar

    Tar command is used to compress and extract files/directory. In cPanel, if you want to extract only public_html directory from full backup of account, then below command is used:

    # tar –zxvf cpmove-<cPanel_user>.tar.gz cpmove-<cPanel_user>/homedir/public_html

    If you want to extract only index.php file from full backup, then use below command:

    # tar –zxvf cpmove-<cPanel_user>.tar.gz cpmove-<cPanel_user>/homedir/public_html/index.php

  • Rsync

    Rsync is used to sync or copy files from one server to another. If you have a cPanel account of very big size (more than 50GB) and you want to migrate this account from one server to another, then first all the config files are migrated by transfer tool but then the files and directories are migrated via below command:

    # rsync -vrplogDtH root@<source_server_ip>:/home/<cPanel_user> /home/

  • cPanel scripts’ commands

    Below are the most commonly used cPanel commands to manage a hosting account:

    1. Backup cPanel account:
      # /script/pkgacct <cPanel_user>
      This command places backup in /home directory.
    2. Restore cPanel account:
      #/script/restoreacct <cPanel_user>

      This command restores account if the backup is placed in /home directory.

      If the backup is placed in some other directory like /backup, then below command is used:

      # /script/restoreacct /backup/<cPanel_backup_file>

    3. Terminate an account:
      # /script/removeacct <cPanel_user>
    4. Update cPanel version:
      # /script/upcp
    5. Rebuild apache configuration:
      # /script/rebuildhttpconf
    6. Reconfigure PHP:
      # /script/easyapache
  • MySQL commands

    If the database size is larger than 1GB, then it will be difficult to manage database via phpmyadmin and the only option is command line. Below commands are used to manage databases in cPanel server.

    1. To take backup of database (eg db_name)
      # mysqldump db_name > db_name.sql
    2. Import database
      # mysql db_name < db_name.sql
    3. Check database consistency
      # mysqlcheck –c db_name
    4. Repair database
      # mysqlcheck –auto-repair db_name
    5. Optimize database
      # mysqlcheck –o db_name
  • Kill

    Sometimes Linux admins have to terminate a process if it causes any issues. For example, backup process should be killed in peak time if the load is high on the server. Below commands are used to kill processes:

    1. Kill process via ID
      # kill -9 <process_id>

      It terminates only a particular process.

    2. Terminate all child as well as parent processes
      # killall <process>
      Eg. # killall cpbackup
      # killall httpd

Conclusion: Linux commands help system admins to manage servers in a smart way but it is necessary that system admin must know each Linux command in depth before running it as the server might crash if a wrong command is run.

Services ZNetLive offer:

Domain Names India

Shared Hosting India

WordPress Hosting India

VPS Hosting India

Dedicated Server India

Kaushal Kishor Mahato

Kaushal Kishor, a computer engineering graduate from Nepal, is the Linux system admin of great caliber. With an expertise of over 5 years in Linux systems’ administration, his areas of interest include server monitoring, performance tuning and security implementation. When he is not passing time with servers, he goes for movies with friends and surfs about new technologies to keep himself abreast with the latest.
Kaushal Kishor Mahato

Latest posts by Kaushal Kishor Mahato (see all)