halt, reboot, poweroff

Deprecated

allow a system administrator to halt, reboot or poweroff the system.

/sbin/halt [options]

/sbin/reboot [options]

/sbin/poweroff [options]

Actually, halt and poweroff are symlinks to reboot. When --force is specified, or when runlevel is 0 or 6, then reboot system call directly reboots the system. Otherwise shutdown is executed.

Options

--help    --version    -v    --verbose

-f, --force

don't call shutdown, perform the actual action corresponding to the invocation name;

-n, --no-sync

don't sync disks before reboot or halt;

-p, --poweroff

force halt to behave as poweroff;

-q, --quiet

reduce output to errors only;

-w, --wtmp-only

write shutdown rec in /var/log/wtmp, but do not perform actual shutdown or reboot system call;

hddtemp

This is a utility to monitor HDD (hard disk drive) temperature. In fact, it works with SSDs too, at least with those using SATA interface. Technically, hddtemp uses S.M.A.R.T. (Self-Monitoring Analysis and Reporting Technology) and can only get info from HDD/SSD supporting this feature and equipped with a temperature sensor (practically all modern drives).

hddtemp [options] [type:]disk

sudo hddtemp /dev/sda

sudo hddtemp /dev/sda /dev/sdb

sudo hddtemp /dev/hda

sudo hddtemp PATA:/dev/hda

sudo hddtemp SCSI:/dev/sdc

Usually there is no need to specify type which can be PATA, SATA, or SCSI. But sometimes detection fails.

However, it does not fail (even without type spec) when I insert my USB Flash drive (JetFlashTranscend), and get a report that "drive supported, but it doesn't have a temperature sensor". Interesting. I didn't know that USB flash drives can have S.M.A.R.T.

You can also run hddtemp as a daemon providing permanent temperature monitoring.

head

prints the first 10 (unless other value is explicitly given) lines of the specified file(s) to stdout.

head msgs.txt

print the first 10 lines of msgs.txt;

head -25 file2.txt

print the first 25 lines of file2.txt;

head -n 25 file2.txt

print the first 25 lines ...;

head -n -25 file2.txt

print the whole file except the last 25 lines;

head -c 2k misc.dat

print the first 2K bytes of misc.dat;

head [options] [file] ...

Options

--help    --version    -v    --verbose

-c n, --bytes=n

print the first n bytes of a file;

-c -n, --bytes=-n

print all but the last n bytes of a file;

-n n, --lines=n

print the first n lines of a file;

-n -n, --lines=-n

print all but the last n lines of a file;

-q, --quiet

never print headers giving file names;

hexdump

is a filter that displays the specified files (or data coming from stdin) in a specified format (ASCII, decimal, hexadecimal, octal).

hexdump [options] file ...

For each input file, ~ sequentially transforms the data according to the format strings and in the order they were specified. The result is sent to stdout. ~ returns 0 on success, and positive number on error.

hexdump -C -n 1024 logo.gif

display the first 1K bytes of logo.gif in hex+ASCII format;

Options
-b one-byte octal display;
-c one-byte character display;
-C canonical hex+ASCII display;
-d two-byte decimal display;

-e format_str

specifies a format string to be used for displaying data (see online man for details);

-f format_file

specifies a file that contains one or more format strings separated by newlines;

-n m interpret only m bytes of input;
-o two-byte octal display;
-s n skip n bytes from the beginning of the input;
-v causes ~ to display all input data; otherwise, any num of groups of output lines, which would be identical to the immediately preceding grp of output lines (except for the input offsets), are replaced with a line comprised of a single asterisk;
-x two-byte hexadecimal display;

history

The GNU history cmd keeps a list of all cmds that have been run from that terminal session and allows you to repeat/replay those cmds without typing them again. The history list is displayed with the line numbers. The modified entries are prefixed with a *.

To list all cmds that you used since the start of this terminal session:

history

To exec [again] some cmd from the list you only need its line number:

!25

Of course, you can use Ctrl + P and Ctrl + N, but this is only convenient for the nearest cmds.

To see the last 10 cmds from the history:

history 10

You can use grep to find some specific cmd, e.g.

history | grep iptables

If, for example, you entered [whatever the reason] a plaintext password on the cmdline, you definitely should remove this entry from history list as quickly as possible. Get the number of the entry and delete it:

history -d 214

Of course, you can delete (clear) the whole history, but isn't that too much?

history -c

The syntax in general:

history --help

history [n]

history [-c] [-d offset]

history -anrw [filename]

history -ps arg [arg...]

