Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Something like "--auto" in:

It seems a bit complicated to --no-clobber (-n) and work on return codes if [ $? -eq 1 ];then some_function $line ... $line is the absolute file path.

Here is the script i am trying to write:

# searches by filetype extension 
# writes find results to search_output
# reads lines of search_output and echo/cp/mv to current folder
# run as sudo to also search hidden folders
echo "Choose operation by entering number: ( 0:echo, 1:cp, 2:mv )"
read index

cmd[1]='cp -l'
cmd[2]='mv -i'

echo "Enter filetype extension (i.e .pdf, .jpg, .csv, ...):"
read file_extension
echo "Enter directory path ( /path/to/search/in ):"
read fp
echo "Searching for: "
echo "*$file_extension files\n"
echo "Searching recursively starting: "
echo "$fp"
# clear file
echo "" > search_output

find "$fp" -iname "*$file_extension" -fprint search_output
while read line; do eval ${cmd[$index]} '$line' .; done < search_output
echo "Files Found: "
wc -l search_output | cut -d ' ' -f 1

Posts looked at:

share|improve this question
One small comment: use read -r line instead of read line to prevent interpretation of backslashes. –  Sparhawk May 11 '14 at 5:02
Thanks for the tip @Sparhawk –  jm_____ May 11 '14 at 16:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.