Category Archives: Linux

Bash: No space left on device

If you get this error on your Linux web server: -bash: No space left on device-bash: No space left on device That probably means you ran out of inodes, type this to check: df -idf -i If you see something like this: Filesystem Inodes IUsed IFree IUse% Mounted on /dev/sda2 1310720 1310720 0 100% /Filesystem […]

Bash Script to Delete PHP Session Files and Free Inodes

Use “df -i” command to view inodes usage: Filesystem Inodes IUsed IFree IUse% Mounted on /dev/sda2 1310720 1310720 0 100% /Filesystem Inodes IUsed IFree IUse% Mounted on /dev/sda2 1310720 1310720 0 100% / That means you ran out of inodes! Most probably PHP sessions are the issue. A quick command to delete all sess_* files […]

Force Overwrite Files with Cp on Linux

Command to force “cp” to copy and overwrite files without confirmation: Call “cp” directly to prevent it from using the aliased version: /bin/cp -rf /source/* /destination/bin/cp -rf /source/* /destination Or use “yes” to auto-reply with “y” to confirmation: yes | cp -rf /source/* /destinationyes | cp -rf /source/* /destination

Netstat Count Active ESTABLISHED Connections

Count all active ESTABLISHED connections: netstat -anp | grep ESTABLISHED | wc -lnetstat -anp | grep ESTABLISHED | wc -l Count all active ESTABLISHED connections on port 80: netstat -anp | grep :80 | grep ESTABLISHED | wc -lnetstat -anp | grep :80 | grep ESTABLISHED | wc -l Count all active ESTABLISHED connections on […]

Copy Files Preserving Timestamps on Linux

You can use the parameter “-p” to preserve timestamps and modification date: -p same as –preserve=mode,ownership,timestamps-p same as –preserve=mode,ownership,timestamps Recursively (-R) copy a folder maintaining modification time (-p): cp -Rp folder destinationcp -Rp folder destination Copy all .log files maintaining modification time: cp -p *.log destinationcp -p *.log destination More information: http://www.unix.com/man-page/Linux/1/cp/

Bash Script to Get Website IP Address

Simple bash script to get IP address of a website: #!/bin/bash # Usage: ./script google.com ip="$(/usr/bin/dig A $1 +short)" echo $1 = $ip#!/bin/bash # Usage: ./script google.com ip="$(/usr/bin/dig A $1 +short)" echo $1 = $ip Example output: root@server:~# ./getip.sh google.com google.com = 172.217.16.78root@server:~# ./getip.sh google.com google.com = 172.217.16.78

RAID1 vs RAID5 IOPS Write\Read Speed Benchmark

Here is a simple RAID1 vs RAID5 IOPS write\read speed benchmark test: RAID5 (3x120GB SSD) The server has the following characteristics: 2 x Intel Xeon E5 2620 12C/24T @2,00 GHz 3x120GB SSD (RAID5) 128GB RAM DDR32 x Intel Xeon E5 2620 12C/24T @2,00 GHz 3x120GB SSD (RAID5) 128GB RAM DDR3 The RAID controller type and […]

Rotate Nginx Logs and Append Date and Time

I needed to rotate Nginx logs and append the date and time, i.e: access.log => access.log-25-02-2017access.log => access.log-25-02-2017 So instead of adding a number like access.log.1 I need to add date. Here are two solutions that can be used: Use a custom bash script Here is a simple bash script that can do the work: […]

Determine RAID Controller Type and Model on Linux

First you need to install lshw and lspci: apt-get install lshw pciutilsapt-get install lshw pciutils Then type this command to get RAID controller details: lspci | grep -i raidlspci | grep -i raid It should display the RAID controller type and model, i.e: 04:00.0 RAID bus controller: Hewlett-Packard Company Smart Array Gen8 Controllers (rev 01)04:00.0 […]

Copy Files on Google Storage Buckets

You need to use gutils cp command: https://cloud.google.com/storage/docs/gsutil/commands/cp Example command to copy all .txt files to my-bucket: gsutil cp *.txt gs://my-bucketgsutil cp *.txt gs://my-bucket Example command to copy all .txt files to my-bucket/Folder/: *** Folder will be created if not existent *** gsutil cp *.txt gs://my-bucket/Folder/gsutil cp *.txt gs://my-bucket/Folder/