Category Archives: Bash

Bash string comparison

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465#!/bin/bash function test(){ echo "" echo "TEST $1" echo "VAR_1: $VAR_1 VAR_2: $VAR_2 " if [ "$VAR_1" = "false" ]; then echo " VAR_1 is false"; fi if [ "$VAR_2" = "false" ]; then echo " VAR_2 is false"; fi … Continue reading

Posted in Bash, Linux | Leave a comment

Crontab header

123456# minute (0-59), # |      hour (0-23), # |      |       day of the month (1-31), # |      |       |       month of the year (1-12), # … Continue reading

Posted in Bash, Linux | Leave a comment

Linux find files and total their size

1find ./ -type f -newerct "1 May 2015" ! -newerct "1 Jul 2015" -print0 | du –files0-from=- -hc| tail -n1

Posted in Bash, Linux | Leave a comment

Search and replace withing a file

1234567sed -i -e"s/SEARCH_TEXT/REPPLACE_TEXT/g" FILENAME.txt # another example using bakup sed -i.bak -e"s/SEARCH_TEXT/REPPLACE_TEXT/g" FILENAME.txt # another example using variable sed -i -e"s/\/pathname/\/pathname-$date/g" "filename-"$date".xml"

Posted in Bash, Linux, Operating System | Leave a comment

Bash Scripting Basics (Variable Assignment, If, Loop)

12345678910111213141516171819202122232425262728293031#!/bin/bash ################################################## # Benchmark the processing time when wkhtmltopdf # converts an html file to a pdf file ################################################## if [[ $1 = "" || $2 = "" || $3 = "" ]]; then         echo "Usage: … Continue reading

Posted in Bash, Linux | Leave a comment

Compress and Extract Files in Linux

Extract: .tar.bz2 To extract a tar (Tape ARchiver) file, type the following in the shell prompt: 1tar xvjf yourFileName.tar.bz2 Which will untar it to the current directory. Depending on the file structure that being compressed, it might create sub-directories. Parameters: … Continue reading

Posted in Bash, Linux | Tagged | Leave a comment

Delete files older than X number of days in Linux

Say you backup your database daily and you need to delete the old backup files. You can issue the command bellow which will erase any files within the specified directory that are older than 7 days. 1$ find /your/target/directory* -mtime … Continue reading

Posted in Bash, Linux, Operating System | Leave a comment