util-linux

Last update: 2023-03-12 17:53:21 +0800 +0800
Available translations: 日本語 / 中文(简体) / 中文(繁體)

util-linux is a collection of system utilities maintained as an independent upstream project. It supplies interfaces for block devices, mounts, terminals, sessions, namespaces, resource control, and data formatting. Distributions can split utilities into separate packages, so installed commands depend on packaging policy.

Operational Boundaries #

Commands that modify partitions, mounts, swap, device state, process credentials, or namespaces require suitable privileges. Inspect state before changing it, identify devices through stable attributes such as UUID or /dev/disk/by-id, and confirm a target is not mounted or in active use.

The project spans several kernel interfaces:

  • lsblk, blkid, blockdev, fdisk, and wipefs inspect sysfs, device nodes, ioctls, and on-disk signatures;
  • mount, umount, findmnt, and fsfreeze operate on the VFS mount API and /proc/self/mountinfo;
  • unshare, nsenter, setpriv, prlimit, taskset, and chrt configure process namespaces, credentials, resource limits, affinity, and schedulers;
  • agetty, script, setterm, and wall operate on terminals and login records.

The exact command set depends on the util-linux build configuration and distribution packaging. Use command --help, the command’s man page, and the distribution’s package metadata or an individual command’s --version output before depending on a recent option.

Command Reference #

CommandPurpose
addpartadd a partition to a kernel-recognized disk table
agettyopen a terminal line and start login
blkdiscarddiscard sectors on a block device
blkidlocate or print block-device attributes
blkprmanage block-device persistent reservations
blkzonemanage zoned block-device zones
blockdevissue block-device ioctl operations
caldisplay a calendar
cfdiskinteractive partition-table editor
chcpuconfigure CPU state where the architecture supports it
chfnchange a user finger-information field
chmemconfigure memory state where the architecture supports it
choomdisplay or adjust out-of-memory killer scores
chrtinspect or set scheduling policy and priority
chshchange a user login shell
colfilter reverse line feeds
colcrtfilter nroff overstrikes
colrmremove selected columns from lines
columnformat input into columns or tables
ctrlaltdelset Ctrl-Alt-Del handling
delpartremove a partition from the kernel
dmesgprint or control the kernel ring buffer
ejecteject or close removable-media devices
enosysreturn an unimplemented-system-call error
exchexchange two files atomically
fadvisepredeclare file-access patterns
fallocateallocate file space
fdiskmanipulate partition tables
fincorecount cached pages in files
findfsfind a block device by label or UUID
findmntlist mounted filesystems
flockacquire an advisory file lock
fsckcheck and repair a filesystem
fsck.cramfscheck a cramfs filesystem
fsck.minixcheck a Minix filesystem
fsfreezefreeze or unfreeze a filesystem
fstrimdiscard unused filesystem blocks
getoptparse command-line options in shell scripts
hardlinkfind or replace duplicate files with hard links
hexdumpdisplay file contents in hexadecimal
hwclockquery or set the hardware clock
i386run a program with i386 personality
ioniceget or set I/O scheduling priority
ipcmkcreate System V IPC objects
ipcrmremove System V IPC objects
ipcsshow System V IPC status
irqtopdisplay interrupt usage
isosizereport an ISO-9660 image size
killsend a signal to processes
lastshow login history from wtmp
lastbshow failed-login history from btmp
lastlog2query or update the lastlog2 database
ldattachattach a line discipline to a serial device
linux32run a program with 32-bit personality
linux64run a program with 64-bit personality
loggerwrite a message to the system log
loginbegin a user login session
lookdisplay lines beginning with a string
losetupmanage loop devices
lsblklist block devices
lsclockslist available clocks
lscpudisplay CPU architecture information
lsfdlist open file descriptors
lsipcdisplay System V IPC information
lsirqlist interrupt information
lslockslist local system locks
lsloginsdisplay known users
lsmemlist memory ranges
lsnslist namespaces
mcookiegenerate a magic cookie
mesgcontrol terminal write permission
mkfsbuild a filesystem
mkfs.bfsbuild a SCO BFS filesystem
mkfs.cramfsbuild a compressed ROM filesystem
mkfs.minixbuild a Minix filesystem
mkswapcreate a swap area
morepage through text
mountattach a filesystem
mountpointtest whether a path is a mount point
nameiresolve path components
newgrpstart a shell with a different group
nologinrefuse interactive logins
nsenterrun a program in existing namespaces
partxtell the kernel about disk partitions
pgpage through text
pipeszinspect or set pipe buffer size
pivot_rootchange the root filesystem
prlimitget or set process resource limits
readprofileread kernel profiling information
renamerename files using a substitution
renicealter process scheduling priority
resizepartresize a partition entry
revreverse characters in each line
rfkillquery or change radio-device state
rtcwakeenter suspend using an RTC wake alarm
runuserrun a command as another user
scriptrecord a subshell terminal session
scriptlivestream a recorded terminal session
scriptreplayreplay a recorded terminal session
setarchchange execution personality
setpgidset a process group identifier
setprivrun a program with selected privileges
setsidrun a program in a new session
settermcontrol terminal attributes
sfdiskscriptable partition-table editor
surun a shell as another user
suloginsingle-user-mode login
swaplabelprint or change swap labels
swapoffdisable swap devices or files
swaponenable swap devices or files
switch_rootswitch to a new root filesystem
tasksetget or set CPU affinity
tunelpset parallel-port printer parameters
uclampsetget or set utilization clamping
ulunderline text with backspaces
umountdetach mounted filesystems
uname26run a program with a Linux 2.6 personality
unsharerun a program with new namespaces
utmpdumpdump utmp or wtmp records
uuiddrun the UUID generation daemon
uuidgengenerate UUIDs
uuidparseparse and print a UUID
vigredit group or gshadow safely
vipwedit passwd or shadow safely
waitpidwait for a child process
wallwrite a message to logged-in users
wdctlshow watchdog-device status
whereislocate binary source and manual files
wipefserase filesystem or partition signatures
writesend a message to another terminal
x86_64run a program with x86-64 personality
zramctlset up compressed RAM block devices

