Linux Server Commands & Basic Overview

Description

This document focuses on managing the server from the command line. Linux or Unix version is irrelevant in 99% of the cases, however, there are some commands specific to your operating system which you’ll also need to familiarize yourself with. All of these commands, once installed on the system, can be read about in more detail by using the ‘man’ command, which is short for ‘manual’. The manual will be help when you run into trouble on the job and it’s one of, or you your only available resource.

Any os-specific commands used throughout this site, as mentioned above, are going to be Red Hat, Centos or Fedora Linux commands. The main 2 commands handle package management details, ‘yum‘ and ‘rpm‘. See their respective manpages for more help with them: man rpm or man yum

All commands listed here are safe to run and non-destructive to your system but you should always exercise caution when copying commands from any websites. It’s a good idea to setup an isolated test environment in a Virtual Machine manager like Vagrant or a spare laptop lying around for testing and running commands without fear of data loss.

Common Basic Server Configurations

These are the most common basic webserver software configurations for various operating systems, there are many other configurations as well.

LAMP Stack

Linux
Apache httpd
MySQL / Maria
PHP / Perl / Python

LEMP Stack

Linux
Enginx
MySQL / Maria
PHP / Perl / Python

MAMP Server

Mac OSX
Apache httpd
MySQL / Maria
PHP / Perl / Python

WAMP Server

Windows
Apache httpd
MySQL / Maria
PHP / Perl / Python
Also see: XAMPP

Basic Server Management

Remember that type case (aA) is important on Linux, Unix and Mac OSX operating systems. If a command has upper or lowercase letters it’s generally for a reason.

cd
– Change directory.

Example: cd /var/www

chmod
– Change mode of files and directories.

Example: chmod -Rf 755 /var/www/example.com

chown
– Change ownership of files and directories.

Example: chown -Rf webuser:bob /var/www/example.com

cp
– Copy files and directories.

Example: cp -r /var/www/exmaple.com ~/backups

df
– Displays total disk usage for mounted filesystems.

Example: df -h

du
– Displays total disk usage for named directories.

Example: du -chs /var/www/example.com

find
– Searches a given directory structure for a named string and displays pertinent results.

Example: find /home/ -iname "back*"

grep
– Searches the named input file(s) (or standard input if no files are named, or the file name – is given) for lines containing a match to the given pattern.

Example: grep -r -i "include_once*" /var/www/example.com

groupadd
– reate a new group on the system.

Example: groupadd sshusers

groupdel
– Remove group on the system.

Example: groupremove sshusers

ls
– List files and directories.

Example: ls -lash /var/www

mv
– Move or rename files and directories.

Example: mv /var/www/example.com /var/www/example.net

nano
– A popular text editor.

Example: nano /var/www/example.com/index.php

rm
– Remove or delete files and directories.

Example: rm -f /var/www/example.com/testfile.php

passwd
– Used to update a user’s authentication token(s).

Example: passwd bob

ps
– Prints a list of currently running processes, their respective owners and process id’s.

Example: ps aux

pwd
– Print the name of the working directory.

Example: pwd

useradd
– Add new users to the system.

Example: useradd bob

userdel
– Delete users from the system.

Example: useerdel bob

usermod
– Modify users on the system.

Example: usermod -a -G sshuusers bob

vi
– A popular text editor.

Example: vi /var/www/example.com/index.php

Advanced Server Management

These commands are generally used for maintenance, troubleshooting issues or monitoring the system.

apachetop
– Display real-time web server statistics in a like the ‘top’ command.

Example: apachetop /var/log/httpd/example.com_access_log

dstat
– Dstat is a versatile replacement for vmstat, iostat and ifstat and allows you to view all system resources instantly.

Example: dstat

htop
– Interactive process viewer

Example: htop

kill
– Terminate a currently running or rogue process. also see: killall.

Example: kill -9 12345

mc
– (Midnight Commander) Visual shell for Unix-like systems

Example: mc

mytop
– Display MySQL / MariaDB server performance info like the ‘top’ command.

Example: mytop

screen
– Full featured virtual terminal and terminal sharing application.

Example: screen -S unique_name

sed
– Stream editor for filtering and transforming (inserting, deleting, rearranging, editing) text.

Example: sed -i 's/foo/foo_bar/g' /path/to/file

strace
– trace system calls and signals from a running program.

Example: strace /usr/sbin/httpd

su
– Substitute user command. most commonly used to run commands / daemons which require root privileges, view / alter certain directories, files and log files.

Example: su -
Note: the ‘-‘ is important because it gives us the shell of the user which is handy for running commands without the full path.

tail
– View or output the last x=n lines of a file, useful for error log debugging.

Example: tail -f /var/log/httpd/example.com_error_log

Last Modified: 27 Dec, 2015 at 20:17:29