read a file in reverse

At times it is required to read a file in reverse. i.e. starting from the last time and reading up. The best way to do this is to use the ‘tac’ command tac filename

Merge multiple text files into another file

One way to merge multiple text files into a new text file is to use the cat command. cat file1.csv file2.csv > file3.csv This command merges file1.csv and file2.csv into a new file called file3.csv we can also append to an existing file instead of creating a new one cat file1.csv file2.csv >> file3.csv This … Read more

Flush Memcached

Memcached can be flushed by firing the following command echo ‘flush_all’ | nc localhost 11211 This needs ‘nc’ to be installed. nc can be installed on ubuntu by the command ‘sudo apt-get install nc’ In case nc cannot be installed, another way to flush memcache is to use telnet. type in telnet localhost 11211 Once … Read more

tail a file that is recreated

tail -f –follow=name –retry fie This will tail a file even if the file is recreated. Typical use includes tailing a log file that is rolled over. (e.g. apache logs)

kill all processes with a specific string in its name

kill $(ps aux | grep “java” | grep -v ‘grep’ | awk ‘{print $2}’) kills all java processes. grep -v ‘grep’ ignores the current grep command If you need to give them a chance to gracefully shut down first then do this pids=”$(ps -C “java” -o pid,bsdstart | fgrep -v “:” | awk ‘{print $1}’)” … Read more