If filename is given, it is used as the history file. But usually the history file name is set by HISTFILE env var, and the default is ~/.bash_history (hidden file in the home dir).

The size of the history list is set by HISTSIZE env var. It works like FIFO: when the list is full, top/first lines disappear as you exec new cmds.

Options
-a append history lines from this session to the history file;
-c clear the history list by deleting all entries;
-d n delete the history entry at position n; negative value means count back from the end of the history list;
-n read all history lines not already read from the history file and append them to the history list;
-p perform history expansion on each ARG and display the result without storing it in the history list;
-r read the history file and append the contents to the history list;
-s append the ARGs to the history list as a single entry;
-w write the current history to the history file;

host

is a simple DNS lookup utility. It is used mainly to convert names to IP addresses and vice versa.

host [options] name [server]

name is either the domain name or IPv4/IPv6 address of a host to be resolved. server is an IP address of an optional name server to be used instead of those listed in /etc/resolv.conf.

host srv5.acme.net

what IP address has srv5.acme.net?

host 212.87.37.250

what’s the name of the host with IP = 212.87.37.250?

host -t MX acme.net

what servers handle mail for acme.net domain?

host -t SOA local

display SOA records for the domain .local;

Options
-v verbose;
-4 use IPv4 query transport only;
-6 use IPv6 query transport only;
-a set verbose mode and make a query of type ANY;
-C attempt to display the SOA records for zone name from all the listed authoritative name servers for that zone;

-c cls

make a query of the specified class (default is IN);

-d same as -v (verbose);
-i specifies that reverse lookups of IPv6 addresses should use IP6.INT domain (default is IP6.ARPA);
-l list all hosts in domain using AXFR (obsolete; use -t AXFR instead; means: perform zone transfer for zone name);
-N n set the number of dots that have to be in name for it to be considered absolute (default is 1);
-R n retry query n times (default is 1);
-r use non-recursive queries;
-s don't send query to the next name server if any server responds with a SERVFAIL;
-T query name server using TCP (default is UDP);

-t type

select the query type (CNAME, NS, MX, SOA, etc);

-W n wait n seconds for a reply (1 is minimum);
-w wait forever for a reply;

hostname

displays or sets system's hostname. To set a new hostname you need root priv, and this name is only valid until next reboot. To make it permanent, edit config file (name/location depends on distro, see Files below). dnsdomainname displays the system's DNS name (it cannot be changed locally). There are also domainname, ypdomainname, nisdomainname that can be used to show/set system's NIS/YP domain name.

hostname

show full name of this computer;

hostname -s

show short name of this computer;

hostname -a

show the alias names of this computer;

hostname -f

show the host’s fully qualified domain name;

dnsdomainname

show the DNS domain name of this host;

hostname ws4

set the host name of this computer to ws4 (root only);

hostname -i -v

show IP addresses of this host and give some explanations;

hostname [options] [hostname]

domainname [options] [name]

dnsdomainname [options]

nisdomainname [options]

ypdomainname [options]

Options

-h    --help    -V    --version    -v    --verbose

-A, --all-fqdns

show all FQDNs of the machine; all configured net addresses on all net interfaces are enumerated and translated to DNS domain names; addresses that cannot be translated (e.g., having no appropriate reverse DNS entry) are skipped; note that diff addresses may resolve to the same name, so the duplicate entries are possible; the order of the output is random;

-a, --alias

(deprecated) display the alias name of the host (if used);

-b, --boot

always set a hostname; make it localhost if nothing else can be found (e.g., file /etc/hostname is missing or empty);

-d, --domain

display the name of the DNS domain; don’t use domainname (it shows NIS domain name), run dnsdomainname instead;

-F fname, --file fname

read the host name from the specified file;

-f, --fqdn

display the fully qualified domain name;

-I, --all-ip-addresses

display all net addresses of the host; all configured addresses on all net interfaces are enumerated; the loopback interface and IPv6 link-local addresses are omitted; contrary to -i, this option does not depend on name resolution; the order of output is random;

-i, --ip-address

display the IP address(es) of the host; it works only if the host name can be resolved;

-s, --short

display the short host name;

-y, --yp, -nis

display the NIS domain name (root can also set a new NIS domain);

Files
/etc/sysconfig/network hostname (Red Hat, Fedora);
/etc/hostname hostname (Ubuntu, Debian);
/etc/HOSTNAME hostname (Slackware, ...);

htop

is an interactive [ncurses-based] process viewer. It's like top, but allows you to scroll vert/horiz, viewing all running processes and their full cmd lines. Tasks related to processes (e.g., kill) can be done without entering their PIDs.

