Skip to content

Instantly share code, notes, and snippets.

@CodyStringham
Last active September 11, 2017 15:03
Show Gist options
  • Select an option

  • Save CodyStringham/d8586ac23631913b13c055924c1531e9 to your computer and use it in GitHub Desktop.

Select an option

Save CodyStringham/d8586ac23631913b13c055924c1531e9 to your computer and use it in GitHub Desktop.
Helpful Shell Stuff!

Shell Editing

Change hello to goodbye

This will create a duplicate file called greetings.txt.old so you can compare.

sed -i '.old' 's/Hello/Goodbye/' greetings.txt

Undo if mistakes

mv greetings.txt.old greetings.txt
y

Change without creating a duplicate

The empty string says to override the current file.

sed -i '' 's/Hello/Goodbye/' greetings.txt

Shell Searching

Print last 5 lines of log

tail -n 5 log/staging.log

Search for text

grep Hello log/staging.log

Search and ignore case

grep -i hello log/staging.log

Search with regex

grep -E '[Hh]ello' log/staging.log

Find everything that doesn't include 200

grep -v 200 log/staging.log

Search directory

grep -r hello /path/to/search
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment