From aa20e47e0d03d48068fd22d99772315bccf11fbf Mon Sep 17 00:00:00 2001 From: kesu Date: Wed, 24 Jun 2015 15:28:50 +0000 Subject: [PATCH 01/11] Added bullet for alias. Fixes #119 --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 0d890a1..88187f6 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,8 @@ Notes: - Learn about file glob expansion with `*` (and perhaps `?` and `{`...`}`) and quoting and the difference between double `"` and single `'` quotes. (See more on variable expansion below.) +- Use `alias` to create shortcuts or synonyms for commonly used commands. For example: `alias ll='ls -latr'` creates a new alias `ll`. + - Be familiar with Bash job management: `&`, **ctrl-z**, **ctrl-c**, `jobs`, `fg`, `bg`, `kill`, etc. - Know `ssh`, and the basics of passwordless authentication, via `ssh-agent`, `ssh-add`, etc. From 6c26b698623f903917ff615a0f1ce66000b2ab0b Mon Sep 17 00:00:00 2001 From: Joshua Levy Date: Wed, 1 Jul 2015 21:58:16 -0700 Subject: [PATCH 02/11] Correct omission of sort -n. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ec29e3c..7a61169 100644 --- a/README.md +++ b/README.md @@ -196,7 +196,7 @@ Notes: - Use `shuf` to shuffle or select random lines from a file. -- Know `sort`'s options. Know how keys work (`-t` and `-k`). In particular, watch out that you need to write `-k1,1` to sort by only the first field; `-k1` means sort according to the whole line. Stable sort (`sort -s`) can be useful. For example, to sort first by field 2, then secondarily by field 1, you can use `sort -k1,1 | sort -s -k2,2`. For handling human-readable numbers (e.g. from `du -h`) use `sort -h`. +- Know `sort`'s options. For numbers, use `-n`, or `-h` for handling human-readable numbers (e.g. from `du -h`). Know how keys work (`-t` and `-k`). In particular, watch out that you need to write `-k1,1` to sort by only the first field; `-k1` means sort according to the whole line. Stable sort (`sort -s`) can be useful. For example, to sort first by field 2, then secondarily by field 1, you can use `sort -k1,1 | sort -s -k2,2`. - If you ever need to write a tab literal in a command line in Bash (e.g. for the -t argument to sort), press **ctrl-v** **[Tab]** or write `$'\t'` (the latter is better as you can copy/paste it). From cba6daafda73a43d53738e2ca0a75d9467b7c499 Mon Sep 17 00:00:00 2001 From: Joshua Levy Date: Fri, 3 Jul 2015 00:22:55 -0700 Subject: [PATCH 03/11] Include uname Fixes #114. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7a61169..5ddfa10 100644 --- a/README.md +++ b/README.md @@ -252,7 +252,7 @@ Notes: - For deeper systems and performance analyses, look at `stap` ([SystemTap](https://sourceware.org/systemtap/wiki)), [`perf`](http://en.wikipedia.org/wiki/Perf_(Linux)), and [`sysdig`](https://github.com/draios/sysdig). -- Confirm what Linux distribution you're using (works on most distros): `lsb_release -a` +- Check what OS you're on with `uname` or `uname -a` (general Unix/kernel info) or `lsb_release -a` (Linux distro info). - Use `dmesg` whenever something's acting really funny (it could be hardware or driver issues). From 27eb7509a121dbd8a0ee99a9d67ba042c53621a8 Mon Sep 17 00:00:00 2001 From: Joshua Levy Date: Fri, 3 Jul 2015 00:46:48 -0700 Subject: [PATCH 04/11] New section specific to MacOS. Fixes #153, #134. --- README.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5ddfa10..d5178e4 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ - [System debugging](#system-debugging) - [One-liners](#one-liners) - [Obscure but useful](#obscure-but-useful) +- [MacOS only](#macos-only) - [More resources](#more-resources) - [Disclaimer](#disclaimer) @@ -32,7 +33,7 @@ but given the interest there, it seems it's worth using Github, where people mor Scope: - This guide is both for beginners and the experienced. The goals are *breadth* (everything important), *specificity* (give concrete examples of the most common case), and *brevity* (avoid things that aren't essential or digressions you can easily look up elsewhere). Every tip is essential in some situation or significantly saves time over alternatives. -- This is written for Linux. Many but not all items apply equally to MacOS (or even Cygwin). +- This is written for Linux, with the exception of the "[MacOS only](#macos-only)" section. Many of the other items apply or can be installed on other Unices or MacOS (or even Cygwin). - The focus is on interactive Bash, though many tips apply to other shells and to general Bash scripting. - It includes both "standard" Unix commands as well as ones that require special package installs -- so long as they are important enough to merit inclusion. @@ -435,6 +436,21 @@ A few examples of piecing together commands: - `fortune`, `ddate`, and `sl`: um, well, it depends on whether you consider steam locomotives and Zippy quotations "useful" +## MacOS only + +These are items relevant *only* on MacOS. + +- Package management with `brew` (Homebrew) and/or `port` (MacPorts). These can be used to install on MacOS many of the above commands. + +- Copy output of any command with `pbcopy` and paste input with `pbpaste`. + +- To open a file with a desktop app, use `open` or `open -a /Applications/Whatever.app`. + +- Spotlight: Search files with `mdfind` and list metadata (such as photo EXIF info) with `mdls`. + +- Be aware MacOS is based on BSD Unix, and many commands (for example `ps`, `ls`, `tail`, `awk`, `sed`) have many subtle variations from Linux, which is largely influenced by System V-style Unix and GNU tools. You can often tell the difference by noting a man page has the heading "BSD General Commands Manual." In some cases GNU versions can be installed, too (such as `gawk` and `gsed` for GNU awk and sed). + + ## More resources - [awesome-shell](https://github.com/alebcay/awesome-shell): A curated list of shell tools and resources. From f4789f0aa4d0c1494e7ef79276b71bf2c6b8d21b Mon Sep 17 00:00:00 2001 From: Joshua Levy Date: Fri, 3 Jul 2015 00:52:01 -0700 Subject: [PATCH 05/11] One more update to MacOS section. #153 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d5178e4..65b2189 100644 --- a/README.md +++ b/README.md @@ -442,13 +442,13 @@ These are items relevant *only* on MacOS. - Package management with `brew` (Homebrew) and/or `port` (MacPorts). These can be used to install on MacOS many of the above commands. -- Copy output of any command with `pbcopy` and paste input with `pbpaste`. +- Copy output of any command to a desktop app with `pbcopy` and paste input from one with `pbpaste`. - To open a file with a desktop app, use `open` or `open -a /Applications/Whatever.app`. - Spotlight: Search files with `mdfind` and list metadata (such as photo EXIF info) with `mdls`. -- Be aware MacOS is based on BSD Unix, and many commands (for example `ps`, `ls`, `tail`, `awk`, `sed`) have many subtle variations from Linux, which is largely influenced by System V-style Unix and GNU tools. You can often tell the difference by noting a man page has the heading "BSD General Commands Manual." In some cases GNU versions can be installed, too (such as `gawk` and `gsed` for GNU awk and sed). +- Be aware MacOS is based on BSD Unix, and many commands (for example `ps`, `ls`, `tail`, `awk`, `sed`) have many subtle variations from Linux, which is largely influenced by System V-style Unix and GNU tools. You can often tell the difference by noting a man page has the heading "BSD General Commands Manual." In some cases GNU versions can be installed, too (such as `gawk` and `gsed` for GNU awk and sed). If writing cross-platform Bash scripts, avoid such commands (for example, consider Python or `perl`) or test carefully. ## More resources From d623fee2e09e8343a29c4fc6734492bac87ee9a8 Mon Sep 17 00:00:00 2001 From: Joshua Levy Date: Fri, 3 Jul 2015 00:54:30 -0700 Subject: [PATCH 06/11] Mention appending with >>. Fixes #151. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 65b2189..a5d9b89 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ Notes: - Know how to read documentation with `man` (for the inquisitive, `man man` lists the section numbers, e.g. 1 is "regular" commands, 5 is files/conventions, and 8 are for administration). Find man pages with `apropos`. Know that some commands are not executables, but Bash builtins, and that you can get help on them with `help` and `help -d`. -- Learn about redirection of output and input using `>` and `<` and pipes using `|`. Learn about stdout and stderr. +- Learn about redirection of output and input using `>` and `<` and pipes using `|`. Know `>` overwrites the output file and `>>` appends. Learn about stdout and stderr. - Learn about file glob expansion with `*` (and perhaps `?` and `{`...`}`) and quoting and the difference between double `"` and single `'` quotes. (See more on variable expansion below.) From 2a68e1aab59e8c46bde8ea56571b25597005f4fd Mon Sep 17 00:00:00 2001 From: Joshua Levy Date: Fri, 3 Jul 2015 00:59:32 -0700 Subject: [PATCH 07/11] Add sudo and su. Fixes #150. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index a5d9b89..db5b175 100644 --- a/README.md +++ b/README.md @@ -151,6 +151,8 @@ Notes: - For a simple web server for all files in the current directory (and subdirs), available to anyone on your network, use: `python -m SimpleHTTPServer 7777` (for port 7777 and Python 2) and `python -m http.server 7777` (for port 7777 and Python 3). +- For running a command with privileges, use `sudo` (for root) or `sudo -u` (for another user). Use `su` or `sudo bash` to actually run a shell as that user. Use `su -` to simulate a fresh login as root or another user. + ## Processing files and data From 1262a25e9a989eb1c48b84aad93cf86409e8b546 Mon Sep 17 00:00:00 2001 From: Joshua Levy Date: Fri, 3 Jul 2015 01:13:06 -0700 Subject: [PATCH 08/11] Add sponge #60 --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index db5b175..6f82761 100644 --- a/README.md +++ b/README.md @@ -379,6 +379,8 @@ A few examples of piecing together commands: - `split `and `csplit`: splitting files +- `sponge`: read all input to memory before wriring it, useful for reading from then writing to the same file (for example, `grep -v something some-file | sponge some-file`) + - `units`: unit conversions and calculations; converts furlongs per fortnight to twips per blink (see also `/usr/share/units/definitions.units`) - `7z`: high-ratio file compression From d285213f08cb732997af5014a228bbad296a26e0 Mon Sep 17 00:00:00 2001 From: Joshua Levy Date: Fri, 3 Jul 2015 01:15:18 -0700 Subject: [PATCH 09/11] Fix language re sponge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6f82761..ea6b753 100644 --- a/README.md +++ b/README.md @@ -379,7 +379,7 @@ A few examples of piecing together commands: - `split `and `csplit`: splitting files -- `sponge`: read all input to memory before wriring it, useful for reading from then writing to the same file (for example, `grep -v something some-file | sponge some-file`) +- `sponge`: read all input before wriring it, useful for reading from then writing to the same file, e.g., `grep -v something some-file | sponge some-file` - `units`: unit conversions and calculations; converts furlongs per fortnight to twips per blink (see also `/usr/share/units/definitions.units`) From b09a1864e38b3515ff97f58b7603395d83fc059c Mon Sep 17 00:00:00 2001 From: Joshua Levy Date: Fri, 3 Jul 2015 01:19:26 -0700 Subject: [PATCH 10/11] Add fzf Fixes #96 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ea6b753..d6775ed 100644 --- a/README.md +++ b/README.md @@ -144,7 +144,7 @@ Notes: stat -c '%A %a %n' /etc/timezone ``` -- For interactive selection of values from the output of another command, use [`percol`](https://github.com/mooz/percol). +- For interactive selection of values from the output of another command, use [`percol`](https://github.com/mooz/percol) or [`fzf`](https://github.com/junegunn/fzf). - For interaction with files based on the output of another command (like `git`), use `fpp` ([PathPicker](https://github.com/facebook/PathPicker)). From 7469c72e0f0b50ddf42946fd704cdee856262a2d Mon Sep 17 00:00:00 2001 From: Joshua Levy Date: Fri, 3 Jul 2015 02:14:04 -0700 Subject: [PATCH 11/11] Move alias info to "Everyday use." Better fit in that section. #119 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 38ca118..870a2f3 100644 --- a/README.md +++ b/README.md @@ -55,8 +55,6 @@ Notes: - Learn about file glob expansion with `*` (and perhaps `?` and `{`...`}`) and quoting and the difference between double `"` and single `'` quotes. (See more on variable expansion below.) -- Use `alias` to create shortcuts or synonyms for commonly used commands. For example: `alias ll='ls -latr'` creates a new alias `ll`. - - Be familiar with Bash job management: `&`, **ctrl-z**, **ctrl-c**, `jobs`, `fg`, `bg`, `kill`, etc. - Know `ssh`, and the basics of passwordless authentication, via `ssh-agent`, `ssh-add`, etc. @@ -102,6 +100,8 @@ Notes: - See also `lsof` for open sockets and files. +- Use `alias` to create shortcuts for commonly used commands. For example, `alias ll='ls -latr'` creates a new alias `ll`. + - In Bash scripts, use `set -x` for debugging output. Use strict modes whenever possible. Use `set -e` to abort on errors. Use `set -o pipefail` as well, to be strict about errors (though this topic is a bit subtle). For more involved scripts, also use `trap`. - In Bash scripts, subshells (written with parentheses) are convenient ways to group commands. A common example is to temporarily move to a different working directory, e.g.