2chars

ac
Print statistics on how long users have been connected

More information: https://www.gnu.org/software/acct/manual/accounting.html#ac.

- Print how long the current user has been connected in hours: ac

- Print how long users have been connected in hours: ac --individual-totals

- Print how long a particular user has been connected in hours: ac --individual-totals username

- Print how long a particular user has been connected in hours per day (with total): ac --daily-totals --individual-totals username

- Also display additional details: ac --compatibility

ar
Create, modify, and extract from archives (.a, .so, .o)

More information: https://manned.org/ar.

- Extract all members from an archive: ar -x path/to/file.a

- List the members of an archive: ar -t path/to/file.a

- Replace or add files to an archive: ar -r path/to/file.a path/to/file1.o path/to/file2.o

- Insert an object file index (equivalent to using ranlib): ar -s path/to/file.a

- Create an archive with files and an accompanying object file index: ar -rs path/to/file.a path/to/file1.o path/to/file2.o

bc
An arbitrary precision calculator language

More information: https://manned.org/bc.

- Start bc in interactive mode using the standard math library: bc -l

- Calculate the result of an expression: bc <<< "(1 + 2) * 2 ^ 2"

- Calculate the result of an expression and force the number of decimal places to 10: bc <<< "scale=10; 5 / 3"

- Calculate the result of an expression with sine and cosine using mathlib: bc -l <<< "s(1) + c(1)"

cp
Copy files and directories

More information: https://www.gnu.org/software/coreutils/cp.

- Copy a file to another location: cp path/to/source_file.ext path/to/target_file.ext

- Copy a file into another directory, keeping the filename: cp path/to/source_file.ext path/to/target_parent_directory

- Recursively copy a directory's contents to another location (if the destination exists, the directory is copied inside it): cp -R path/to/source_directory path/to/target_directory

- Copy a directory recursively, in verbose mode (shows files as they are copied): cp -vR path/to/source_directory path/to/target_directory

- Copy text files to another location, in interactive mode (prompts user before overwriting): cp -i *.txt path/to/target_directory

- Follow symbolic links before copying: cp -L link path/to/target_directory

dc
An arbitrary precision calculator. Uses reverse polish notation (RPN)

More information: https://www.gnu.org/software/bc/manual/dc-1.05/html_mono/dc.html.

- Run calculator in interactive mode: dc

- Execute dc script in file: dc -f file

- Calculate 4 times 5 [4 5 *], subtract 17 [17 -], and [p]rint the output (using echo): echo "4 5 * 17 - p"| dc

- Set number of decimal places to 7 [7 k], calculate 5 divided by -3 [5 _3 /] and [p]rint (using dc -e): dc -e "7 k 5 _3 / p"

- Calculate the golden ratio, phi: Set number of decimal places to 100 [100 k], square root of 5 [5 v] plus 1 [1 +], divided by 2 [2 /], and [p]rint result: dc -e "100 k 5 v 1 + 2 / p"

dd
Convert and copy a file

More information: https://www.gnu.org/software/coreutils/dd.

- Make a bootable USB drive from an isohybrid file (such like archlinux-xxx.iso) and show the progress: dd if=file.iso of=/dev/usb_drive status=progress

- Clone a drive to another drive with 4 MiB block, ignore error and show progress: dd if=/dev/source_drive of=/dev/dest_drive bs=4M conv=noerror status=progress

- Generate a file of 100 random bytes by using kernel random driver: dd if=/dev/urandom of=random_file bs=100 count=1

- Benchmark the write performance of a disk: dd if=/dev/zero of=file_1GB bs=1024 count=1000000

- Generate a system backup into an IMG file and show the progress: dd if=/dev/drive_device of=path/to/file.img status=progress

- Restore a drive from an IMG file and show the progress: dd if=path/to/file.img of=/dev/drive_device status=progress

- Check progress of an ongoing dd operation (Run this command from another shell): kill -USR1 $(pgrep ^dd)

