From a53ef6c6bdeafd3f13f72830f4de5dab67de41d5 Mon Sep 17 00:00:00 2001 From: Diomidis Spinellis Date: Tue, 26 Jan 2016 11:19:59 +0200 Subject: [PATCH 1/7] Add .bashrc recommendation --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index ef25da8..ee0de79 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,8 @@ Notes: - Use `alias` to create shortcuts for commonly used commands. For example, `alias ll='ls -latr'` creates a new alias `ll`. +- Save aliases and settings your commonly use in your home directory file named `.bashrc`. This will make them available in all your shell sessions. + - Understand that care is needed when variables and filenames include whitespace. Surround your Bash variables with quotes, e.g. `"$FOO"`. Prefer the `-0` or `-print0` options to enable null characters to delimit filenames, e.g. `locate -0 pattern | xargs -0 ls -al` or `find / -print0 -type d | xargs -0 ls -al`. To iterate on filenames containing whitespace in a for loop, set your IFS to to be a newline only using `IFS=$'\n'`. - In Bash scripts, use `set -x` (or the variant `set -v`, which logs raw input, including unexpanded variables and comments) for debugging output. Use strict modes unless you have a good reason not to: Use `set -e` to abort on errors (nonzero exit code). Use `set -u` to detect unset variable usages. Consider `set -o pipefail` too, to on errors within pipes, too (though read up on it more if you do, as this topic is a bit subtle). For more involved scripts, also use `trap` on EXIT or ERR. A useful habit is to start a script like this, which will make it detect and abort on common errors and print a message: From ba05a4866c674a234438e9f7989912108a295764 Mon Sep 17 00:00:00 2001 From: Diomidis Spinellis Date: Tue, 26 Jan 2016 11:24:11 +0200 Subject: [PATCH 2/7] Recommend using Git to manage .bashrc --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ee0de79..cf21ef7 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ Notes: - Use `alias` to create shortcuts for commonly used commands. For example, `alias ll='ls -latr'` creates a new alias `ll`. -- Save aliases and settings your commonly use in your home directory file named `.bashrc`. This will make them available in all your shell sessions. +- Save aliases and settings your commonly use in your home directory file named `.bashrc`. This will make them available in all your shell sessions. Synchronize this file among various computers with Git. - Understand that care is needed when variables and filenames include whitespace. Surround your Bash variables with quotes, e.g. `"$FOO"`. Prefer the `-0` or `-print0` options to enable null characters to delimit filenames, e.g. `locate -0 pattern | xargs -0 ls -al` or `find / -print0 -type d | xargs -0 ls -al`. To iterate on filenames containing whitespace in a for loop, set your IFS to to be a newline only using `IFS=$'\n'`. From 459467c5ebf132805b698ed856ed50c10eb6abf2 Mon Sep 17 00:00:00 2001 From: Diomidis Spinellis Date: Tue, 26 Jan 2016 11:28:16 +0200 Subject: [PATCH 3/7] Add home directory basics --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ef25da8..2f24165 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,9 @@ Notes: - To see recent commands, `history`. There are also many abbreviations such as `!$` (last argument) and `!!` last command, though these are often easily replaced with **ctrl-r** and **alt-.**. -- To go back to the previous working directory: `cd -` +- Go to your home directory with `cd`. Access files relative to your home directory with the `~` prefix (e.g. `~/.bashrc`). In `sh` scripts refer to the home directory as `$HOME`. + +- To go back to the previous working directory: `cd -`. - If you are halfway through typing a command but change your mind, hit **alt-#** to add a `#` at the beginning and enter it as a comment (or use **ctrl-a**, **#**, **enter**). You can then return to it later via command history. From 3fd605653a4c4421b29a4aa2b8f7d620d6ab3be5 Mon Sep 17 00:00:00 2001 From: Diomidis Spinellis Date: Tue, 26 Jan 2016 11:36:08 +0200 Subject: [PATCH 4/7] Add version control management --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index ef25da8..ed10532 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,8 @@ Notes: - Basic network management: `ip` or `ifconfig`, `dig`. +- Learn and use a version control management system, such as `git`. + - Know regular expressions well, and the various flags to `grep`/`egrep`. The `-i`, `-o`, `-v`, `-A`, `-B`, and `-C` options are worth knowing. - Learn to use `apt-get`, `yum`, `dnf` or `pacman` (depending on distro) to find and install packages. And make sure you have `pip` to install Python-based command-line tools (a few below are easiest to install via `pip`). From c86523be03356d30eb5bd27dbcf6e526b2fff104 Mon Sep 17 00:00:00 2001 From: Diomidis Spinellis Date: Tue, 26 Jan 2016 17:54:34 +0200 Subject: [PATCH 5/7] Fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cf21ef7..29941c4 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ Notes: - Use `alias` to create shortcuts for commonly used commands. For example, `alias ll='ls -latr'` creates a new alias `ll`. -- Save aliases and settings your commonly use in your home directory file named `.bashrc`. This will make them available in all your shell sessions. Synchronize this file among various computers with Git. +- Save aliases and settings you commonly use in your home directory file named `.bashrc`. This will make them available in all your shell sessions. Synchronize this file among various computers with Git. - Understand that care is needed when variables and filenames include whitespace. Surround your Bash variables with quotes, e.g. `"$FOO"`. Prefer the `-0` or `-print0` options to enable null characters to delimit filenames, e.g. `locate -0 pattern | xargs -0 ls -al` or `find / -print0 -type d | xargs -0 ls -al`. To iterate on filenames containing whitespace in a for loop, set your IFS to to be a newline only using `IFS=$'\n'`. From dbc8f924d24cfd40c1cda04a72c987ad03d4b1d9 Mon Sep 17 00:00:00 2001 From: Diomidis Spinellis Date: Tue, 26 Jan 2016 20:44:56 +0200 Subject: [PATCH 6/7] Add .bash_profile description --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 29941c4..c8ca568 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,11 @@ Notes: - Use `alias` to create shortcuts for commonly used commands. For example, `alias ll='ls -latr'` creates a new alias `ll`. -- Save aliases and settings you commonly use in your home directory file named `.bashrc`. This will make them available in all your shell sessions. Synchronize this file among various computers with Git. +- Save aliases, shell settings, and functions you commonly use in `~/.bashrc`, and [arrange for login shells to source it](http://superuser.com/a/183980/7106). This will make your setup available in all your shell sessions. + +- Put the settings of environment variables as well as commands that should be executed when you login in `~/.bash_profile`. Separate configuration will be needed for shells you launch from graphical environment logins and `cron` jobs. + +- Synchronize your configuration files (e.g `.bashrc` and `.bash_profile`) among various computers with Git. - Understand that care is needed when variables and filenames include whitespace. Surround your Bash variables with quotes, e.g. `"$FOO"`. Prefer the `-0` or `-print0` options to enable null characters to delimit filenames, e.g. `locate -0 pattern | xargs -0 ls -al` or `find / -print0 -type d | xargs -0 ls -al`. To iterate on filenames containing whitespace in a for loop, set your IFS to to be a newline only using `IFS=$'\n'`. From 2c5df2316990966064edf3e79514b9f2cb83dc25 Mon Sep 17 00:00:00 2001 From: Diomidis Spinellis Date: Tue, 26 Jan 2016 20:57:29 +0200 Subject: [PATCH 7/7] Add command-specific environment settings --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index ef25da8..f530536 100644 --- a/README.md +++ b/README.md @@ -204,6 +204,8 @@ Notes: - Know that locale affects a lot of command line tools in subtle ways, including sorting order (collation) and performance. Most Linux installations will set `LANG` or other locale variables to a local setting like US English. But be aware sorting will change if you change locale. And know i18n routines can make sort or other commands run *many times* slower. In some situations (such as the set operations or uniqueness operations below) you can safely ignore slow i18n routines entirely and use traditional byte-based sort order, using `export LC_ALL=C`. +- You can set a specific command's environment by prefixing its invocation with the environment variable settings, as in `TZ=Pacific/Fiji date`. + - Know basic `awk` and `sed` for simple data munging. For example, summing all numbers in the third column of a text file: `awk '{ x += $3 } END { print x }'`. This is probably 3X faster and 3X shorter than equivalent Python. - To replace all occurrences of a string in place, in one or more files: