unmounts filesystem specified by the dir name where it has been mounted. Special device name can also be used, but this is obsolete and doesn’t work in case the device was mounted on several directories.
umount
[options] dir
A filesystem cannot be unmounted while it is busy (when there are open
files on it, some process has working dir there, swap file on this system
is used). A lazy (-l
) unmount helps to solve this problem.
umount /mnt
unmount filesystem mouted on dir /u01;
umount /media/cdrom
unmount CD;
umount /dev/sde1
unmount fs on the specified device;
Some options
-h |
help; |
-V |
version; |
-v |
verbose; |
-a |
unmount all filesystems described in /etc/mtab; |
-d |
if the unmounted device was a loop device, free this device; |
-f |
force unmount (in case of an unreachable NFS system); |
-l |
lazy unmount: detach the filesystem from the tree now, and cleanup all references to it as soon as possible; |
-n |
unmount without writing in /etc/mtab; |
-r |
if unmount fails, try to remount read-only; |
outputs some system information.
uname
show kernel name;
uname -a
show all relevant system info;
uname -m
show system architecture: i686 means that your system is Intel 32-bit, x86_64 means your system is Intel 64-bit;
uname -rvi
show kernel release / version and hw platform;
Options
--help
--version
-a
, --all
print all in the order of the following options;
-s
, --kernel-name
print kernel name (default);
-n
, --nodename
print network node hostname;
-r
, --kernel-release
print kernel release;
-v
, --kernel-version
print kernel version;
-m
, --machine
print machine hardware name;
-p
, --processor
print processor type;
-i
, --hardware-platform
print hardware platform;
-o
, --operating-system
print operating system;
writes contents of the specified files to stdout, replacing strings of two or more spaces with as many tabs as possible followed by as many spaces as needed.
unexpand
[options] [file] ...
If there is no file, or '-
' is specified, ~
gets
data from stdin. By default only initial spaces are converted (those
preceding all non-space or non-tab chars).
unexpand -a ex1.cpp > ex2.cpp
replace spaces with tabs in ex1.cpp and save new version to ex2.cpp;
Options
--help
--version
-a
, --all
convert all strings of two or more spaces or tabs (not just initial ones) to tabs;
-t
n[,
m]...,
--tabs=
n[,
m]...
if only n is given, set tabs n spaces
apart; otherwise set tabs at columns n, m, etc (starting
from 0); when the list is over, leave the remaining tabs and
spaces unchanged; -t
implies -a
;
--first-only
convert only leading sequences of whitespace;
Omitting -t
is equivalent to specifying -t 8
;
copies text lines from input (stdin, pipe, file) to output (stdout, pipe, file) discarding adjacent identical lines (default behaviour that can be changed by options). Exit status is 0 on success, non-zero otherwise.
cat messages.txt | uniq -u
display only uniq lines in messages.txt;
uniq
[options] [input [output]]
Options
--help
--version
-c
, --count
prefix lines by the number of occurrences;
-d
, --repeated
output duplicate lines only;
-D
,
--all-repeated=
method
do not discard the repeated input lines, but discard lines
that are not repeated; an optional method (none
,
prepend
, separate
) defines how to delimit groups
of repeated lines;
-f
n,
--skip-fields=
n
don't compare the first n fields;
-i
, --ignore-case
ignore case when comparing;
-s
n,
--skip-chars=
n
don't compare the first n chars;
-u
, --unique
output unique lines only (by default, the repeated input lines are detected only if they are adjacent;
-w
n,
--check-chars=
n
compare no more than n chars;
lists, tests, extracts files from a ZIP archive. Similar to DOS
pkunzip
, though options and default behaviour differ.
See also zip
.
The default behavior (with no options) is to extract into the curr dir (and subdirs below it) all files from the specified ZIP archive.
unzip backup01.zip
extract all files from backup01.zip into the curr dir preserving original dir structure;
unzip backup02 -d tmp2
extract all files from backup02.zip to tmp2 dir;
unzip backup01 -x a2712.dat
extract all files except a2712.dat from the archive backup01.zip;
unzip -fo bkp04 notes.txt
quietly replace an existing notes.txt if the archived notes.txt is newer;
unzip
[-Z
]
[-
opts[modifiers]
] file[.zip
] [list]
[-x
xlist] [-d
exdir]
Options
-d |
extract files into exdir; |
-f |
freshen existing files, do not create new; |
-l |
list files in archive; |
-p |
extract files to pipe (no messages); |
-t |
test compressed archive data; |
-u |
update files, create new, if necessary; |
-x |
exclude files specified in xlist; |
-z |
display archive comment; |
Modifiers
-a |
auto-convert text files; |
-aa |
treat all files as text; |
-C |
match file names case-insensitively; |
-j |
junk paths (do not make dirs); |
-L |
make some names lowercase; |
-M |
pipe through more ; |
-n |
never overwrite existing files; |
-o |
overwrite files without prompting; |
-q |
quiet mode (-qq even more quiet mode); |
-v |
verbose; (also displays version info); |
-X |
restore UID/GID info; |
creates a new user account or updates default values (-D
).
useradd -m vmail
the most basic user creation cmd: it creates user named vmail, user's group vmail (only if USERGROUPS_ENAB=yes in /etc/login.defs), user's home dir (most likely /home/vmail, check defaults);
useradd jane -m -N -g users
create new user account (jane) assuming defaults for shell, expiration date, home dir name, etc;
useradd oracle -g oinstall -G dba
create new user account named oracle with an initial login group oinstall and a supplementary group dba;
useradd -D
show current defaults;
useradd -D -g users -e 60 -f 0
change new user creation defaults (initial group users, expiration time 60 days, the number of inactive days 0);
useradd
username [options]
Options
-h
--help
-b
dir,
--base-dir
dir
the default base dir for the system;
-c
str,
--comment
str
comment field in passwd file (usually user's full name);
-D |
display current or set new default values: |
-d
home_dir,
--home
home_dir
the new user’s home dir (by default it is usually login name + base dir);
-e
date,
--expiredate
date
the date on which the user account will be disabled; the date format should be YYYY-MM-DD;
-f
days,
--inactive
days
the number of days after a password expires until the account is permanently disabled; the default is -1, which makes this feature inactive; 0 disables account immediately after password expiration;
-G
list,
--groups
list
a comma-separated list of supplementary groups which the user is a member of;
-g
init_grp,
--gid
init_grp
the name or the number of the user’s initial login group (must exist);
-k
dir,
--skel
dir
(is only valid if home dir is created) skeleton dir containing files and dirs to be copied to the user's home dir (by default it is /etc/skel);
-K key=value
,
--key key=value
overrides default values in /etc/login.defs (UID_MIN, UID_MAX, UMASK, etc);
-l
, --no-log-init
do not add user to the lastlog and faillog databases;
-m
, --create-home
create (if it doesn't exist) a home dir for new user;
-M |
don't create the user's home dir, even if the system defaults require it; |
-N
, --no-user-group
do not create a group with the same name as the user,
but add the user to the group specified by the -g
option
or by the GROUP var in /etc/default/useradd;
-o
, --non-unique
allow to create users with duplicate UID;
-p
passwd,
--passowrd
passwd
the encrypted password, as returned by crypt
(bad, because passwords are visible to users listing processes);
-r
, --system
create a system account;
-s
shell
the name of the user’s login shell;
-U
, --user-group
create a group with the same name as the user, and add user to this group;
-u
uid
the numerical value of the user's ID (must be unique unless
-o
); 0..999 are usually reserved for system accounts;
-Z
user,
--selinux-user
user
SELinux user for the user's login (the default is to leave this field blank, which causes system to select the default SELinux user);
/etc/passwd | user account info; |
/etc/shadow | secure user account info; |
/etc/group | group info; |
/etc/gshadow | secure group info; |
/etc/default/useradd | useradd defaults; |
/etc/login.defs | system-wide settings; |
/etc/skel | directory containing default files; |
System account vs [regular] user account
There is no big difference. But it may be useful to keep in mind that system users are created with no aging info in /etc/shadow, and their numeric identifiers are chosen in the SYS_UID_MIN - SYS_UID_MAX range, defined in /etc/login.defs, instead of UID_MIN - UID_MAX (same with GIDs).
The main difference is the purpose: these accounts in most cases are auto created by system and supposed to be used by daemons, system apps, and for other [system] purposes. Some system accounts have predefiend user IDs, e.g. root account.
There are also Service accounts - the accounts used by web servers, database servers, application servers. The difference between system accounts and service accounts is vague.
A privileged account is a user account that has more privileges than ordinary users. System/service accounts are usually privileged accounts.
deletes a user account and related files.
userdel
[-r
] username
In fact, it modifies the system account files, removing all entries that
refer to username. The option -r
causes the user’s
home directory to be removed with all its contents (the user mail spool also
will be removed). However, files, belonging to this user in other
filesystems, must be removed manually. You cannot remove an account,
if the user is currently logged in.
modifies a user account (modifies the system account files).
usermod
[options] username
Usually this is a bad idea to modify an account while user is logged in. You cannot change user’s login name in this case, however some values can be changed (expiration date, inactive days, supplementary groups, etc).
usermod -d /var/vmail -m vmail
move user's home dir (with all contents) to a new location;
usermod -g oinstall -G dba oracle
change user's initial grp and add one supplementary grp;
usermod -e 2005-12-10 alex
set new expiration date for this account;
usermod -L pro9
lock user's account;
usermod -U pro9
unlock user's account;
usermod -a -G vboxusers ozzy
add user ozzy to a supplementary group vboxusers; Note! If you successfully add yourself to some group, you won't see any changes until you logout/login (or reboot);
Options
-a
, --append
add user to supplementary group(s); it should only be used
with -G
;
-c
str,
--append
str
change user's comment field;
-d
dir,
--home
dir
change user's login (home) dir; if -m
is given,
the contents of the current home dir are moved to the new dir (it's not
neccessary to create it beforehand);
-e
date,
--expiredate
date
set user account expiration date (YYYY-MM-DD);
-f
days,
--inactive
days
set the number of days after pass expiration until account is permanently disabled;
-g
grp,
--gid
grp
user's new initial login group (name or number / must exist);
-G
list,
--groups
list
new list of user's supplementary groups; if user is
currently a member of a grp which is not listed, user will be removed
from that grp (-a
can change this behaviour);
-L
, --lock
lock user's password;
-l
new_name,
--login
new_name
change user's account name; other params (including home dir) are not changed;
-m
, --move-home
move contents of the user's home dir to a new location
(can be used with -d
only);
-o
, --non-unique
allow to use non-unique UIDs;
-p
new_pass,
--password
new_pass
a bad way to change user's password; ~
works
with classical password files only and does not understand more advanced
auth schemas;
-s
str,
--shell
str
set new login shell; if str is missing,
~
selects system's default shell;
-u
uid,
--uid
uid
set new UID, non-negative and unique
(unless -o
is also given); 0..999 are usually
reserved for system; the inodes of files owned by user and
located in user's home dir (+mailbox) will be properly modified;
however, the ownership of user's files outside of the home dir must be
fixed manually;
-U
, --unlock
unlock user's password;
-Z
user,
--selinux-user
user
set SELinux user for the user's login (the default is to leave this field blank, which causes the system to select the default SELinux user);
creates a new universally unique identifier (UUID).
uuidgen
uuidgen -r
generate a random-based UUID; a high quality random number generator (/dev/random) is required (default);
uuidgen -t
generate a time-based UUID (system time plus ethernet hardware address, if available);
The UUID looks like:
1e4v28ma-2fo6-33p2-97q5-hg8dnpf1996i