htop [-dChusv]

Options

-h    --help    -v    --version

-d, --delay=delay

delay between updates (in 0.1 sec);

-C, --no-color, --no-colour

use monochrome mode;

-u, --user=username

show only the processes of a specified user;

-p start working thread for pagemap memory stats;

-s, --sort-key column

sort by col (--sort-key help shows a column list);

Interactive commands

q or F10

quit;

/ / / / PgUP / PgDn / Home / End

scroll the process list;

Space

tag/untag a process; cmds that can operate on multiple processes (like kill), will be applied to the list of tagged proc, instead of the currently highlighted one;

U untag all processes;
s trace proc system calls (strace (1) must be installed); pressing this key will attach proc to the currently selected process, presenting a live update of sys calls issued by proc;
l display proc open files (lsof (1) must be installed); pressing this key will display the list of file descriptors opened by proc;

F1, h, ?

help screen;

F2, S

show setup screen, where you can config the meters displayed at the top of the screen, set various display opts, choose color scheme, select column order;

F3, /

incrementally search cmd lines of all displayed processes; the currently selected cmd will update as you type; while in search mode, pressing F3 will cycle through matching occurrences;

F4, \

incremental process filtering: type in part of a proc cmd line and only processes whose names match will be shown; to cancel filtering, enter the Filter option again and press Esc;

F5, t

toggle between tree and your previously selected sort view; selecting a sort view will exit the tree view;

F6, < , >

select a field for sorting (the current sort field is indicated by a highlight in the header);

F7, ]

increase the selected process's priority (subtract from 'nice' value) (superuser only);

F8, [

decrease the selected process's priority (add to 'nice' value);

F9, k

kill proc (sends a signal which is selected in a menu); if multiple processes were tagged, sends the signal to all of them; if none is tagged, sends to the currently selected;

I toggle sort order (increasing/decreasing);

+, -

when in tree mode, expand/collapse subtree (when subtree is collapsed a "+" sign shows to the left of the proc name);

a (on multiprocessor machines) set CPU affinity (which CPUs a proc is allowed to use);
u show only processes owned by a specified user;
M sort by memory usage;
P sort by processor usage;
T sort by time;
F "follow" process: if the sort order causes the currently selected proc to move in the list, make the selection bar follow and keep it always on screen; when a movement key is used, "follow" stops working;
K hide/show (toggle) kernel threads display;
H hide/show (toggle) user threads display; on systems that represent user threads differently than ordinary processes (such as recent NPTL-based systems), this can hide threads from userspace processes;

CTRL + L

refresh/recalculate;

pid

type in a PID and the selection highlight moves to the corresponding proc;

Columns

'-' in all rows means that a column is either not supported (on your system), or currently not implemented. The col names are the ones used in the "Available Columns" section of the setup screen.

Command

full cmd line of the process;

PID

the process ID;

PPID

the parent process ID;

PGRP

the process's group ID;

SESSION (SESN)

the process's session ID;

TTY_NR (TTY)

the controlling terminal of the proc;

TPGID

the process ID of the foreground proc group of the controlling terminal;

STATE (S)

the state of the proc: S - sleeping (idle), R - running, D - disk sleep (uninterruptible), Z - zombie (waiting for parent to read it's exit status), T - traced or suspended (e.g. by SIGTSTP), W - paging;

PROCESSOR (CPU)

the ID of the CPU the process last executed on;

NLWP

the number of threads in the process;

NICE (NI)

the nice value of a process, from 19 (low priority) to -20 (high priority); a high value means the process is being nice, letting others have a higher relative priority; only root can lower the value (i.e., increase proc priority);

PERCENT_CPU (CPU%)

the percentage of CPU time that the proc is currently using;

UTIME (UTIME+)

the amount of time the process has spent executing on the CPU in user mode (i.e. everything minus system calls), measured in clock ticks;

STIME (STIME+)

the amount of time the kernel has spent executing system calls on behalf of the process, measured in clock ticks;

TIME (TIME+)

the time the process has spent in user and system time (measured in clock ticks);

CUTIME

the children's user CPU time (the amount of time the process's waited-for children have spent executing in user mode);

CSTIME

the children's system CPU time (the amount of time the kernel has spent executing system calls on behalf of all the process's waited-for children);

PRIORITY (PRI)

the kernels internal priority for the process, usually just it's nice value plus 20; different for real-time processes;

PERCENT_MEM