df
Gives an overview of the filesystem disk space usage

More information: https://www.gnu.org/software/coreutils/df.

- Display all filesystems and their disk usage: df

- Display all filesystems and their disk usage in human-readable form: df -h

- Display the filesystem and its disk usage containing the given file or directory: df path/to/file_or_directory

- Display statistics on the number of free inodes: df -i

- Display filesystems but exclude the specified types: df -x squashfs -x tmpfs

du
Disk usage: estimate and summarize file and directory space usage

More information: https://www.gnu.org/software/coreutils/du.

- List the sizes of a directory and any subdirectories, in the given unit (B/KB/MB): du -b|k|m path/to/directory

- List the sizes of a directory and any subdirectories, in human-readable form (i.e. auto-selecting the appropriate unit for each size): du -h path/to/directory

- Show the size of a single directory, in human-readable units: du -sh path/to/directory

- List the human-readable sizes of a directory and of all the files and directories within it: du -ah path/to/directory

- List the human-readable sizes of a directory and any subdirectories, up to N levels deep: du -h --max-depth=N path/to/directory

- List the human-readable size of all .jpg files in subdirectories of the current directory, and show a cumulative total at the end: du -ch */*.jpg

ed
The original Unix text editor

More information: https://man.archlinux.org/man/ed.1.

- Start ed, editing an empty document (which can be saved as a new file in the current directory): ed

- Start ed, editing an empty document, with : as a command prompt indicator: ed -p :

- Start ed editing an existing file (this shows the byte count of the loaded file): ed -p : path/to/file

- Toggle the printing of error explanations. (By default, explanations are not printed and only a ? appears): H

- Add text to the current document. Mark completion by entering a period by itself in a new line: atext_to_insert.

- Print the entire document (, is a shortcut to the range 1,$ which covers the start to the end of the document): ,p

- Write the current document to a new file (the filename can be omitted if ed was called with an existing file): w filename

- Quit ed: q

fc
Open the most recent command and edit it

More information: https://manned.org/fc.

- Open in the default system editor: fc

- Specify an editor to open with: fc -e 'emacs'

- List recent commands from history: fc -l

fd
An alternative to find.Aims to be faster and easier to use than find

More information: https://github.com/sharkdp/fd.

- Recursively find files matching the given pattern in the current directory: fd pattern

- Find files that begin with "foo": fd '^foo'

- Find files with a specific extension: fd --extension txt

- Find files in a specific directory: fd pattern path/to/directory

- Include ignored and hidden files in the search: fd --hidden --no-ignore pattern

- Execute a command on each search result returned: fd pattern --exec command

fg
Run jobs in foreground

More information: https://manned.org/fg.

- Bring most recently suspended background job to foreground: fg

- Bring a specific job to foreground: fg %job_id

gs
GhostScript is a PDF and PostScript interpreter

More information: https://manned.org/gs.

- To view a file: gs -dQUIET -dBATCH file.pdf

- Reduce PDF file size to 150 dpi images for reading on a e-book device: gs -dNOPAUSE -dQUIET -dBATCH -sDEVICE=pdfwrite -dPDFSETTINGS=/ebook -sOutputFile=output.pdf input.pdf

- Convert PDF file (pages 1 through 3) to an image with 150 dpi resolution: gs -dQUIET -dBATCH -dNOPAUSE -sDEVICE=jpeg -r150 -dFirstPage=1 -dLastPage=3 -sOutputFile=output_%d.jpg input.pdf

- Extract pages from a PDF file: gs -dQUIET -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=output.pdf input.pdf

- Merge PDF files: gs -dQUIET -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=output.pdf input1.pdf input2.pdf

- Convert from PostScript file to PDF file: gs -dQUIET -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=output.pdf input.ps

hr
Print a horizontal rule in the terminal

More information: https://github.com/LuRsT/hr.

- Print a horizontal rule: hr

- Print a horizontal rule with a custom string: hr string

- Print a multiline horizontal rule: hr string_a string_b string_c

id
Display current user and group identity

More information: https://www.gnu.org/software/coreutils/id.

- Display current user's ID (UID), group ID (GID) and groups to which they belong: id

- Display the current user identity as a number: id -u

- Display the current group identity as a number: id -g

- Display an arbitrary user's ID (UID), group ID (GID) and groups to which they belong: id username

if
Simple shell conditional.See also: test, [

More information: https://www.tcl.tk/man/tcl8.6.11/TclCmd/if.html.

- Execute two different commands based on a condition: if command; then echo "true"; else echo "false"; fi

- Check if a variable is defined: if -n "$VARIABLE" ; then echo "defined"; else echo "not defined"; fi

- Check if a file exists: if -f "path/to/file" ; then echo "true"; else echo "false"; fi

- Check if a directory exists: if -d "path/to/directory" ; then echo "true"; else echo "false"; fi

- Check if a file or directory exists: if -e "path/to/file_or_directory" ; then echo "true"; else echo "false"; fi

- List all possible conditions (test is an alias to [; both are commonly used with if): man [

lp
Print files.

- Print the output of a command to the default printer (see lpstat command): echo "test" | lp

- Print a file to the default printer: lp path/to/filename

- Print a file to a named printer (see lpstat command): lp -d printer_name path/to/filename

- Print N copies of file to default printer (replace N with desired number of copies): lp -n N path/to/filename

- Print only certain pages to the default printer (print pages 1, 3-5, and 16): lp -P 1,3-5,16 path/to/filename

- Resume printing a job: lp -i job_id -H resume

ls
List directory contents

More information: https://www.gnu.org/software/coreutils/ls.

- List files one per line: ls -1

- List all files, including hidden files: ls -a

- List all files, with trailing / added to directory names: ls -F

- Long format list (permissions, ownership, size, and modification date) of all files: ls -la

- Long format list with size displayed using human-readable units (KiB, MiB, GiB): ls -lh

- Long format list sorted by size (descending): ls -lS

- Long format list of all files, sorted by modification date (oldest first): ls -ltr

- Only list directories: ls -d */

