Category Archives: Linux

Linux commands and simple HowTos

Configuring SELinux Policies for Apache Web Servers

Overview SELinux can be very troublesome when deploying web applications on Red Hat while not using the default Apache directories, for either content or logs. Your application may need to be installed in a separate directory or maybe, for other … Continue reading

Posted in Linux | Tagged | Leave a comment

Grep through files and replace

Want to replace recursively http://example.co.uk with http://10.0.0.7 and also create backups of the files modified: grep -rFl “http://www.example.co.uk” /path  | xargs sed -i.bak ‘s/http:\/\/www.example.co.uk/http:\/\/10.0.0.7/g’

Posted in Linux | Tagged , , | Leave a comment

PS Codes

ps ax PROCESS STATE CODES Here are the different values that the s, stat and state output specifiers (header “STAT” or “S”) will display to describe the state of a process: D uninterruptible sleep (usually IO) R running or runnable … Continue reading

Posted in Linux | Leave a comment

Install OpenDKIM with Postfix on CentOS

Install opendkim    ( epel repoor other sources ) Either find/add those options to the original config file, or even better, make a copy of the original file and replace /etc/opendkim.conf with the following: AutoRestart Yes # Need to investigate this … Continue reading

Posted in Linux | Tagged | Leave a comment

Reduce KVM Windows qcow2 file size

Clean up the virtual drive (remove temps files, etc) Defrag with the open source UltraDefrag software with “full optimisation” Run “sdelete -z c:“ Run “qemu-img convert -p -f qcow2 -O qcow2 Win7.qcow2  /newpath/Win7.qcow2“ For Linux Guest: dd if=/dev/zero of=/mytempfile # … Continue reading

Posted in Linux, Windows | Tagged | Leave a comment

Bash Assign Find Output To Array

To assign the output to an array, you need to use a command substitution inside of an array assignment. arr=($(grep -n “search term” file.txt | sed ‘s/:.*//’)) The inner $() runs the command while the outer () causes the output … Continue reading

Posted in Linux | Tagged , | Leave a comment

Shrinking LVM logical volume with ext3/ext4 filesystem

… the required steps to reduce the size of an LVM logical volume formatted as an ext4 filesystem… 1) Unmount the logical volume (or boot into a live CD if the logical volume contains the root filesystem) 2) Check the … Continue reading

Posted in Linux | Tagged , | Leave a comment

Escape special characters inside folder/file name variable

array=(`find /path/ -mindepth 2 -maxdepth 2 -type d -print | sed -e ‘s;[^/]*/;;g’ |  sed ‘s/&/\\&/’`) ( sed ‘s/&/\\&/’  replaces & with \& in the folder/file name )

Posted in Linux | Tagged , | Leave a comment

Expanding a LVM root partition to fill remaining drive space

Expanding a LVM root partition to fill remaining drive space 09 Dec 2009 When I deploy new servers through VMWare ESX, I usually copy an existing base that I have already setup. I keep the base image VMDK size small … Continue reading

Posted in Linux | Tagged | Leave a comment

Resize KVM guest disk space then resize PV LV

Increase KVM virtual machine guest’s disk space from the command line if you initially set insufficient amount of disk space: Shutdown the VM Move the current image mv mykvm.img mykvm.img.bak Create a new image qemu-img create -f raw addon.raw 30G … Continue reading

Posted in Linux | Tagged , | Leave a comment