Shell (unix) commands you always forget
This is a list of typical commands that I often have to Google because I forget either their usage or important flags.
Using grep
with perl type regex
Using the -P
flag lets you search for more advanced regex expressions. Other useful grep flags:
-i
ignore case-o
print only matching-v
invert matching-A number
show lines after match-B number
show lines before match
Using grep
without pipe
searches after pattern hell\w
in current directory and sub-directories. Add -h
to ignore filenames in output.
For loops - range
For loops - command
Bash script for traversing arguments and line breaks
Simple sed
commands
Search and replace file content:
From pipe and print result:
To replace matched regex groups, use \1, \2 and so on.
Finding size of subfolders, sorted.
du -h d -1
is the disc usage command with the-h
flag for outputting human readable sizes and-d 1
for depth of 1 sub dirs.sort -hr
sorts human readable sizes in reverse order.