cat all files recursively in a directory
find . -name ‘*.txt’ -exec cat {} \; This command finds all files that have an extension of .txt in the current directory and its sub directories and executes a cat command on them
find . -name ‘*.txt’ -exec cat {} \; This command finds all files that have an extension of .txt in the current directory and its sub directories and executes a cat command on them
Use the du command to get the size of a directory du -h prints the size of current directory and each directory under it in a human readable form. To get the size of the current directory only use this command du -sh to get the size of a particular directory du -sh
The cut command is extremely powerful. In this example we look at using the cut command to parse a comma separated file and retrieve columns 1 to 4 cut -d “,” -f -4 -d specifies the delimiter -f specifies which columns to select. In this case we select all columns upto 4 The unix pipe … Read more
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