Common Workflows #

lsblk --fs, blkid, findmnt, and mountpoint inspect storage without changing it:

sh
lsblk --json --output NAME,PATH,SIZE,FSTYPE,UUID,MOUNTPOINTS
findmnt --json --output SOURCE,TARGET,FSTYPE,OPTIONS
blkid --probe --usages filesystem /dev/disk/by-id/example

Specify columns in scripts because default output changes as util-linux adds information. Prefer --json, --pairs, or --raw where supported, and set LC_ALL=C if parsing human-readable diagnostics. Never parse the aligned default table as a stable interface.

fdisk, cfdisk, and sfdisk modify partition tables. Save the current layout with sfdisk --dump and verify the device by size, model, serial, and stable path before writing. partx asks the kernel to add or remove partition mappings after an intended table change; it does not edit the on-disk table. mkswap prepares a swap area, then swapon enables it and swapoff disables it.

unshare, nsenter, setpriv, runuser, setarch, and taskset affect execution context. A namespace or affinity change does not grant permissions; capabilities, user mappings, and cgroup policy still determine what the process can do.

sh
unshare --user --map-root-user --mount-proc sh
nsenter --target "$pid" --mount --uts --ipc --net --pid
script --log-out session.typescript --log-timing session.timing

nsenter joins the selected namespaces of an existing process and therefore requires permission to inspect and enter them. unshare availability for unprivileged user namespaces is controlled by the kernel and local security policy.

script, scriptreplay, and scriptlive can capture terminal sessions. Recorded input may contain credentials or other secrets, so files require access controls appropriate to their contents.

Comments

Read or comment on GitHub (sign-in required to comment)