Linux Shell Usage (101)
Navigation
Basic Commands
ls- list filescd- change directorypwd- get working directorypushd- saves last locationpopd- pops back to saved spot
Nav Shortcuts
.- "here" or current working directory..- up one level from current directory~- current user's home directory-- last working directory
Reading Files
cat- concatenate and printless- display output one screen at a timehead- first lines of a filetail- end of a file often combined with -f (live follow)cat- concatenate and print (display) the content of files- example:
cat /etc/passwd
- example:
Changing Files
mkdir- make new directoryecho- print to standard out>- redirect and overwrite>>- redirect and appendtouch- create or change timecp- copy filesmv- move or renamerm- remove file
Searching
find- find /path -option “searchstring”grep- prints lines that match a given patterngrep -e- matches an extended expression (egrep)zgrep- search compressed files
Find
Find syntax:
find <PATH> -name “<STRING>”find /etc/elasticsearch -name "*.conf"find /etc -name jvm* -maxdepth 2
Grep
-
Options:
-iignore case-vinvert search-ccount results-oonly chars match-rrecursive-
-Eextended regex (same as egrep) -
Example 1:
grep -i 'root' /etc/passwd - Example 2: pipe output of other commands to grep
find / -name *.txt | grep apache
Sorting & Filtering
-
pipe (
|) - passes output from one command to anotherecho “echo will print this message”echo “echo will print this message” | wc- output: line word characters
cat file | grep search
-
tee- send the output of a command to a file and the screen?teels | tee lsout.txtls | tee -a lsout.txt# appendsfind /etc | sort | tee etcsort.txt | wc -lfind /etc 2> etcerr.txt | sort | tee etcsort.txt | wc -l
-
wc- print byte, word, and line counts cut- divide a file into several partsuniq- uniquify files (dedupe)sort- sort text files