Bash backup specified file extensions in multiple directories -
i have line here find "$directory" -name "*.sh" -print0 | xargs -0 cp -t ~/bckup
backs ending in .sh. how multiple file extensions? i've tried different combinations of quotes, parentheses , $. none of them worked =\
i file extensions different folders , i'm not sure how search file name specific extension.
here whole code in case:
#!/bin/bash collect() { find "$directory" -name "*.(sh|c)" -print0 | xargs -0 cp -t ~/bckup #xargs handles files names spaces. gives error of "cp: not overwrite just-created" if file didn't exist } echo "starting log" timelimit=10 echo "please enter directory collect. if no input in 10 secs, default of /home selected" read -t $timelimit directory if [ ! -z "$directory" ] #if directory doesn't have length of 0 echo -e "\nyou want copy $directory." #-e \n work , won't show part of string else directory=/home/ echo "time's up. backup in $directory" fi if [ ! -d ~/bckup ] echo "directory not exist, creating now" mkdir ~/bckup fi collect echo "finished collecting" exit 0
one option might use builtin logical or (from find man page):
expr1 -o expr2 or; expr2 not evaluated if expr1 true.
so in case can do:
find "$directory" -name '*.c' -o -name '*.sh'
Comments
Post a Comment