Monthly Archives: September 2017

Bash Function to find files with a certain extension

ls_ext () { find . -type f -iname '*.'${1}'' -exec ls -l {} \; ; }

or

ls_ext ()
{
 find . -type f -iname '*.'${1}'' -exec ls -l {} \; ;
}

then type “ls_ext pdf” or “ls_ext txt”

use unset -f function-name in this case “unset -f ls_ext” to clear the function.

Function to test multiple commands.

function mytest {
    "$@"
    local status=$?
    if [ $status -ne 0 ]; then
        echo "error with $1" >&2
    fi
    return $status
}

mytest $command1
mytest $command2