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
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
head -c 50 file This returns the first 50 characters of the file ‘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
find *.png -mtime +5 -exec rm {} \;> This delets all files older than 5 days find *.png -mmin +60 -exec rm {} \; This deletes all png files older than 60 minutes
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 -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 $(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
find . ! -name ‘*gz’ -type f -delete This deletes all files that do not contain ‘gz’ in its filename
find . ! -name ‘*gz’ -type f This searches recursively in the current folder for all files that do not contain ‘gz’ in its name.
To search a folder recursively for files that contain a specific string using this grep -rnw -e ” . Note that this searches the file content. to search for string in file name use this find . ! -name ‘*gz’ -type f -delete