# Guide to Unix/Commands/Miscellaneous

| Wikibooks Guide to Unix Computing | Edit template |
   General: Introduction | Explanations | Why Unix-like Platforms: Linux | BSD Quick Reference: Commands | Environment Variables | Files | License
   Commands: Getting Help | File System Utilities | Finding Files | Devices | File Viewing | File Editing | Text Processing | File Compression | File Analysing | Multiuser Commands | Self Information | System Information | Process Management | Kernel Commands | Miscellaneous | SW Development |

### sync

sync write memory buffers to disk
Example: Sync has no options, doesn't display any messages
Tips:
It is always good to type sync a couple of times, one the important functions of sync is to update your superblock information.
The sync calls sync Unix system call and exits with success code '0' or '1' if it fails. These exit codes stored in $? variable.
The above example shows that sync was successful.
Links:
* sync, freebsd.org
* sync, manpages.ubuntu.com
* 14.4 sync in GNU Coreutils manual, gnu.org

### echo

echo outputs its parameters to the standard output.
Examples:
Tips: Some common echo usage:
Check a shell variable:
Check the parameters passed in the previous command:
Check the current parent process:
Check the exit code of the last command:
Create a empty file (same as touch /tmp/newfile):
Create a new file with some text:
Add (append) a new line to end of file:
Links:
* echo, opengroup.org
* echo man page, man.cat-v.org
* 15.1 echo in GNU Coreutils manual, gnu.org

### printf

Produces formatted output, richer than echo.
Examples:
* printf Hello world
** Outputs Hello world, with no final newline.
* printf "Hello "; printf "world"
** As above, with no newline to separate Hello and world.
* printf "Hello world\n"
** Outputs Hello world, with a final newline via \n.
* printf "Hello\tworld"
** Outputs Hello, then tab character, then world. Other escape sequences supported include \\, \n, \r, and more.
* printf "Hello\011world"
** As above: 011 is the octal number of the tab character.
* printf "%0x" 255
** Outputs ff, that is, 255 converted to hex.
* printf "%s %0x" Hex: 255
** Takes "Hex:" as the 1st argument to be formatted using %s and 255 to be the 2nd argument to be formatted using %0x.
* printf "%s\n" 1 2 3 4 5
** Outputs the integers 1,..., 5, one integer per line. Thus, feeds the 2nd to last argument into the format string as if in a loop.
* printf "%s-%s\n" 1 2 3 4 5 6
** Outputs lines containing 1-2, 3-4, and 5-6. Thus, repeatedly lets the format string consume as many arguments as it needs.
* printf "%s-%s-%s\n" 1 2 3 4
** Outputs lines containing 1-2-3 and 4--. Thus, the arguments missing to provide complete triplets are treated as empty.
* printf "%i-%i-%i\n" 1 2 3 4
** Outputs lines containing 1-2-3 and 4-0-0. Thus, the arguments missing to provide complete triplets are treated as zeros.
* printf "%o" 255
** Outputs 377, octal of 255.
* printf "%X" 255
** Outputs FF, hex of 255 with capital letters.
Links:
* printf, opengroup.org
* printf, freebsd.org
* 15.2 printf in GNU Coreutils manual, gnu.org

### cal

Outputs a calendar, per default for the current month. If followed by a year, outputs calendar for that year; if followed by a month and a year, outputs a calendar for that period. POSIX supports no options: all options are extensions. The options of linux-util cal, GNU gcal and FreeBSD cal are generally incompatible.
Introductory examples, covered by POSIX:
More examples for POSIX cal:
* cal 2004
** Outputs a calendar for the whole year 2004.
Examples for util-linux cal:
* cal Mar 2000
** Outputs March of year 2000.
* cal -3
** Outputs current, previous and next month.
* cal -3 04 2004
** Outputs April 2004, as well as the previous (March) and following (May) month. Works in util-linux and FreeBSD.
* cal -1
** Outputs the current month, default per POSIX.
* cal -n 2 06 2020
** Outputs the calendar for June (06) and July, thus, for 2 months starting with the month entered.
* cal -j
** Outputs this months calendar with day-of-year number (counted from January 1st) rather than the date
* cal -w
** Outputs week number in addition to the daily calendar.
Examples for GNU gcal:
* gcal
** Outputs current month.
* gcal .
** Outputs current, previous and next month.
* gcal Jan
** Outputs current January.
* gcal Jan-Mar
** Outputs current January through March.
* gcal Jan 2000
** Outputs the January of 2000.
* gcal -K
** Outputs week number in addition to the daily calendar.
Tips: The Gregorian Calendar was adopted in the British Empire in 1752. The 2nd day of September 1752 was immediately followed by the 14th day of September:
Links:
* cal, opengroup.org
* cal man page, man.cat-v.org
* cal, freebsd.org
* cal in util-linux, man7.org
* GNU gcal manual, gnu.org
* cal (command), wikipedia.org
* cal.c in util-linux, github.com
* gcal.git, git.savannah.gnu.org
* ncal.c in freebsd-src, github.com

### date

