2.2 Quoting and literals 4. ${#var} returns length of the string. Inside single quotes '' nothing is interpreted: 5. ${var:offset:length} skips first offset they preserve literal values of characters enclosed characters from var and truncates the output Bash 5.1.0 notes, version 0.2.209 within them. A single (strong) quote may not appear to given length. :length may be skipped. between single quotes, even when escaped, but it Negative values separated with extra space may appear between double (weak) quotes "". Remigiusz Suwalski are accepted. ey work quite similarly, with an exception that the 6. uses a default value, if shell expands any variables that appear within them ${var:-value} var August 19, 2021 is empty or unset. (pathname expansion, process substitution and word splitting are disabled, everything else works!). ${var:=value} does the same, but performs an assignment as well. Bash, a command line interface for interacting with It is a very important concept: without them Bash the operating system, was created in the 1980s. splits lines into words at whitespace characters – ${var:+value} uses an alternative value if 1 (Google) shell style guide tabs and spaces. See also: IFS variable and $'...' var isn’t empty or unset! and $"..." (both are Bash extensions, to be done). e following notes are meant to be summary of a 2.4.4 Command substitution style guide written by Paul Armstrong and too many Avoid backticks `code` at all cost! To execute commands in a subshell and then pass more to mention (revision 1.26). 2.3 Variables their stdout (but not stderr!), use $( commands) . Bash is the only shell scripting language permitted Variable names are case sensitive. ey can contain (To group them without new shell, use { cmds }.) for executables. Bash should only be used for simple digits and underscores as well, but a name starting 2.4.5 Arithmetic expansion wrapper scripts or small utilities. with a digit is not allowed. Example: e arithmetic expression $(( ...)) is evaluated Executables should have no extension, libraries var="kind" and expands to the result. Bash guarantees that the must have a .sh extension and should not be echo ${var}ness # kindness output will be a one-word integer. Exit code is zero executable. SUID and SGID are forbidden on shell ⇐⇒ output is nonzero. scripts. Special variables: 2.4.6 Process substitution All error messages should go to STDERR, a function 1. $0: name of the script itself. is kind of substitution: and to print out error messages along with other status 2. $1, $2, ...: the first, second, etc. argument. <( ... ) >( ... ) (not specified by POSIX!), where input or output of a information is recommended: shift removes first argument and advances rest of them forward. command appears as a temporary file, is performed err () { 3. $* and $@ denote all positional parameters simultaneously with the following: arithmetic and echo "[$(date +%Y-%m-%d\%T) ]: $@" >&2 ($*: as a single word, $@: as separate strings). parameter expansions, command substitution. } 4. $#: the number of positional parameters. 2.4.7 Word splitting 5. $?: exit status of last executed command. Comments. Start each file with a description of its 2.4.8 File name expansion contents. Any function that is in a library or not both 6. $$: the process ID of the shell. obvious and short, must be commented. Comment 7. $!: the process ID of last executed command. Glob patterns (composed of normal characters and , , ) are not regular expressions! Bash tricky, interesting or important parts of code. Use 2.4 Expansions * ? [...] TODO comments for temporary or good enough but supports extended globs too (X(list) where X is not perfect code and short-term solutions. Eight expansions happen a ter splitting command one from ?*+@!). into tokens, in the order that they are expanded. e following are required for any new code: 2.5 Streams 2.4.1 Brace expansion ere are always three default files open: 1. Indent 2 spaces, no tabs. Brace expansion is used when we need to generate 2. Maximum line length is 80 characters. all possible string combinations. Both of the 1. stdin (the keyboard, file descriptor 0), 3. Long pipelines should be split one per line. commands produce the same output: 2. stdout (the screen, file descriptor 1) and 4. Indent case alternatives by 2 spaces. 3. stderr (error messages, file descriptor 2). 5. Always quote strings containing variables, echo {I,really,love,dots}. spaces, command substitutions or shell meta echo I. really. love. dots. ese streams can be redirected: characters, unless unquoted expansion is Warning: it does not expand the variables ($var), 1. cmd > file redirects to a file (overwrites), required. which is done later, but supports ranges (sequences) 2. cmd >> file appends instead, Use quotes rather than filler characters if possible. of characters: 3. m>n (m>&n) redirects a file descriptor to a file Use an explicit path when doing wildcard expansion (or another file descriptor), echo {a..t} 4. redirects stdout and stderr to a file, of filenames. Avoid eval. Use process substitution &>file abcdefghijklmnopqrst or for loops in preference to piping to while. Finally, 5. | (pipe) serves as a command chaining tool. [[ ... ]] is preferred over [ and test. and (maybe zero paded or with an increment rate) Here document is a section of a file that integers, assuming the Bash version is 4 or newer: Naming conventions. Function and variable names is treated as if it were a separate file: should be lower case, with underscore to separate echo{01..10..1}. cat < /path/to/your/file words. Constants and environment variable names 01. 02. 03. 04. 05. 06. 07. 08. 09. 10. Line to be written in your file. should be all caps, declared at the top of the file. Use 2.4.2 Tilde expansion EOF readonly or declare - to ensure they’re read only. Declare function specific variables with ere is a tilde expansion as well. e expression Using 'EOF' instead prevents variable expansion. local. A function called main is required for scripts ~[user] expands to the home directory of the 2.6 Control flow statements long enough to contain at least one other function. current (or given) user. e one-line constructs and work not like and, 2.4.3 Parameter expansion && || Other useful resources If you want to understand or (∧, ∨), but the if – then – else statement. Nonzero Bash better, consider one of the following webpages: 1. ${var^}, ${var,}, ${var~} convert first exit status denotes (usually) a failure. 1. character to upper, lower or reverse case http://wiki.bash-hackers.org 2.6.1 Loops 2. http://mywiki.wooledge.org/BashGuide (every, when caret/comma/tilde are doubled). while read myline; do Avoid guides by TLDP!!! is has an impact on every array element. echo "It says ${myline}" 2. , remove ${var#pattern} ${var%pattern} done < some_file 2 Programming in Bash the pattern from the beginning, end of variable (greedy when hash, percent sign are 2.1 Shebang for var in "the first" "the second"; do doubled). Application: extracting parts of a e shebang ( ) at the head of a script indicates an echo "${var}" #! filename. interpreter for execution, as in #!/bin/bash. Lines done starting with a # (with the exception of shebang) are 3. ${var/pattern/string} performs a single for((i=1; i <= 10; i++ )); do comments and thus won’t be executed. Even better (when first slash is doubled: full) search and echo "i = ${i}." is #!/usr/bin/env bash (overflow-16365130). replace operation. done # C-style

1 2.6.2 Conditionals  compopt: ...... ???? See also ack, an optimized for programmers tool Here at least one statement must be specified inside  continue: ...... ???? like grep, at https://beyondgrep.com/ or learn every block, but one can use a single colon (:) as a  declare: ...... ???? . null statement to avoid rewriting the code.  dirs: ...... ???? 4.1 grep – pattern search enginge  disown: ...... ???? if condition; then  echo: displays a line of text: e ed command g/re/p was used to globally commands e enables interpretation of backslash escapes, search a regular expression and print. does not output the trailing newline. elif second_condition; then n ??? grep prints lines matching a pattern: some_commands enable: ...... ????  E interprets pattern as an extended regexp, else eval: ...... ????  F does not recognize regexps, other_commands exec: ...... ????  P interprets pattern as a Perl regexp, fi  exit: ...... ???? export: ...... ????  c prints a count of matching lines instead, select word in "Bash" "Haskell" "Python" false: ...... ????  m exits a ter finding ... matches, do fc: ...... ????  o prints only matched parts of lines, echo "Your language is $word". fg: ...... ????  n prints line numbers as well, done getopts: ...... ????  r reads all files under each directory.  hash: ...... ???? ere is also a case instruction: help: ...... ????  uses a “regexp” pattern, history: ...... ???? e case $language in  obtains patterns from a file, jobs: ...... ???? f bash)  ignores case disctinctions, kill: ...... ???? i echo "Bourne Again Shell!"  inverts the sense of matching, let: ...... ???? v ;;  selects only lines with whole words matches, local: ...... ???? w python|haskell)  x selects matches exactly matching whole line. echo "Python or Haskell!"  logout: ...... ???? mapfile: ...... ???? ;;  prints ... lines of trailing content, popd: ...... ???? A *)  prints ... lines of leading content, printf: ...... ???? B echo "Unknown language!"  C prints ... lines of both contents. ;; # optional  pushd: ...... ???? esac  pwd: prints name of current directory. 4.2 sed – stream editor  read: ...... ???? ??? sed filters and transforms text: 2.6.3 Single versus double square brackets readarray: ...... ????  -e adds a script to the commands to be executed, e [ command is defined by POSIX, ] prevents its readonly: ...... ????  -i edits files in place. With sufix supplied, further arguments from being used. Double return: ...... ????  makes backup (sed -i[suffix] ...), brackets, the [[ command, are a Bash extension set: ...... ????  -n suppresses auto- printing of pattern space, that changes the way text ist being parsed: shi t: ...... ????  -r accepts extended regular expressions.  shopt: ...... ???? 1. < and > compare lexicographically instead of  source: ...... ???? e simplest usage is sed 's/foo/bar/g' which redirecting streams (inside [] they have to  suspend: ...... ???? substitutes (s) strings globally (g). ere are other be escaped: \<, \>)  test: checks file types and compares values. options, including: 2. || and && are true logical operators.  times: ...... ???? 3. () groups commands (not a subshell!) a appends line before,  trap: ...... ???? 4. == without quotes does pattern matching d deletes line,  true: ...... ???? 5. =∼ matches extended regex (no i inserts line before,  type: ...... ???? []-alternative) p prints line,  typeset: ...... ???? w writes pattern space to a file. 2.6.4 Testing conditions  ulimit: ...... ???? umask: gets/sets file mode creation mask. All of these tests but -h follow symlinks (!), beware.  Default delimiter / can be replaced by any other.  unalias: ...... ???? is is useful when regular expression already 1. File tests:  unset: unsets a shell variable, removing it contains /. Addresses allow limiting to given line (a) -e file exists, -s file is nonempty, from memory and the shell’s exported numbers: (b) -d directory, -f regular file, -h environment. 1. 1-10 first ten lines symlink,  wait: waits for process to change state. (c) -b block device, -c character device, 2. $ the last line (d) -p named pipe, -S socket. 3 Emacs shortcuts in Bash 3. 10~2 even lines starting from the 10th. 2. File permissions: For detailed information on emacs editing mode, One can also use regular expressions: (a) -r readable, -w writable, -x executable, visit sed -e '/:/s/ /_/g' (b) -u setuid, -g setgid, -k sticky bit. http://readline.kablamo.org/emacs.html 3. String tests: -z empty, -n nonempty. or type man readline. replaces spaces with underscores in lines containing 4. Arithmetic tests: =, <, >, -eq -lt -gt -ne a colon. Negation may be obtained with !s. 6=, -le ≤, -ge ≥. clears the screen. Ctrl L 4.3 awk – Aho, Weinberger, Kernighan Both break and continue are accepted. Ctrl A moves to the start of the line, ??? awk is a language used as a data extraction 2.7 Shell builtins Ctrl E moves to the end of the line. and reporting tool. General form of its code:  .: ...... ???? deletes to the beginning of the line, #! /bin/awk  :: ...... ???? Ctrl U deletes to the end of the line, pattern {actions} # comment  [: ...... ???? Ctrl K deletes to the start of the word,  alias: allows a string to be substituted for a Ctrl W Supported types of pattern are word. Ctrl Y pastes text from the clipboard. 1. BEGIN for initialization,  bg: ...... ???? undoes all changes to the line, 2. regular expressions (enclosed in //, single  bind: ...... ???? Alt R searches incrementally up the history, slashes): for example /[a-z0-9_-]{3,16}/,  break: ...... ???? Ctrl R invokes an editor to write commands, 3. awk expressions, comparison operators (<, >,  builtin: ...... ???? Ctrl XE inserts the last argument of last <=, >=, ==, !=, tilde: matches, ! negates),  caller: ...... ???? Alt . command. 4. END for final actions.  cd: changes the shell working directory. - to the previous directory. 4 Text processing (grep, sed, awk) Awk is weakly typed: variables can be treated either  command: ...... ???? as numeric values or strings, which are not  compgen: ...... ???? is is an expanded description of three powerful represented as one-dimensional arrays of  complete: ...... ???? text processing tools: grep, sed and awk. characters! Important variables include:

2 1. FS: field separator (tab and space by default), 2. OFS: output field separator, 3. RS: record separator (new line), 4. NR: number of the current record, 5. NF: number of fields in the current record, 6. $0: the entire input record, 7. $1, $2, ...: fields in the current record. Available numerical functions: 1. int, 2. sqrt, exp, log, 3. sin, cos, atan2, 4. rand (uniformly distributed value from [0, 1)), srand (sets the seed (by default, time of day) for random number generator). String/text functions: 1. length returns number of characters. 2. split divides string into pieces separated by a separator. 3. sprintf returns string printed by printf (which is C-like function) without printing. 4. gsub searches for all of the longest, le tmost, nonoverlapping substrings and replaces them (globally). sub replaces only first match. 5. index searches for the first occurrence of a string. match accepts regexes too. 6. tolower, toupper convert case. find Tests: [→] -iname, -name (case insensitive) file name, [→] -path, -regex shell pattern or regular expr. [→] -group, -user ownership [→] -perm 755, -perm /u=x permissions [→] -size +5M -1G size between 5MB and 1GB [→] -amin, -cmin, -mmin accessed, created, modified in last...minutes (-atime, ...: days) [→] -type d (f) directories (files) only, [→] -empty empty files or directories only, Example (deletes files larger than 5 megabytes): [→] find / -size +5M -exec rm -f {} \; 4.4 Regular expressions 1. POSIX character classes: (a) [:lower:] = [a-z] (b) [:alpha:] = [a-zA-Z] (c) [:alnum:] = [a-zA-Z0-9] (d) [:word:] = [A-Za-z0-9_] (e) [:digit:] = [0-9] (f) [:xdigit:] = [A-Fa-f0-9] (g) [:blank:] = [ \t] (h) [:space:] = [ \t\r\n\v\f] (i) [:cntrl:] = [\x00-\x1F\x7F] (j) [:graph:] = [\x21-\x7E] (k) [:print:] = [\x20-\x7E] (l) [:ascii:] = [\x00-\x7F] 2. Repetitions: (a) *: 0 or more, +: 1 or more, ?: 0 or 1, (b) {a, b}: at least a, at most b. 3. Anchors: (a) ^: start of line, (b) $: end of line, (c) \<: start of word, (d) \>: end of word. 4. Other: (a) one|two: one or two, (b) (one): a group, (c) $n: nth group, (d) [abcd], [a-d]: ranges, (e) [^abcd]: negation (not [abcd]).

3 5 Unix utilities and shell builtins i always prompts, s prints sizes as well r removes directories and their contents. 5.1 File system Filename manipulation:  shred: overwrites repeatedly. Changing file attributes: Working with special file types:  basename prints path without parent chgrp changes group ownership: directory  mkdir makes directories: afects symlinks instead of referenced files,   dirname prints only parent directory h with parents as needed, chmod changes permissions of a file: p  pathchk: ...... ???  verbosely. of the owner, group, other or all users, v  realpath: ...... ??? ugoa rmdir removes empty directories. adds, removes or sets selected file mode bits,  +-= mktemp creates temporary files: ??? mount mounts a filesystem. selects file mode bits: read 4/write 2/execute  rwx creates directory instead. t indicates filesystem type (ext4, xfs, btrfs, ...) 1. d ln makes hard links between files: chown changes owner of a file:  ??? tar manipulates archives (“Tape ARchive”):  makes so t (symbolic) links instead. recursively (applies for chgrp, chmod, s f archive to manipulate, R unlink ...... ???? chown).  v verbosely lists files processed, readlink resolves canonical file names touch changes file timestamps:  c creates a new archive,  m by following every symlink recursively, a only the access time, r appends files to the end of an archive, f same and all but last part of path must exist, m only the modification time, t lists the contents of an archive, e same and all parts of path must exist. c creates no new files, x extracts files,  link ...... ???? r uses another file’s times as a reference, k doesn’t replace existing files when extracting,  mkfifo ...... ???? t uses custom stamp instead of current time. a guesses compression program from filename,  mknod ...... ???? j uses compression program bzip2, SELinux: Disk usage: J uses compression program xz, chcon: ...... ???? z uses compression program gzip,  df reports file system disk space usage: runcon: ...... ????  C changes directory before operations.  h prints size in powers of 1024, Summarizing files: i list inode information instead of block usage, 5.2 Processes limits listing to file systems of given type, wc: counts... t Modified command invocation:  limits listing to file systems not of given type, lines, x l prints file systems types.  chroot changes the root directory of the words, T w du estimates file space usage: calling process and their children. bytes,  c writes counts for all files, not just directories,  env ...... ???? characters, a m produces a grand total,  printenv ...... ???? characters in longest line. c L the depth at which summing should occur,  nice adjusts process priority. b2sum: ...... ???? d  prints sizes in human readable format,  nohup ...... ???? cksum: CRC checksums ...... ???? h  diplays only a total,  stdbuf ...... ???? md5sum: ...... ???? s  excludes files that match pattern from  timeout ...... ???? sha1sum: ...... ???? X  pattern. sha224sum: ...... ???? ??? at schedules commands to be executed once  stat displays file status: sha256sum: ...... ????  in the future, accepts times of many forms:  following links, sha384sum: ...... ???? L HH:MM, midnight, noon, now (time); today,  in terse form. sha512sum: ...... ???? t tomorrow or [CC]YY-MM-DD (date) or 2pm +  sync ...... ???? ??? shasum prints or checks SHA message  1 week (increment) to name few. truncate ...... ???? digests:  Bash bg resumes suspended jobs in the algorithm: 1/224/256/384/512/512224/512256, ??? file determines file type. a background. reads in binary mode, doesn’t prepend filenames to output (brief), b b Bash fg resumes suspended jobs in the foreground. verifies SHA sums read from a file. prints MIME, not human-readable types, c i Bash jobs lists the active jobs.  sum: ...... ???? k doesn’t stop at the first match (keep going). Process control: Basic operations: ??? find searches for files in a directory hierarchy. [???] See also: whereis. [???] See also: locate, cp copies files and directories: ??? kill terminates a process by PID, sends TERM:  whose database can be updated with 9 sends instead. b makes a backup of existing destination files, KILL updatedb. ??? killall kills processes by name. f removes existing destination files if needed, o only older than, float + unit (smhdwMy) i prompts before overwriting, ??? fsck checks and repairs a Linux filesystem: y only younger than, float + unit (smhdwMy) n does not overwrite existing files, a automatically repairs (without any question!), L always follows symlinks in “source”, A tries to check all filesystems in one run, ??? ps prints a snapshot of the current processes: P never follows symlinks in “source”, M skips mounted filesystems, e? selects all processes, p preserves timestamps, mode, ownership, R skips the root filesystem. f? does full-format listing, r copies directories recursively, t specifies the type(s) of filesystem to be m? shows threads (see also: H, -L, -T) l hard links files instead, checked, C? selects processes by command name, makes symbolic links instead, s Directory listing: p? selects processes by PID, t copies all “source” arguments into “directory”, u? selects processes by EUID or name. T treats “destination” as a normal file,  ls lists directory contents: Warning: aux (BSD) ≈ -eF (standard syntax). u copies only newer source files, a does not ignore entries starting with dot, ??? pstree displays a tree of processes. v explains what is being done. F appends indicator to entries, ??? pgrep, pkill, pwait look up, signal or wait for  dd converts and copies files (non-std syntax!): h prints human readable sizes, if= reads from a file, i prints the index number of each file, processes (based on name by default). of= writes to a file, l prints permissions, number of hard links, ??? time runs programs with timing statistics. bs= up to ... bytes at a time, owner, group, size, last-modified date as well, count= copies only ... input blocks. r reverses order while sorting, ??? vmstat monitors memory usage.  install: ...... ???? R lists subdirectories recursively, ??? top displays Linux processes.  tee duplicates pipe content: S sorts by file size (largest first), ??? See also: htop (Hisham top based on ncurses). a appends to the given files, does not overwrite, t sorts by modification time (newest first), 5.3 User environment i ignores interrupts.  pwd is also a Bash builtin.  mv moves (renames) files:  dir: ...... ??? Terminal handling: f does not prompt before overwriting,  vdir: ...... ???  tty prints terminal filename. Some cp options are allowed: b, i, n, t, T, u,  dircolors: ...... ???  stty changes/prints terminal settings. v. ??? tree lists tree-like contents of directories.  rm removes files or directories: d skips files ??? clear clears the terminal screen. f never prompts, L limits search depth ??? env runs programs in modified environment:

4 without parameters, prints environmental 1 skips lines unique to 1st file, d only prints duplicate lines, one for each variables. 2 skips lines unique to 2nd file, group, ??? exit terminates the calling process. 3 skips common lines. u skips duplicated lines, ??? finger looks up user information. ??? dif compares files line by line: f avoids comparing first ... fields, Bash history displays the history list. y outputs in two columns, s avoids comparing first ... characters, ??? mesg displays messages from other users. i ignores case diferences, w compares no more than ... characters. E ignores tab expansions, ??? passwd changes user password: ??? xargs builds and executes command lines: b ignores changes in amount of white space, d deletes (empties) an account’s password, 0 accepts null-terminated items, B ignores changes where lines are all blank, e expires an account’s password, I with custom argument placeholder ({}), w ignores trailing white space, n minimum days to change password, n with at most that many arguments per line, w ignores all white space. w warning days before password expire, r doesn’t run if stdin empty. maximum days a password remains valid. x Operating on fields: 5.5 Networking su ??? changes user ID or becomes superuser.  join merges two sorted files on a field: ??? curl transfers data to/from a server: ??? sudo executes a command as superuser: join on this field of file 1 (1st by default), 1 I fetches the headers only, as a diferent user. join on this field of file 2 (1st by default), u 2 i includes HTTP response headers, use custom input/output field separator. System context: t L redoes requests to relocated pages, paste merges lines of files.  o writes to a file, not stdin, arch: ...... ???? reuses characters from “list” instead of tabs,  d u specifies user name and password, hostid: ...... ???? interchanges rows and columns.  s x uses proxy, uptime: how long has system been running?  Replacing text: X specifies custom request method. s system up since: yyyy-mm-dd HH:MM:SS. ??? s tp is similar to tp but uses SSH.  hostname shows/sets the host name: ??? sed has been described earlier. ??? wget is a network downloader: displays the DNS domain name, d  tr translates/deletes characters A, R specifies lists of file sufixes or patterns (when i displays the network address. (find+replace): wildcard characters appear) to accept/reject, nproc prints number of processing units.  c uses complement of character set, b goes to background immediately, uname prints system information:  d deletes characters, does not translate, c continues getting a partially-downloaded file, equivalent to: (kernel name), (network a s n s squeezes repeated character occurrences. m turns on mirroring options: infinite recursion node hostname), rv (kernel release and  expand: ...... ???? and time-stamping, version), (machine hardware name), m p  unexpand: ...... ???? np disallows ascension to parent directories, (processor type), (hardware platform), i o U identifies as a diferent agent to the server. (operating system). Output of parts of files: w waits specified number of seconds between ??? wall sends a message to all users, ??? cut prints selected parts of lines: the retrievals (check: –random-wait too). ??? write sends a message to another user. c selects (positional) range of characters, ??? rlogin starts an unencrypted terminal session f selects range of fields, on a remote host. User information: d using custom field delimeter, ??? ssh executes commands remotely: s skips lines without delimeters. requests compression of all data,  whoami prints efective userid. C ??? head outputs the first part of files: uses custom key for authentication,  logname prints user’s login name. i c first ... bytes, selects a port to connect to on the remote  pinky prints user information. p who shows who is logged on, n first ... lines, host,  with headers giving file names. a more data, same as bdprtTu + login. v X enables X11 forwarding. ??? w does the same, shows what they are doing, ??? tail outputs the last part of files: f output appended data as the file grows, ??? ping tests reachability of a network host:  users: ...... ???? n ... (a number) last ... lines, c stops a ter sending ... packets,  groups: ...... ??? n +... (a number) starting with line ..., n no DNS name resolution.  id: ...... ??? -c , v work like for head. ??? route shows and manipulates the IP routing table. 5.4 Text processing  split splits files into chunks: Printing text: a with custom filename sufix length (default: ??? rsync copies (remote or local) files fast: 2), a in archive mode, equivalent to: echo is also a Bash builtin.  b with custom number of bytes per chunk, g preserves group, printf is also a Bash builtin.  l with custom number of lines per chunk, o preserves owner (super-user only) yes outputs a string repeatedly until killed.  d uses numeric (not alphabetic) sufixes, p preserves permissions, Output of entire files: n generates custom amount of chunks. t preserves modification times,  csplit: ...... ???? l copies symlinks as symlinks,  cat concatenates and prints files: Reordering lines: b make backups, A shows all nonprinting characters, c skip based on checksum, n numbers all output lines (compare with nl!),  shuf generates random permutations: n performs a dry run without changes made, s suppresses repeated empty output lines. e treats arguemnts as input lines, r resursively,  tac reverses order of input lines. i uses range of numbers as input, u skip newer files on the receiver, ??? rev reverses order of characters in each line. n limits number of output lines, v increases verbosity, ??? less enhances (primitive) more pager: r repeats (with -n) some of the output lines. z compresses file data during the transfer, +F monitors the tail of a file which is growing.  sort sorts lines of text files: ??? scp copies files securely (with SSH).  nl numbers lines of files: r reverses output order, s adds “string” a ter line number, u outputs only first occurrence of duplicates, 5.6 Hardware w uses “number” columns for line numbers. n like numbers, ??? dmesg prints/controls the kernel ring bufer.  base32 encodes data: g like numbers in scientific notation, ??? lsblk lists block devices. w characters per line – 0 disables wrapping, h like file sizes (1K, 2M, 3G, ..., 8Y), ??? lsof lists info about files opened by processes. d decodes data instead. V like Debian package names + versions ? fuser lists PIDs that use given files/sockets.  base64 works similarly. b ignoring leading blanks, ??? lsusb lists USB devices.  od dumps files in octal. ignoring upper/lower case, f 5.7 Miscellaneous Formatting: c does not sort, checks for sorted input, k via part between two fields, not whole line ??? bc is an arbitrary precision calculator  fmt: ...... ???? s stably – no more comparisons in case of ties language.  pr: ...... ???? t using custom field separator, 1. echo ’obase=16;255’ | bc prints FF,  fold: ...... ????  tsort performs topological sort. 2. echo ’ibase=2;obase=A;10’ | bc uniq omits repeated lines: prints , Comparing file content:  2 c prefixes lines by the number of occurences, 3. scale=10 (a ter bc -l) sets working  comm compares two sorted files line by line: i ignores diferences in case, precision.

5 ??? dc is a reverse-polish desk calculator. One of the oldest Unix utilities, predating even the invention of the C programming language.  ptx produces permuted index of file contents. Date/time operations:

 date prints/sets system date and time: d displays time described by ..., not now, s sets the date instead.  sleep pauses for ... seconds. ??? cal, displays a calendar for current month: j displays Julian days, w prints the numbers of the weeks, y displays a calendar for a whole year, 3 displays the previous, current and next month. Numeric operations:

 factor ...... ????  numfmt ...... ????  seq prints a sequence of numbers: w equalizes width by padding with leading zeroes. Conditionals:

 false does nothing unsuccessfully.  true does nothing successfully.  test ...... ???  expr ...... ???

6