System Administration

System Information

uname -a
uname -r

IP Address Management

ifconfig eth0 #show specific interface On Centos
ifconfig ens3 #show specific interface On Ubuntu
ip addr show ens3 #show specific interface
hostname -I|cut -d" " -f 1 #current ip of system/node
hostname -I | awk {'print $1'}

Disk Information

Display All FileSystems

df -ah

Check Size Of a Directory On Disk

du -sh /directory/

File Management

Find A File By filename

find /direcotry/  -name 'filename'

Delete Files Older Than X DAYS

find /path/to/directory/ -mindepth 1 -mtime +7 -delete

Delete Files Newer Than X DAYS

find /path/to/directory/ -mindepth 1 -mtime -7 -delete

Lists all certificates without accepting variables from all sites

WEBSITE_NAMES=$(ls /etc/nginx/sites-enabled)
WEBSITE_LOCATION=/etc/nginx/sites-enabled
sleep 5
for WEBSITE in $WEBSITE_NAMES;
do
    if [ -f  "$(find $WEBSITE_LOCATION/$WEBSITE  -name 'ssl_certificate')" ]; then
        echo "\e[32m$WEBSITE Certificate Exists"
    else
        echo "\e[31m$WEBSITE Certificate DOES NOT exist"
    fi
    if [ -f "$(find $WEBSITE_LOCATION/$WEBSITE -name 'ssl_certificate_key')" ]; then
        echo "\e[32m$WEBSITE Cert Key Exists"
    else
        echo "\e[31m$WEBSITE Cert Key DOES NOT exist"
    fi
done

Searches for a specific website name

WEBSITE=/etc/nginx/sites-enabled/$1/
CERT=$(find /etc/nginx/sites-enabled/$1/ -name 'ssl_certificate')
KEY=$(find /etc/nginx/sites-enabled/$1/ -name 'ssl_certificate_key')
#sleep 5
for EACH_CERT in $WEBSITE;
do
    if [ -f  "$CERT" ]; then
        echo "\e[32m$1 Certificate Exists"
    else
        echo "\e[31m$1 Certificate DOES NOT exist"
    fi
    if [ -f "$KEY" ]; then
        echo "\e[32m$1 Certificate Key Exists"
    else
        echo "\e[31m$1 Certificate KEY DOES NOT exist"
    fi
done

Service Management

systemctl status service_name

Process information Checking

ps aux | grep service_name
top
htop

Volume Management

mount /dev/sda2 /mnt

SSH Public And Private Keys Creation

ssh-keygen -t rsa -b 4096 -C "root@example.com"
ssh-copy-id -i root_id_rsa root@example.com -f

Sed Command

Changing A Word To All Files Containing It, Within A Directory

grep -rl 'apples' /dir_to_search_under | xargs sed -i 's/apples/oranges/g'

Docker Container Management

File Copy From Container To Host

docker cp container_name:/path/to/container /path/to/host

File Copy From Host To Container

docker cp /file/path/to/host/foo.txt container_name: /file/path/to/foo.txt
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

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