delete all msg in the postfix queue

just type a simple “postsuper -d ALL” and they are gone 😉

Posted in commandline, linux, postfix, snipped | Leave a comment

Bash infinite loop

#!/bin/bash
while :
do
	echo "Press [CTRL+C] to stop.."
	sleep 1
done

This is a loop that will forever print “Press [CTRL+C] to stop..”. Please note that : is the null command. The null command does nothing and its exit status is always set to true. You can modify the above as follows to improve the readability:

#!/bin/bash
while true
do
	echo "Press [CTRL+C] to stop.."
	sleep 1
done

A single-line bash infinite while loop syntax is as follows:

 while :; do echo 'Hit CTRL+C'; sleep 1; done

OR

 while true; do echo 'Hit CTRL+C'; sleep 1; done

Bash for infinite loop example

#!/bin/bash
 
for (( ; ; ))
do
   echo "Pres CTRL+C to stop..."
   sleep 1
done

How Do I Escape the Loop?

A for or while loop may be escaped with a break statement when certain condition is satisfied:

 ### for loop example ###
for (( ; ; ))
do
   echo "Pres CTRL+C to stop..."
   sleep 1
   if (disaster-condition)
   then
	break       	   #Abandon the loop.
   fi
done

OR

 ### while loop example ###
while :
do
   echo "Pres CTRL+C to stop..."
   sleep 1
   if (disaster-condition)
   then
	break       	   #Abandon the loop.
   fi
done
Posted in commandline, linux, snipped | Tagged | Leave a comment

How to execute a command whenever a file changes?

while inotifywait -e close_write myfile.py; do ./myfile.py; done

or

inotifywait -q -m -e close_write myfile.py |
while read -r filename event; do
  ./myfile.py         # or "./$filename"
done

The first snippet is simpler, but it has a significant downside: it will miss changes performed while inotifywait isn’t running (in particular while myfile is running). The second snippet doesn’t have this defect.

Posted in commandline, linux, snipped | Leave a comment

sed replace word / string syntax

The syntax is as follows:
sed -i 's/old-word/new-word/g' *.txt

GNU sed command can edit files in place (makes backup if extension supplied) using the -i option. If you are using an old UNIX sed command version try the following syntax:

sed 's/old/new/g' input.txt > output.txt

Posted in commandline, linux, snipped | Leave a comment

How can I find the oldest file in a directory tree

find -type f -printf '%T+ %p\n' | sort | head -n 1
Posted in commandline, linux, snipped | Leave a comment

Backups with tar

tar -cvpzf backup.tar.gz --exclude=/backup.tar.gz --one-file-system /

 

Posted in commandline, linux, snipped | Leave a comment

Hello Again !

This is now my 3rd attempt to run this personal Blog

Posted in Uncategorized | Leave a comment