pacmd

can be used to introspect or reconfigure a running PulseAudio sound server during runtime. It connects to the sound server and offers a simple live shell that can be used to enter cmds that can also be stored in the default.pa config script.

To exit the live shell, use CTRL + D. Note that the exit cmd inside the shell will tell the PulseAudio daemon itself to shutdown!

If any arguments are passed on the cmdline, they will be passed into the live shell which will process the command and exit.

pacmd --help

pacmd --version

echo "suspend 1" | pacmd     suspend pulseaudio;

echo "suspend 0" | pacmd     unsuspend pulseaudio;

Other typical cmd examples (the "list" output is usually voluminous):

pacmd list-sinks

pacmd list-sink-inputs

pacmd set-default-sink '1'

pacmd set-default-sink ladspa_out

passwd

changes user’s password (updates user’s authentication tokens).

passwd [options] [username]

Though users can change their own passwords, some options are available to root only. Options -i, -n, -w, -x may not work, if user account is not properly configured.

passwd

change password for the current user;

passwd alice

change password for user alice;

passwd -l alice

lock account of user alice;

passwd -u alice

unlock account of user alice;

passwd -S alice

show status info about alice's password; the output

alice P 05/08/10 0 300 0 0

means: password valid, changed at May 8, 2010, can be changed any time, expires after 300 days, no warning, no disable;

passwd -w14 -i14 alice

set warning 14 days before the date of expiration, and make account inactive in 14 days after that date;

Options

-?    --help    --usage

-d delete user’s password (disables user's account until the passwd is changed by the superuser);
-i n set the grace period (the num of days before the expired passwd is disabled);
-l lock (disable) the specified account;
-n n set the min passwd life time (days);
-S show the passwd status info;
-u unlock (enable) the specified account;
-w n set the numr of days before passwd expiration, when the user receives warning msgs;
-x n set the max passwd life time (days);

--stdin

read new passwd from stdin (which can be pipe);

pgrep, pkill

pgrep looks up (pkill signals) processes matching the selection criteria (usually proc name, or part of it, or regexp with proc name).

pgrep firefox

show PID of the specified app;

pgrep -l fire

show the process name and PID of the specified app;

pgrep [options] [pattern]

pkill [options] [pattern]

pattern is an ERE for matching against the process names or cmd lines. pgrep looks through the currently running processes and lists the PIDs of those matching the pattern; pkill sends to the matching processes the specified signal (by default SIGTERM).

pgrep -u root named

find the PID of the named daemon;

ps -fp $(pgrep -d, -x xterm)

give the detailed info on all xterm processes;

pkill -HUP syslogd

force syslog to re-read its config file (/etc/syslog.conf);

Options

-d delim

sets the string used to delimit each PID in the output (by default it is a newline) (pgrep);

-f match the pattern against the full cmd line (by default the pattern is matched against the process name limited to 15 chars present in the output of /proc/pid/stat);

-g pgrp

only match processes in the process group IDs listed; pgrp = 0 is translated into pgrep's / pkill's own process grp;

-G gid

only match processes whose real group ID is listed;

-l list the process name and the process ID (pgrep);
-n select only the most recently started of the matching proc;
-o select only the oldest of the matching processes;

-P ppid,...

only match processes whose parent PID is listed;

-s sid,...

only match processes whose process session ID is listed; sid = 0 is translated into pgrep's / pkill's own SID;

-t term,...

only match processes whose controlling terminal is listed (term should be specified without /dev/ prefix);

-u euid,...

only match processes whose effective user ID is listed;

-U uid,...

only match processes whose real user ID is listed;

-V version;
-v negates the matching;
-x only match processes whose name (or cmd line when -f is specified) exactly matches the pattern;

-sig

defines the signal to send to each matched process (pkill);

uid, gid, euid, sig can be numerical or symbolical.

Exit status
0 One or more processes matched the criteria;
1 No processes matched;
2 Syntax error in the command line;
3 Fatal error: out of memory, etc;

pidof

finds the process IDs of the specified [running] programs.

pidof [options] program [program ...]

It is mostly for scripts. To be sure, specify the full pathname of the program, otherwise, you can get a pid of another prog with the similar name. Actually, pidof is a symlink to the killall5 (System V version of killall that is used in SysV rc scripts only).

pidof bash

return PIDs of all running bash processes;

Options
-s return one PID only (single shot);
-c return pids that are running with the same root dir (does not make sense for non-root users, as they cannot check the current root dir of processes they do not own);
-x return pids of shells running the named script;

-o pid

omit processes with the specified process ID; you can use -o %PPID to exclude the parent process of ~;

ping

sends ICMP ECHO_REQUEST datagrams to a network host to find whether it is up and running. ~ runs continuously (unless -c or -w), and can be stopped with  CTRL + C.

ping www.microsift.com

ping www.microsoft.com using default parameters;

ping -i 10 192.168.0.8

ping host 192.168.0.8 sending one packet every 10 sec;

ping -p ff 192.168.0.12

ping host 192.168.0.12 sending packets filled with 1's (binary presentation of hex 0xff);

ping -I eth0 ws10

ping host ws10 sending packets through the network card eth0;

ping -I 192.168.0.2 srv5

ping host srv5 sending packets through the network card with IP address 192.168.0.2;

ping [options] host

Options
-h help;
-V version;
-v verbose;
-a audible ping;
-A adapt inter packet interval to round-trip time;
-b allow pinging a broadcast address;
-B do not allow ping to change source address of probes;
-c n stop after sending n ECHO_REQUEST pkts;
-f flood ping; interval is set to 0 unless specified explicitly;
-i n send pkts with an interval n seconds;

-I iface addr

set source address to specified inteface;

-l n send n pkts not waiting for reply; only root can use values more than 3;
-L suppress loopback of multicast packets;
-n use numeric output, do not resolve symbolic names;

-p pattern

send pkts filled with a specified pattern (up to 16 bytes); useful for data-related problem diagnostic;

-Q tos

set quality or service-related bits in ICMP datagrams (bits 1-4 for TOS, bits 5-7 for precedence); TOS can be: 0x02 (minimal cost), 0x04 (reliability), 0x08 (throughput), 0x10 (low delay); precedence range from priority (0x20) to net control (0xE0);

-q quiet output (nothing, except summary at the start/finish);
-R include RECORD_ROUTE option in the ECHO_REQUEST pkt and display the route buffer on returned pkts; many hosts ignore (discard) this option;
-r bypass the normal routing tables and send directly to a host on an attached interface; unless the host is on a directly attached network, error is returned;

-s size

set the number of data bytes to be sent; default is 56 (plus 8 bytes ICMP header);

-t ttl

set IP time to live;

-T timestamp

set special IP timestamp options:

tsonly     timestamps only;

tsandaddr     timestamps and addresses;

tsprespec host1 [host2 [host3 [host4]]]
    timestamp prespecified hops;

-w deadline

set timeout in seconds before ~ exits regardless of how many pkts have been sent or received;

-W time

time to wait for response in seconds;

postfix

You should not mix Postfix as a complex application used to handle e-mail (MTA, Mail Transfer Agent, SMTP server, etc) with postfix utility that is used to control mail service. Actually, there is a set of utilities related to Postfix mail service:

master Postfix master daemon;
mailq lists mail queue (Sendmail compatibility interface);
newaliases initializes the alias database (Sendmail compatibility interface);
postalias create/update/query alias database;
postcat examine Postfix queue file;
postconf Postfix configuration utility;
postfix controls the operation of the Postfix mail system;
postkick trigger Postfix daemon;
postlock Postfix-compatible locking;
postlog Postfix-compatible logging;
postmap Postfix lookup table manager;
postmulti Postfix multi-instance manager;
postqueue Postfix mail queue control;
postsuper   Postfix superintendent (maintains jobs on the Postfix queue);
sendmail Postfix to Sendmail compatibility interface;

The main Postfix process (daemon) is master (config file /etc/postfix/master.cf). The main config for the service is /etc/postfix/main.cf. To re-read configuration without restarting the service, use:

posrfix reload

The general format of postfix (control program) is:

postfix [-Dv] [-c config_dir] cmd

Options

-c config_dir

read the main.cf and master.cf config files in the specified dir (by default /etc/postfix);

-D run each Postfix daemon under control of debugger (use with postfix start only);
-v verbose;
Commands
check check/validate mail system configuration;
start start the Postfix mail system (also runs check);
stop stop the Postfix mail system in orderly fashion;
abort stop the Postfix mail system abruptly;
flush force delivery of every mesg in the deferred mail queue;
reload   re-read config files;
Mail queue management

There are incoming, active, deferred and hold queue dirs with mail files, and bounce, defer, flush dirs with log files. By default postsuper operates on all queue dirs.

postsuper -d msg_id

delete from queue the message specified by msg_id;

postsuper -d - < file_with_msg_ids

delete from queue multiple messages listed in file;

postsuper -d ALL deferred

delete all messages from the deferred queue;

postsuper -h msg_id

put the specified message "on hold";

postsuper -h ALL

put all messages "on hold";

postsuper -H msg_id

release the specified msg from "hold";

postsuper -H ALL

release all messages from "hold";

postsuper -p

purge old temp files after system crash;

Configuration

postconf mail_version

show postfix version;

postconf alias_map

show alias database location;

postconf -d

show default param settings instead of actual;

postconf -e

edit main.cf config file;

postconf -n

show non-default param settings only;

postmap hash:sasl_passwd

create lookup table sasl_passwd.db using plain text file sasl_passwd as source;

See more examples of postconf usage in Mail service (postfix + dovecot)

printf

formats and prints data (like C function of the same name). ~ is used mostly in bash scripts.

printf "PI\t%e\nE\t%e\n" 3.14159 2.71828

print the values of "pi" and "e" in exponential form;

printf format [arg] ...

Options

--help    --version

Interpreted sequences
\" double quote;

\NNN

char with octal value NNN (1..3 digits);

\\ backslash;
\a alert (BEL);
\b backspace;
\c produce no further output;
\f form feed;
\n new line;
\r carriage return;
\t tab (horizontal);
\v vertical tab;

\xNN

byte with hexadecimal value NN (1..2 digits);

\uNNNN

char with hexadecimal value NNNN (4 digits);

\UNNNNNNNN

char with hex value NNNNNNNN (8 digits);

%% a single %;
%b arg as a string with '\' escapes interpreted, except that octal escapes are of the form \O or \ONNN;

All C format specs (diouxXfeEgGcs) are also supported.

Note!

Your shell may have its own version of printf!

ps

gives a snapshot of the current processes.

ps [options]

Process 0 (PID = 0) is smth special. It is kernel's runnable process known as init_task, sched, swapper, idle. The program init is spawned by init_task and has PID = 1, PPID = 0. Usually kthreadd, kernel thread daemon, has PID = 2, PPID = 0.

Current version of ~ accepts 3 kinds of options:

Options of different types may be freely mixed.

ps U $USER

show all processes owned by the current user;

ps ax

show every process on the system using BSD syntax;

ps aux

like previous, but shows more columns;

ps axZ

show all processes with security context (SELinux);

ps -e

show every process on the system using standard syntax;

ps -el --headers

show every process on the system using standard syntax, long format, add column headers to each page;

ps U oracle

show all processes owned by oracle;

ps -U root -u root -N

show every process except those running as root (real or effective ID);

ps -eo pid,tt,user,fname,tmout,f,wchan

show every process with a user-defined format;

ps -axo pid,cmd,etime | grep firefox

how long firefox browser is already running? (time format is dd-hh:mm:ss, i.e., num of days, hours, minutes, seconds); NOTE that this is not the same as CPU time, this is the total time since the proc was started;

ps -eo pid,lstart,cmd | grep firefox

another way to find when the process was started;

General options

--help    -V    --version

--info   show debugging info;

Process selection
-A select all processes;
-a select all processes with a tty except session leaders;
-d select all, but omit session leaders;
-e select all processes;
-N negate selection;
 a select all proc on a terminal, including those of other users;
 r restrict output to running processes;
 T select all processes on this terminal;
 x select processes without controlling ttys;
Process selection by list
-C select by command name;
-G select by RGID;
-g select by session leader or by group name;
-p select by PID;
-s select processes belonging to the sessions given;
-t select by tty;
-U select by RUID;
-u select by effective user ID;
 U select processes for the specified users;
Output format control
-f full listing;
-F extra full format;
-j jobs format;
-l long format;
-o user-defined format;
-y do not show flags; show rss in place of addr;
-Z security context format;
 s signal format;
 u user-oriented format;
 v virtual memory format;
Output modifiers
-H show process hierarchy (forest);

-n lst, N lst

set name list file;

-w wide output;
 C use raw CPU time instead of decaying average;
 c show true command name;
 e show environment after command;
 f show ASCII-art process hierarchy (forest);

--cols, --columns

set screen width;

--forest

show ASCII-art process tree;

--headers

repeat header lines on each output page;

--no-headers

print no header line at all;

--rows, --lines

set screen height;

--sort

specify sorting order;

Thread info
-L show threads, possibly with LWP and NLWP columns;
-m show threads after processes;
-T show threads, possibly with SPID column;
 H show threads as if they were processes;
Some format specifiers
ColumnSpecDesciption
%CPU %cpu CPU usage, %;
%MEM %mem task’s current share of the available physical memory, %;
C c priority of the process used by scheduler;
CMD args,cmd,
command
full cmd line of the process;
COMMAND fname simple name of executable;
F f task’s current scheduling flags in hex;
GROUP group group name;
NI ni,nice the nice value of the task; negative means higher pri, positive means lower; zero means that priority will not be ajusted in determinig a task’s dispatchability;
PID pid process ID;
PPID ppid parent process ID;
PRI pri kernel scheduling priority of the task;
RSS rss resident set size;
RUSER ruser real user name;
S s,state the process status;
SESS sess session ID;
STIME stime the time when the process was started;
SZ sz memory size in Kb;
TIME time total cpu time the task has used since it started;
TTY tty8 controlling tty; this is usually the device (serial port, pty, etc) from which the proc was started;
UID uid user ID;
USER user,uname user name;
VSZ vsz,vsize total virtual memory size in Kb;
WCHAN wchan depending on the availability of the kernel link map (System.map), this field will show the name or the addr of the kernel function in which the task is currently sleeping;
Process state codes
D uninterruptible sleep (usually I/O);
R runnable (on run que);
S sleeping;
T traced or stopped;
W paging;
X dead;
Z defunct (zombie);
Additional process state codes (BSD)
W has no resident pages;
< high-priority process;
N low-priority task;
L has pages locked into memory (real-time and custom I/O);

pstree

shows running processes as a tree rooted at the specified pid or init if there are neither pid nor user. If user is specified, all process trees rooted at processes owned by that user are displayed.

pstree [options] [pid | user]

To make the view compact ~ visually merges identical branches by placing them in square brackets and prefixing with the repetition count.

pstree -Gap

show all processes as a tree with PIDs and cmd lines using VT100 line drawing (may have sense if you connect from the remote host using terminal emulation);

pstree -a zorg

show processes of user zorg;

pstree -a 1239

show ancestors of the process 1239;

Options
-a show command line arguments;
-c disable compaction of identical subtrees;
-G use VT100 line drawing characters;
-h highlight the current process and its ancestors;

-H pid

highlight the specified process and its ancestors;

-l display long lines (by default lines are truncated);
-n sort processes with the same ancestor by PID;
-p show PIDs (as decimal numbers after process names);
-u show UID transitions; if the process UID differs from UID of its parent, the new UID is shown after the process name;
-U use UTF-8 line drawing characters;
-V version;
-Z show security context for each process (SELinux);

pwck

verifies the integrity of the system authentication information.

pwck [options] [passwd shadow]

~ checks that all entries in /etc/passwd and /etc/shadow have the proper format and contain valid data. The user is prompted to delete entries that are improperly formatted or have other uncorrectable errors. Checks are made to verify that each entry has:

Shadow checks are enabled when a second file param is specified or when /etc/shadow exists on the system. These checks are:

The outcome of the procedure:

  1. An entry with the wrong number of fields (fatal error) is prompted for deletion. If user does not answer affirmatively, all further checks are bypassed.
  2. An entry with a duplicated user name (fatal error) is also prompted for deletion, and if user does not answer affirmatively, the remaining checks will still be made.
  3. All other errors are warnings and user is encouraged to correct them with usermod.
Options

-h    --help

-q report errors only (--quiet);
-r execute ~ in read-only mode (--read-only);

-R chroot_dir, --root chroot_dir

apply changes in the chroot_dir directory and use the config files from the chroot_dir;

-s sort entries in /etc/passwd, /etc/shadow by UID (--sort);
Exit codes
1 invalid command syntax;
2 one or more bad password entries;
3 can't open password files;
4 can't lock password files;
5 can't update password files;

pwconv, pwunconv,
grpconv, grpunconv

convert to/from shadow passwords and groups.

pwconv

creates /etc/shadow from /etc/passwd and an optionally existing /etc/shadow;

pwunconv

creates /etc/passwd from /etc/passwd and /etc/shadow and then removes /etc/shadow;

grpconv

creates /etc/gshadow from /etc/group and an optionally existing /etc/gshadow;

grpunconv

creates /etc/group from /etc/group and /etc/gshadow and then removes /etc/gshadow;

There are no args. The programs operate on the normal and shadow password and group files:

/etc/passwd

/etc/group

/etc/shadow

/etc/gshadow

Warning!

Run pwck and grpck before converting, because errors in password or group files may cause these programs to loop forever or fail.