Handy Linux Commands For Managing Your Web-hosting Server Like A Pro

Working on the Linux command-line

There are a lot of things you can do from the command line. Correction. There are a lot of things you can only do from a command line. My main system is a MacBook Pro which supports all of the above commands; because it’s UNIX. Linux isn’t different. My second laptop runs Arch Linux with XFCE and Deepin. My hosting server is the cutting edge Fedora which I tinker around with everyday. So even I can’t remember how much I know Linux. But suffice it to say, these commands are the stepping stone to getting familiar with Linux.

Login to a remote system via ssh

ssh username@yourdomainorip -i full-path-to-ssh-privatekey-including-file-name

Clear the terminal


Show current directory


List files in the current directory

ls -al

Navigate to another directory or folder

cd foldername

Navigate to the parent directory or folder

cd ..

Moving and renaming files

mv file destination


mv wp-config.php /var/www/html/

Rename works the same

mv .htaccess wp.htaccess

Becoming superuser (equivalent of administrator in Windows)

sudo commandname

Switch to different user

sudo su username

Switch to ‘root’ user

sudo su -

Installing software

Fedora / RHEL based systems

sudo dnf install packagename

On Debian based systems

sudo apt-get install packagename

Updating the Server Softwre

Fedora / RHEL based systems

sudo dnf update

On Debian based systems

sudo apt-get update

Monitoring system performance


(usually not installed by default)


(usually not installed by default)

Creating backups

Create a tar archive of a folder

tar cvjf archivename.tar.bz2 foldertobackup


tar cvjf mybackup.tar.bz2 wp-content

Backing up or dumping a database

mysqldump -u username --password="insert your password here" databasename > database.sql

Importing a database dump

mysql -u username --password="insert your password here" databasename < database.sql

Extracting archive

tar xvjf archivename.tar.bz2

Simple recursive copy

cp -rv folder destination

Efficient copying over network

rsync -arzv directory destination

If you want to try a dry run without changing anything, try:

rsync -arzvn directory destination

Managing Services

Checking the status of a service

systemctl status service

Example: check the status of apache

systemctl status httpd

Enabling a service

systemctl enable service

Example: enable apache to automatically start on boot

systemctl enable httpd

Disabling a service

systemctl disable service

Example: disable apache from automatically start on boot

systemctl disable httpd

Start a service

systemctl start service

Example: start apache manually

systemctl start httpd

Restart a service

systemctl restart service

Example: restart apache service

systemctl restart httpd

Finding help

Finding help for linux is very easy. However before you resort to Google, you can try the following commands:

Most commands in Linux support the --help argument

command --help

Look up the manual

man command

Commands helpful for coders

Searching for strings in files

Search for string in files (r to search recursively, n to show line numbers in files, the dot means in the current directory and sub-directories)

grep -rn "string to search for" .

Example: Search for function do_action. Comes in handy to find where a WordPress function is declared and to study the function code.

grep -rn "function do_action" .

Finding Files

find . -iname "filename"

Example, let's find the location of the apache configuration file:

find . -iname "httpd.conf"

Output: (The second line shows the path of the found file)

[root@localhost /]# find . -iname "httpd.conf"

Getting header information from command line. This one is very useful. I've seen that redirects in .htaccess are cached by browsers. And when I want to be absolutely sure that the browser is not redirecting anymore I use curl. It also comes in handy when troubleshooting headers and various server-level and SEO kind of geek stuff.

curl -I http://google.com

Notice the difference from the regular URL.


curl -I http://google.com
HTTP/1.1 302 Found
Cache-Control: private
Content-Type: text/html; charset=UTF-8
Referrer-Policy: no-referrer
Location: http://www.google.co.in/?gfe_rd=cr&dcr=0&ei=lll7Wvz3Eojy8AezhrLQAw
Content-Length: 271
Date: Wed, 07 Feb 2018 19:55:02 GMT

It gives a 302 found temporary header and had various other information about server headers.

Downloading via command line

wget https://wordpress.org/latest.tar.gz

This downloads the resource to the current directory (WordPress archive in the above example).

I'd love to cover a lot about Linux because I've been using it for about 20 years now. However let's just keep this one to the basics. Once you get a grasp on these, it will be easier to learn the advanced stuff like piping commands.

Oh and did I forget the very basic reboot?

sudo reboot
sudo shutdown now

Those are easy once you know them.

The next step is to play around with regular expressions—cryptic strings that have the superpowers to find, match, replace complex strings with literals or tokens. But that's for another day. For now, boot up a live Linux distro and hack it out. It won't hurt a thing and you'll learn a trick or two which will last you your entire career.

Comment on Handy Linux Commands For Managing Your Web-hosting Server Like A Pro

Your email address will not be published. Required fields are marked *