Skip to content

Instantly share code, notes, and snippets.

@skube
Last active August 29, 2015 14:27
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 skube/4e2dc4d83d3e3ec8a02c to your computer and use it in GitHub Desktop.
Save skube/4e2dc4d83d3e3ec8a02c to your computer and use it in GitHub Desktop.
Command Line Tips

#:notebook_with_decorative_cover: Understanding Command Line Abridged from Codecademy

##List

  • ls -t orders files and directories by the time they were last modified

##Copy, Move, Rename & Delete##

  • cp copies files
  • mv moves and renames files
  • rm removes files
  • rm -r removes directories

Useful Utils

  • grep : searches for a text pattern and outputs it.
  • sed : searches for a text pattern, modifies it, and outputs it.
  • sort : sorts lines of text alphabetically.
  • uniq : filters duplicate, adjacent lines of text.

###grep grep stands for "global regular expression print". It searches files for lines that match a pattern and returns the results. It is also case sensitive. Use i option for case insensitive.

Find all instances of "Mount" in `mountain.txt' regardless of case

$ grep -i Mount mountains.txt

Recursively search (within) files within a directory

$ grep -R searchForSomething /path/to/directory

###sed sed stands for "stream editor". It accepts standard input and modifies it based on an expression, before displaying it as output data. It is similar to "find and replace". Works on each line separately. Use g flag to match all instances on line, not just first.

$ sed 's/snow/rain/g' forests.txt

Putting it all together: Pipes & Redirects

  • Pipe is used to pass output to another program or utility.
  • Redirect is used to pass output to either a file or stream
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment