#: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 filesmv
moves and renames filesrm
removes filesrm -r
removes directories
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
- Pipe is used to pass output to another program or utility.
- Redirect is used to pass output to either a file or stream