the percentage of memory the process is currently using (based on the process's resident memory size);

M_SIZE (VIRT)

size in memory of the total program size;

M_RESIDENT (RES)

the resident set size, i.e. the size of the text and data sections, plus stack usage;

M_SHARE (SHR)

the size of the process's shared pages;

M_TRS (CODE)

the size of the text segment of the process;

M_LRS (LIB)

the library size of the process;

M_DRS (DATA);

the size of the data segment plus stack usage of the process;

M_DT (DIRTY)

the size of the dirty pages of the process;

ST_UID (UID)

the user ID of the process owner;

USER

the username of the process owner, or the user ID if the name can't be determined;

STARTTIME

the time the process was started;

RCHAR (RD_CHAR)

the number of bytes the process has read;

WCHAR (WR_CHAR)

the number of bytes the process has written;

SYSCR (RD_SYSC)

the number of read (2) syscalls for the process;

SYSCW (WR_SYSC)

the number of write (2) syscalls for the process;

RBYTES (IO_RBYTES)

bytes of read (2) I/O for the process;

WBYTES (IO_WBYTES)

bytes of write (2) I/O for the process;

IO_READ_RATE (IORR)

the I/O rate of read (2) in bytes per second, for the process;

IO_WRITE_RATE (IOWR)

the I/O rate of write (2) in bytes per second, for the process;

IO_RATE (IO)

the I/O rate, IO_READ_RATE + IO_WRITE_RATE;

CNCLWB (IO_CANCEL)

bytes of cancelled write (2) I/O;

CGROUP

which cgroup the process is in;

CTID

OpenVZ container ID (virtual env ID);

VPID

OpenVZ process ID;

VXID

VServer process ID;

hwclock

can be used to query/set computer's hardware clock. There are two main clocks in a Linux system: hardware clock and system clock. The hardware clock (RTC, real time clock, CMOS/BIOS clock) runs all the time (uses motherboard battery when the power is off). The system clock inside the Linux kernel is driven by the timer interrupts and works only when OS is running.

hwclock --show

show hardware clock time (RTC);

hwclock --show --utc

show hardware clock time (RTC) assuming it is UTC (warning will be given if hardware clock is set to localtime);

hwclock --show --localtime

show hardware clock time (RTC) assuming it is localtime (warning will be given if it is set to UTC);

hwclock --set --date="2/4/2006 09:40:00"

set RTC to the specified date/time (Feb, 4, 2006, 9:40);

hwclock --adjust

adjust RTC (uses /etc/adjtime to calculate time drift);

The system time is the number of seconds since 00:00:00 Jan 1, 1970 UTC (Universal Time Coordinated). The hardware clock is only used to initialize system time at the system start, and the system time is the only time that matters. You should avoid discontinuities in the system time (for example, changing it with date). When rebooting/shutting down, OS synchronizes hardware clock with the current system time.

The hardware clock is usually not very accurate, though its drift is to some extent systematic and predictable. ~ can be used to correct this drift using historical data in /etc/adjtime file. Assuming your computer is not configured to get accurate time from the NTP server, and runs without reboot sufficiently long (at least several days), the hardware clock adjustment procedure is like this:

Computers using NTP usually run in so called "11-minutes mode", which means the hardware clock is set to the current system time every 11 minutes. In this case the above procedure can cause the chaos. You can adjust system time smoothly using ntpd or ntpdate, though it works slowly, approx. 2 days for 1 minute. This method is good for servers [that don't use NTP] running 24x7 if error is within 1..2 min. Otherwise, it may be better to shutdown/reboot, enter the BIOS setup and set hardware clock (you should make a reasonable delay before starting OS, if the system time was far ahead).

Options

--help    --version

--show

show the hardware clock (RTC) time;

--set

set the hardware clock (RTC) to the specified date/time;

--hctosys

set the system time from RTC (is used by the system startup scripts and should not be used otherwise);

--systohc

set the hardware clock to the current system time (is mainly used by the system shutdown scripts);

--adjust

add or subtract time from the hardware clock to account for systematic drift since the last time the clock was set or adjusted;

--date=date_str

date specification for --set option;

--utc, --localtime

indicates that hardware clock is kept in UTC or localtime respectively (RTC itself knows nothing about this); if /etc/adjtime is missing, the localtime is default, otherwise the default is whichever was last specified with ~ (/etc/adjtime remembers this);

--noadjfile

disables facilities provided by /etc/adjtime; you must specify --utc or --localtime with this option;

--test

do everything except actually updating the hardware clock or anything else (useful for learning/testing);

--debug

display info about internal operations of ~;