Skip to content

Instantly share code, notes, and snippets.

@seanrankin
Last active November 30, 2016 18:25
Show Gist options
  • Save seanrankin/e6542c997419e22ad593 to your computer and use it in GitHub Desktop.
Save seanrankin/e6542c997419e22ad593 to your computer and use it in GitHub Desktop.
A collection of examples of shell scripts I've found handy
# Securly copy from a remote to local:
scp -r [email protected]:/path/to/folder ~/path/to/folder
# Pipe out commands to the at command
echo "Print this out..." | at 7am
# Sleep then do something
sleep 10 && echo 'Ten seconds have passed.'
# Curl the contents of a file
$ for i in `cat urls.txt` ; do curl -O $i ; done
# Curl a file and save it locally
$ curl -o test.txt http://textfiles.com/adventure/221baker.tx
# Rename using a regular expression, remove the echo after testing
for f in *.mp4; do echo mv "$f" "${f#*' - '}"; done
## GREP
# Find a word
grep "liver" words.txt
# Two characters and then the string
grep "..ver" words.txt
# Save the results of search to a file
grep "liver" words.txt > results.txt
# Find in all files
sudo find / -name "com.apple.mail.plist"
# Find in your home
sudo find ~/ -name "com.apple.mail.plist"
# Find a type of file
find ~/ -iname "*.jpg"
# ... and output to a file
$ find ~/ -iname "*.jpg" > liver.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment