Get the total number of lines

July 18, 2009

If you want to know the total number of lines of files in a directory, execute the following line of script in your terminal. You can also save this command in a file and execute.

lines=0; for i in `find . -name “*.php”`; do line=`cat $i | wc -l`; let lines=$lines+$line; done; echo $lines

lines=0; for i in `find /var/www/wordpress -name “*.php”`; do line=`cat $i | wc -l`; let lines=$lines+$line; done; echo $lines

OR

find . -name “*.php” -print0 | xargs -0 wc -l | tail -n1


Get the count of files of a specific file type

July 18, 2009

To know the count of files of a particular type in a directory

find . -name “*.png” | wc -l

find /usr/share/images/ “*.jpg” | wc -l


Uninterruptable processes

May 12, 2009

The processes which are trying to access I/O device may me uninterruptable when that I/O device is very busy/unavailable. For example suppose a process is accessing an NFS shared file and if the NFS server is stopped,  the process state becomes “Uninterruptable”. That means it cannot be killed. To kill such processes either the machine has to reboot or the process should get the unavailable resource back.

The following command lists the uninterruptable processes.

ps axo stat|grep -i D

By piping the above output to wc and cut you will get the count of uninterruptable process.

ps axo stat|grep -i D|wc|cut -d ” ” -f1-10