date displays the current date and time.
Example:
Links:
* date, opengroup.org
* date man page, man.cat-v.org
* 21.1 date in GNU Coreutils manual, gnu.org

### time

time time a program
Example:
Links:
* time, opengroup.org
* time man page, man.cat-v.org

### from

from display the names of those who sent you mail recently
Example:
Count the number of mail in your mailbox
Links:
* from, freebsd.org
* 2.3 frm and from in GNU Mailutils Manual, gnu.org

### mail

mail allows you to read and write emails.
Example:
Tips: Note that you need to press enter then ctrl+d to confirm.
Tips: Press enter to read.
Links:
* mail man page, man.cat-v.org
* 2.4 mail in GNU Mailutils Manual, gnu.org

### clear

Clears the screen of the terminal. Takes no arguments. Keywords: cls.
Links:
* clear man page, man.cat-v.org

### seq

Outputs sequences of numbers, even floating point numbers. Seems not covered by POSIX.
Examples:
* seq 10
** Outputs integers 1 to 10, one per line.
* seq 2 10
** Outputs integers 2 to 10.
* seq 3 2 10
** Outputs integers 3 to 10 with step 2, and therefore, 3, 5, 7, and 9.
* seq -5 5
** Outputs integers -5 to 5
* seq 0.5 0.1 1
** Outputs numbers 0.5 to 1 with step 0.1: 0.5, 0.6, 0.7, 0.8, and 0.9 (why not 1?). The decimal point vs. comma of the output seems to be locale specific.
* seq 1E3
** Outputs integers 1 to 1000, using the exponential notation.
Links:
* seq man page, man.cat-v.org
* 26.3 seq: Print numeric sequences in GNU Coreutils manual, gnu.org
* W:seq (Unix)

### shuf

Randomly shuffles file or input lines. Not covered by POSIX.
Examples:
* seq 10 | shuf
** Outputs numbers from 1 to 10 randomly shuffled, one item per line.
* shuf -e a b c
** Randomly shuffles the a, b and c items, outputting one item per line.
* shuf -i 1-10
** Outputs numbers from 1 to 10 randomly shuffled, one item per line.
Links:
* 7.2 shuf: Shuffling text in GNU Coreutils manual, gnu.org
* shuf, man7.org
* shuf, freebsd.org
* shuf, wikipedia.org

### tee

Writes the input stream into a file while at the same time passing it to standard output.
Examples:
* dir | tee dirout.txt | less
Links:
* tee, opengroup.org
* tee man page, man.cat-v.org
* 17.1 tee: Redirect output to multiple files or processes in GNU Coreutils manual, gnu.org
* W:tee (Unix)

### sleep

Pauses for a period of time.
Examples:
* sleep 5
** Pauses for 5 seconds.
* sleep 10800
** Pauses for 3 hours: for 3 * 60 * 60 seconds.
* sleep 1m
** In GNU sleep, pauses for 1 minute.
* sleep 1h
** In GNU sleep, pauses for 1 hour.
* sleep 1d
** In GNU sleep, pauses for 1 day.
* sleep 0.5m
** In GNU sleep, pauses for half a minute.
* sleep 1m 30s
** In GNU sleep, pauses for 1 minute and 30 seconds.
Links:
* sleep, opengroup.org
* sleep man page, man.cat-v.org
* sleep, freebsd.org
* 25.1 sleep in GNU Coreutils manual, gnu.org

### yes

Outputs an indefinite stream of newline-separated strings "y", or other strings as specified. One of the uses is feeding the output into a command that requires user confirmation.
Examples:
* yes
** Outputs a stream of repeated "y" strings, separated by newline.
* yes hey
** Outputs a stream of repeated "hey" strings, separated by newline.
Links:
* yes, freebsd.org
* yes Linux man page, man7.org
* 15.3 yes in GNU Coreutils manual, gnu.org
* yes (Unix), wikipedia.org

### true

Does nothing and finishes with zero exit code, indicating success.
Links:
* true, opengroup.org
* true man page, man.cat-v.org
* true, freebsd.org
* 16.2 true in GNU Coreutils manual, gnu.org

### false

Does nothing and finishes with non-zero exit code (often 1), indicating failure.
Links:
* false, opengroup.org
* true man page, man.cat-v.org: covers both true and false
* false, freebsd.org
* 16.1 false in GNU Coreutils manual, gnu.org

### env

Sets the environment for a command or outputs all environment variables. See also Environment Variables.
Examples:
* env
** Outputs all environment variables.
* env printf Hello
** Ensures command printf is called rather than the possible shell builtin.
Links:
* env, opengroup.org
* env, man7.org
* env, freebsd.org
* env, wikipedia.org

### printenv

Outputs values of one or more environment variables or all variables if none are passed. Not covered by POSIX. Alternatives are #env to output all variables and "echo $HOME" to output a single variable, here HOME. See also Environment Variables.
Examples:
* printenv HOME
* printenv HOME USER
* printenv
** Outputs all variables.
Links:
* printenv, man.cat-v.org
* printenv, freebsd.org
* 19.3 printenv in GNU Coreutils manual, gnu.org
* Environment variable, wikipedia.org