mc
Midnight Commander, a terminal based file manager.Navigate the directory structure using the arrow keys, the mouse or by typing the commands into the terminal

More information: https://midnight-commander.org.

- Start mc: mc

- Start mc in black and white: mc -b

mv
Move or rename files and directories

More information: https://www.gnu.org/software/coreutils/mv.

- Move a file to an arbitrary location: mv source target

- Move files into another directory, keeping the filenames: mv source1 source2 source3 target_directory

- Do not prompt for confirmation before overwriting existing files: mv -f source target

- Prompt for confirmation before overwriting existing files, regardless of file permissions: mv -i source target

- Do not overwrite existing files at the target: mv -n source target

- Move files in verbose mode, showing files after they are moved: mv -v source target

nl
A utility for numbering lines, either from a file, or from standard input

More information: https://www.gnu.org/software/coreutils/nl.

- Number non-blank lines in a file: nl file

- Read from standard output: cat file | nl options -

- Number only the lines with printable text: nl -t file

- Number all lines including blank lines: nl -b a file

- Number only the body lines that match a basic regular expression (BRE) pattern: nl -b p'FooBar[0-9]' file

od
Display file contents in octal, decimal or hexadecimal format.Optionally display the byte offsets and/or printable representation for each line

More information: https://www.gnu.org/software/coreutils/od.

- Display file using default settings: octal format, 8 bytes per line, byte offsets in octal, and duplicate lines replaced with *: od path/to/file

- Display file in verbose mode, i.e. without replacing duplicate lines with *: od -v path/to/file

- Display file in hexadecimal format (2-byte units), with byte offsets in decimal format: od --format=x --address-radix=d -v path/to/file

