Linux Notes

These are Linux specific, consisting of quick How-To helper notes. These are primarily geared toward CentOS and/or Ubuntu.

Note: If you are not the root user, you may need to add "sudo" to the beginning of each command.

Basic Linux Commands

These are various commands for Linux, some commonly used and others not so much. Useful commands, none the less.

Restart
shutdown -r
View Top Running Processes
top
Find out what directory you are in
pwd
Get a list of system users
awk -F':' '{ print $1}' /etc/passwd
Set Hostname
hostname hostname.domain.com
Move and Copy
Move a file
mv /path/to/file-being-moved.jpg /new/path/file-being-moved.jpg
Copy a file
cp /path/to/file-being-copied.jpg /new/path/file-being-copied.jpg
Delete Files and Directories
Delete a file
rm /path/to/file-being-removed.jpg
Delete a directory
rmdir /path/to/directory-being-removed
Delete a directory that has files
rm -rf /path/to/directory-being-removed
Permissions and Ownership
Permissions - Change all sub directories to 755
find /path/to/directory -type d -exec chmod 755 {} \;
Permissions - Change all files in directory and sub directories to 644
find /path/to/directory -type f -exec chmod 644 {} \;
Ownership - Change owner of directory and subdirectories
chown -R username:groupname .

Apply Updates

This is how you update CentOS and Ubuntu

CentOS
Clean Yum (optional but recommended)
yum clean all
Update
yum update
Ubuntu
Get the available files
apt-get update
Upgrade the current packages
apt-get upgrade
Upgrade + dependencies
apt-get dist-upgrade

Install WP-CLI

The WordPress CLI provides a command-line interface for WordPress.

Step 1Download the WP-CLI phar file
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Step 2Change Permissions
chmod +x wp-cli.phar
Step 3Move the phar file
mv wp-cli.phar /usr/local/bin/wp

Install Memcached on CentOS 7

Be sure to update your system before running the following commands.

Step 1Install Memcached
yum -y install memcached
Step 2Restart Memcached
systemctl restart memcached
Step 3Start Memcached on Boot
systemctl enable memcached
If you need to edit your Memcached settings, the default configuration is found here
/etc/sysconfig/memcached

Install Memcached PHP Extension on CentOS 7

Be sure to update your system before running the following commands.

Step 1Install Memcache PECL
yum -y install php-pecl-memcache
Step 2Restart Memcached
systemctl restart memcached
Step 3Restart Apache
systemctl restart httpd
To verify the Memcache module is loaded
php -m | grep memcache

Enable Epel Repo on CentOS

There are a couple ways of enabling the epel repo on CentOS.

Easy Method

The easiest method to enable the Epel Repo on CentOS is to use Yum.

Step 1Use Yum
yum install epel-release

Alternative Method

If that method is unavailable on your server, go with one of the following methods below.

CentOS 6
Step 1Remove the RPM from CentOS 6
rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
CentOS 7
Step 1Remove the RPM from CentOS 7
rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

Remove Epel Repo on CentOS

There are a couple ways of removing the Epel repo on CentOS.

Easy Method

The easiest method to remove the Epel repo on CentOS is to use Yum.

Step 1Use Yum
yum remove epel-release

Alternative Method

If that method is unavailable on your server, go with one of the following methods below.

Step 1Find the RPM
rpm -qa | grep epel
Step 2Remove the RPM
rpm -e epel-release-x-x.noarch
(Replace the x-x with the release number. Example: epel-release-7-10.noarch)