xargs
build and execute command lines from standard input
- Delete all files in the current working directory which end with "pyc".
ls | grep pyc$ | xargs rm
- Recursively find all PHP files in the current working directory and determine which of the files contain calls to the PHP mysql_connect function.
find . -type f -name '*.php' | xargs grep 'mysql_connect('- Find the number of lines for given extensions. This example would give you the number of lines for all Python and C++ files in the current directory and below.
find . -regextype posix-egrep -regex '.*(py|cpp)$' | xargs wc -l
- Display number of file descriptors the current user has open.
lsof -u `whoami` | grep -v PID | awk '{print $2}' | uniq | xargs -ia ls -l /proc/a/fd 2>&1 | grep -v "total" | wc -l- Display total number of file descriptors currently open.
ps aux | grep -v PID | awk '{print $2}' | uniq | xargs -ia ls -l /proc/a/fd 2>&1 | grep -v "total" | wc -l- Forcefully kill all processes matching pattern $1
ps aux | grep $1 | grep -v "gkill $1" | awk '{print $2}' | xargs kill -9