- Display file in hexadecimal format (1-byte units), and 4 bytes per line: od --format=x1 --width=4 -v path/to/file

- Display file in hexadecimal format along with its character representation, and do not print byte offsets: od --format=xz --address-radix=n -v path/to/file

- Read only 100 bytes of a file starting from the 500th byte: od --read-bytes 100 --skip-bytes=500 -v path/to/file

pi
Compute decimal Archimedes' constant Pi on the command-line

More information: http://manpages.ubuntu.com/manpages/trusty/man1/pi.1.html.

- Display 100 decimal digits of Archimedes' constant Pi: pi

- Display a specified number of decimal digits of Archimedes' constant Pi: pi number

- Display help: pi --help

- Display version: pi --version

- Display recommended readings: pi --bibliography

pr
Paginate or columnate files for printing

More information: https://www.gnu.org/software/coreutils/pr.

- Print multiple files with a default header and footer: pr file1 file2 file3

- Print with a custom centered header: pr -h "header" file1 file2 file3

- Print with numbered lines and a custom date format: pr -n -D "format" file1 file2 file3

- Print all files together, one in each column, without a header or footer: pr -m -T file1 file2 file3

- Print, beginning at page 2 up to page 5, with a given page length (including header and footer): pr +2:5 -l page_length file1 file2 file3

- Print with an offset for each line and a truncating custom page width: pr -o offset -W width file1 file2 file3

ps
Information about running processes.

- List all running processes: ps aux

- List all running processes including the full command string: ps auxww

- Search for a process that matches a string: ps aux | grep string

- List all processes of the current user in extra full format: ps --user $(id -u) -F

- List all processes of the current user as a tree: ps --user $(id -u) f

- Get the parent PID of a process: ps -o ppid= -p pid

- Sort processes by memory consumption: ps --sort size

rm
Remove files or directories

More information: https://www.gnu.org/software/coreutils/rm.

- Remove files from arbitrary locations: rm path/to/file path/to/another/file

- Recursively remove a directory and all its subdirectories: rm -r path/to/directory

- Forcibly remove a directory, without prompting for confirmation or showing error messages: rm -rf path/to/directory

- Interactively remove multiple files, with a prompt before every removal: rm -i file(s)

- Remove files in verbose mode, printing a message for each removed file: rm -v path/to/directory/*

su
Switch shell to another user.

- Switch to superuser (requires the root password): su

- Switch to a given user (requires the user's password): su username

- Switch to a given user and simulate a full login shell: su - username

- Execute a command as another user: su - username -c "command"

tr
Translate characters: run replacements based on single characters and character sets

More information: https://www.gnu.org/software/coreutils/tr.

- Replace all occurrences of a character in a file, and print the result: tr find_character replace_character < filename

- Replace all occurrences of a character from another command's output: echo text | tr find_character replace_character

- Map each character of the first set to the corresponding character of the second set: tr 'abcd' 'jkmn' < filename

- Delete all occurrences of the specified set of characters from the input: tr -d 'input_characters' < filename

- Compress a series of identical characters to a single character: tr -s 'input_characters' < filename

- Translate the contents of a file to upper-case: tr "[:lower:]" "[:upper:]" < filename

- Strip out non-printable characters from a file: tr -cd "[:print:]" < filename

ul
Performs the underlining of a text.Each character in a given string must be underlined separately

More information: https://manned.org/ul.

- Display the contents of the file with underlines where applicable: ul file.txt

- Display the contents of the file with underlines made of dashes -: ul -i file.txt

wc
Count lines, words, or bytes

More information: https://www.gnu.org/software/coreutils/wc.

- Count lines in file: wc -l file

- Count words in file: wc -w file

- Count characters (bytes) in file: wc -c file

- Count characters in file (taking multi-byte character sets into account): wc -m file

- Use standard input to count lines, words and characters (bytes) in that order: find. | wc