DEV Community

Lam
Lam

Posted on

Command Line Stuff Cheat Sheet

Reference

[Grep] Synonyms

egrep  =>  grep -E
fgrep  =>  grep -F
Enter fullscreen mode Exit fullscreen mode

[Grep] Options

Switch Description
-A num Print num lines of training context
----
-G --basic-regexp (default)
-E --extended-regexp
-P --perl-regexp
----
-f file --file (Get patterns for file)
-F --fixed-strings
----
-h --no-filename
-H --with-filename
----
-l --files-with-matches (just print filenames)
-L --files-without-match
----
-r, -R --recursive
-v --invert-match
-i --ignore-case

{:.shortcuts}

Grep

grep [options] [pattern] [file ...]
Enter fullscreen mode Exit fullscreen mode

Search-and-replace in all files

perl -p -i -e 's/hello/HELLO/g' **/*
Enter fullscreen mode Exit fullscreen mode

wc (Word count)

... | wc [options]
Enter fullscreen mode Exit fullscreen mode

| -c | Bytes |
| -l | Lines |
| -m | Characters (incl multi-byte) |
| -w | Words |

[Sudo] Timestamp

| -v | revalidate timestamp for 5 mins |
| -k | invalidate timestamp |
| -K | just like -k |

[Sudo] Interactive

Switch Description
-i [cmd] Interactive shell without variables
-s [cmd] Interactive shell
----
-u user run as this user
-g group run as this group

[Sudo] Prompt

| -p prompt | Custom prompt (-p "%p password:") |

[Sudo] File descriptors

| -C fd | Close all open file descriptors |

[Sudo] Options

| -A | Use $SUDO_ASKPASS |
| -b | Run in background |
| -E | Preserve environment |
| -H | use target's $HOME |
| -n | Don't prompt for password |
| -P | Preserve group vector |
| -S | Read password from stdin |

Top comments (0)