Skip to content

Instantly share code, notes, and snippets.

@codingbychanche
Last active June 6, 2017 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codingbychanche/88f32baa0c52cadf1b6ac160763dd1d0 to your computer and use it in GitHub Desktop.
Save codingbychanche/88f32baa0c52cadf1b6ac160763dd1d0 to your computer and use it in GitHub Desktop.
Bash Scripts
# This checks for a string in a file
search='sawfish'
file='maze.atr'
if [ $(strings $file | grep -i $search) ]
then
echo $search found in file $file
else
echo $search not found in file $file !
fi
# Search file names, save the matching results to
# a file ('result') and copy found files to a folder
# Result already there? If so, delete it
if [ $(find . -name "result") ]
then
echo Deleting existing result....
rm result
else
echo New result file will be created....
fi
# Search
find ~/ -name "*.atr" > result
# Make destination folder
mkdir filesFound
# Read result line by line and copy found files to destination....
files=0
while read result
do
let "files=files+1"
echo Files $files: Copying "$result"....
cp "$result" filesFound
done < result
echo Done! $files found and copied....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment