cheatsheets/command_line.md

172 lines
2.8 KiB
Markdown
Raw Permalink Normal View History

2013-10-14 02:36:58 +00:00
---
2012-12-15 12:56:59 +00:00
title: Command line stuff
---
2013-01-03 09:53:53 +00:00
## List (ls)
{: .-three-column}
### Usage
2012-12-15 12:56:59 +00:00
ls [options] [paths]
2015-03-11 11:44:53 +00:00
### Format
| Switch | Description |
|---|---|
| `-1` | One entry per line |
| `-l` | Long view |
| `-o` | Long view (without groups) |
| `-C` | Multicolumn (sorted horizontally) |
| `-x` | Multicolumn (sorted vertically) |
|---
| `-F` | Add / after directories |
| `-G` | Color |
### Options
| `-R` | Recurse |
| `-a` | Include hidden (dotfiles) |
| `-A` | Include hidden (but not . and ..) |
### Sorting
| Switch | Description |
|---|---|
| `-r` | reverse order |
| `-S` | sort by size |
| `-t` | sort by time modified |
| `-u` | sort by time accessed |
| `-U` | sort by time created |
| `-c` | sort by time status was changed |
|---
| `-h` | Human-readable size (3k) |
2012-12-15 12:56:59 +00:00
2013-01-03 09:53:53 +00:00
## Tail
{: .-three-column}
### Usage
2013-01-03 09:53:53 +00:00
tail [-F | -f | -r] [-bN | -cN | -nN] [file ...]
2015-03-11 11:44:53 +00:00
### Modes
2013-01-03 09:53:53 +00:00
2015-03-11 11:44:53 +00:00
| `-f` | follow |
| `-F` | follow by filename (accounts for log rotation) |
| `-r` | Reverse order |
2013-01-03 09:53:53 +00:00
2015-03-11 11:44:53 +00:00
### Options
2013-01-03 09:53:53 +00:00
2015-03-11 11:44:53 +00:00
| `-bN` | N*512 bytes |
| `-cN` | N bytes |
| `-nN` | N lines |
| `+N` | Start from line N |
2013-01-03 09:53:53 +00:00
2015-03-11 11:44:53 +00:00
<br>
2013-01-03 09:53:53 +00:00
## Sudo
{: .-three-column}
### Usage
2013-01-03 09:53:53 +00:00
2015-03-11 11:44:53 +00:00
```
sudo [options] <command>
```
2013-01-03 09:53:53 +00:00
2015-03-11 11:44:53 +00:00
### Listing
2013-01-03 09:53:53 +00:00
2015-03-11 11:44:53 +00:00
| `-l` | List allowed commands |
2013-01-03 09:53:53 +00:00
2015-03-11 11:44:53 +00:00
### Options
2013-01-03 09:53:53 +00:00
2015-03-11 11:44:53 +00:00
| `-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 |
2013-01-03 09:53:53 +00:00
2015-03-11 11:44:53 +00:00
### File descriptors
2013-01-03 09:53:53 +00:00
2015-03-11 11:44:53 +00:00
| `-C fd` | Close all open file descriptors |
2013-01-03 09:53:53 +00:00
2015-03-11 11:44:53 +00:00
### Prompt
2013-01-03 09:53:53 +00:00
2015-03-11 11:44:53 +00:00
| `-p prompt` | Custom prompt (-p "%p password:") |
2013-01-03 09:53:53 +00:00
2015-03-11 11:44:53 +00:00
### Interactive
2013-01-03 09:53:53 +00:00
2015-03-11 11:44:53 +00:00
| Switch | Description |
|---|---|
| `-i [cmd]` | Interactive shell without variables |
| `-s [cmd]` | Interactive shell |
|----
| `-u user` | run as this user |
| `-g group` | run as this group |
2013-01-03 09:53:53 +00:00
2015-03-11 11:44:53 +00:00
### Timestamp
2013-01-03 09:53:53 +00:00
2015-03-11 11:44:53 +00:00
| `-v` | revalidate timestamp for 5 mins |
| `-k` | invalidate timestamp |
| `-K` | just like -k |
2013-01-03 09:53:53 +00:00
2015-03-11 11:44:53 +00:00
## wc (Word count)
{: .-three-column}
### wc
2013-01-03 09:53:53 +00:00
2015-03-11 11:44:53 +00:00
```
... | wc [options]
```
2012-12-15 12:56:59 +00:00
### Options
2015-03-11 11:44:53 +00:00
| `-c` | Bytes |
| `-l` | Lines |
| `-m` | Characters (incl multi-byte) |
| `-w` | Words |
2013-01-08 08:37:25 +00:00
2015-03-11 11:44:53 +00:00
## Grep
{: .-three-column}
### Usage
2013-01-08 08:37:25 +00:00
2015-03-11 11:44:53 +00:00
```
grep [options] [pattern] [file ...]
```
### 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 |
### Synonyms
2013-01-08 08:37:25 +00:00
egrep => grep -E
fgrep => grep -F
## Other recipes
{: .-three-column}
### Search-and-replace in all files
perl -p -i -e 's/hello/HELLO/g' **/*