GNU Core Utils

The GNU Core Utilities or coreutils is a package of GNU software containing implementations for many of the basic tools, such as cat, ls, and rm, which are used on Unix-like operating systems.

base64

base64 encode/decode data and print to standard output

Usage: base64 [OPTION]... [FILE]

Flags

FlagDescription
-d, --decodeDecode Input
-i, --ignore-garbagewhen decoding, ignore non-alphabet characters

basename

strip directory and suffix from filenames Usage: basename NAME

cat

concatenate files and print on the standard output Usage: cat [OPTION]... [FILE]...

Flags

FlagDescription
-b, --number-nonblanknumber nonempty output lines, overrides -n
-n, --numbernumber all output lines

cd

change current working directory Usage: cd [dir] Go to home directory of current user: cd Go up to the parent of the current directory: cd .. Go to the previously chosen directory: cd -

chmod

change file mode (permissions) bits Usage: chmod [OPTION]... OCTAL-MODE FILE...

Options

OptionDescription
-c, --changeslike verbose but report only when a change is made
-f, --silent, --quietsuppress most error messages
-v, --verboseoutput a diagnostic for every file processed
--reference=RFILEuse RFILE’s mode instead of specifying MODE values. RFILE is always dereferenced if a symbolic link.
-R, --recursivechange files and directories recursively

chown

change file owner and group Usage: chown [OPTION]... [OWNER][:[GROUP]] FILE...

Options

OptionDescription
-c, --changeslike verbose but report only when a change is made
-f, --silent, --quietsuppress most error messages
-v, --verboseoutput a diagnostic for every file processed
--reference=RFILEuse RFILE’s owner and group rather than specifying OWNER:GROUP values. RFILE is always dereferenced.
-R, --recursiveoperate on files and directories recursively

chroot

run command or interactive shell with special root directory Usage: chroot [OPTION] NEWROOT [COMMAND [ARG]...]

cksum

compute and verify file checksums Usage: cksum [OPTION]... [FILE]...

Options

OptionDescription
-a, --algorithm=TYPEselect the digest type to use

Digests

  • crc
  • md5
  • sha1
  • sha224
  • sha256
  • sha384
  • sha512
  • blake2b

cp

copy files and directories Usage: cp [OPTION]... SOURCE DEST

Options

OptionDescription
-l, --linkhard link files instead of copying
-R, -r, --recursivecopy directories recursively
-s, --symbolic-linkmake symbolic links instead of copying
-S, --suffix=SUFFIXoverride the usual backup suffix
-t, --target-directory=DIRECTORYcopy all SOURCE arguments into DIRECTORY
--update[=UPDATE]control which existing files are updated; UPDATE={all,none,older(default)}.
-uequivalent to --update[=older]
-v, --verboseexplain what is being done
-x, --one-file-systemstay on this file system
-bCreate a backup file if destination already exists

cut

remove sections from each line of files Usage: cut OPTION... [FILE]...

Options

OptionDescription
-d, --delimiter=DELIMuse DELIM instead of TAB for field delimiter
-f, --fields=LISTselect only these fields; also print any line that contains no delimiter character, unless the -s option is specified
-s, --only-delimiteddo not print lines not containing delimiters
--output-delimiter=STRINGuse STRING as the output delimiter the default is to use the input delimiter

date

print or set the system date and time Usage: date [OPTION]... [+FORMAT]

Options

OptionDescription
-d, --date=STRINGdisplay time described by STRING
-r, --reference=FILEdisplay the last modification time of FILE
-s, --set=STRINGset time described by STRING
-u, --utc, --universalprint or set Coordinated Universal Time (UTC)
--isoprint ISO date (YYYY-MM-DD)

dd

convert and copy a file Usage: dd [OPERAND]...

Operands

OperandDescription
bs=BYTESread and write up to BYTES bytes at a time (default: 512)
count=Ncopy only N input blocks
if=FILEread from FILE instead of stdin
of=FILEwrite to FILE instead of stdout
status=LEVELThe LEVEL of information to print to stderr; ‘none’ suppresses everything but error messages, ‘noxfer’ suppresses the final transfer statistics, ‘progress’ shows periodic transfer statistics

df

report file system space usage Usage: df [OPTION]... [FILE]...

Options

OptionDescription
-a, --allinclude pseudo, duplicate, inaccessible file systems
-h, --human-readableprint sizes in powers of 1024 (e.g., 1023M)
-H, --siprint sizes in powers of 1000 (e.g., 1.1G)
-i, --inodeslist inode information instead of block usage

dirname

strip last component from file name Usage: dirname [OPTION] NAME...

du

estimate file space usage Usage: du [OPTION]... [FILE]...

Options

OptionDescription
-h, --human-readableprint sizes in human readable format
-s, --summarizedisplay only a total for each argument

echo

display a line of text Usage: echo [OPTION]... [STRING]...

Options

OptionDescription
-ndo not output the trailing newline
-eenable interpretation of backslash escapes
-Edisable interpretation of backslash escapes (default)

Backslash Interpretations

SequenceMeaning
\backslash
\aalert (BEL)
\bbackspace
\cproduce no further output
\eescape
\fform feed
\nnew line
\rcarriage return
\thorizontal tab
\vvertical tab
\0NNNbyte with octal value NNN (1 to 3 digits)
\xHHbyte with hexadecimal value HH (1 to 2)

env

run a program in a modified environment Print Environment Variables with only env Usage: env [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]

Options

OptionDescription
-i, --ignore-environmentstart with an empty environment
-u, --unset=NAMEremove variable from the environment
-C, --chdir=DIRchange working directory to DIR
--block-signal[=SIG]block delivery of SIG signal(s) to COMMAND
--ignore-signal[=SIG]set handling of SIG signal(s) to do nothing
-v, --debugprint verbose information for each processing step

false

do nothing, unsuccessfully Usage: false

output the first part of files Usage: head [OPTION]... [FILE]...

Options

OptionDescription
-c, --bytes=[-]NUMprint the first NUM bytes of each file; with the leading ’-’, print all but the last NUM bytes of each file
-n, --lines=[-]NUMprint the first NUM lines instead of the first 10; with the leading ’-’, print all but the last NUM lines of each file
-q, --quiet, --silentnever print headers giving file names

id

print real and effective user and group IDs Usage: id [OPTION]... [USER]...

Option

OptionDescription
-g, --groupprint only the effective group ID
-G, --groupsprint all group IDs
-n, --nameprint a name instead of a number, for -ugG
-u, --userprint only the effective user ID

install

copy files and set attributes Usage: install [OPTION]... SOURCE... DIRECTORY

Options

OptionDescription
-bmake a backup of each existing destination file
-S, --suffix=SUFFIXoverride the usual backup suffix
-C, --comparecompare content of source and destination files, and if no change to content, ownership, and permissions, do not modify the destination at all
-d, --directorytreat all arguments as directory names; create all components of the specified directories
-g, --group=GROUPset group ownership, instead of process’ current group
-m, --mode=MODEset permission mode (as in chmod), instead of rwxr-xr-x
-o, --owner=OWNERset ownership (super-user only)
-p, --preserve-timestampsapply access/modification times of SOURCE files to corresponding destination files
-s, --stripstrip symbol tables
-t, --target-directory=DIRECTORYcopy all SOURCE arguments into DIRECTORY
-v, --verboseprint the name of each created file or directory

kill

terminate a process Usage: kill [-signal|-s signal|-p] [-q value] [-a] [--timeout milliseconds signal] [--] pid|name...

Options

OptionDescription
-s, --signal signalThe signal to send. It may be given as a name or a number.
-p, --pidOnly print the process ID (PID) of the named processes, do not send any signals.
--verbosePrint PID(s) that will be signaled with kill along with the signal.

ln

make links between files Usage: ln [OPTION]... TARGET LINK_NAME

Options

OptionDescription
-s, --symbolicmake symbolic links instead of hard links
-t, --target-directory=DIRECTORYspecify the DIRECTORY in which to create the links
-v, --verboseprint name of each linked file

ls

list directory contents Usage: ls [OPTION]... [FILE]...

Options

OptionDescription
-a, --alldo not ignore entries starting with .
-h, --human-readablewith -l print sizes like 1K 234M 2G etc
-I, --ignore=PATTERNdo not list implied entries matching shell PATTERN
-luse a long listing format
-r, --reversereverse order while sorting
-R, --recursivelist subdirectories recursively

mkdir

make directories Usage: mkdir [OPTION]... DIRECTORY...

Options

OptionDescription
-m, --mode=MODEset file mode (as in chmod), not a=rwx - umask
-p, --parentsno error if existing, make parent directories as needed, with their file modes unaffected by any -m option.
-v, --verboseprint a message for each created directory

mkfifo

make FIFOs (named pipes) Usage: mkfifo [OPTION]... NAME...

mv

move (rename) files Usage: mv [OPTION]... SOURCE... DIRECTORY

Options

OptionDescription
-bmake a backup of each existing destination file
-S, --suffix=SUFFIXoverride the usual backup suffix
-t, --target-directory=DIRECTORYcopy all SOURCE arguments into DIRECTORY
-v, --verboseprint the name of each created file or directory

nl

number lines of files Usage: nl [FILE]...

nproc

print the number of processing units available Usage: nproc

pwd

print name of current/working directory Usage: pwd

passwd

Change a users password Usage: passwd [user]

print resolved symbolic links or canonical file names Usage: readlink [OPTION]... FILE...

Options

OptionDescription
-f, --canonicalizecanonicalize by following every symlink in every component of the given name recursively; all but the last component must exist
-e, --canonicalize-existingcanonicalize by following every symlink in every component of the given name recursively, all components must exist
-m, --canonicalize-missingcanonicalize by following every symlink in every component of the given name recursively, without requirements on components existence
-n, --no-newlinedo not output the trailing delimiter

realpath

print the resolved path Usage: realpath [OPTION]... FILE...

Options

OptionDescription
-e, --canonicalize-existingall components of the path must exist
-m, --canonicalize-missingno path components need exist or be a directory
-L, --logicalresolve ’..’ components before symlinks
--relative-to=DIRprint the resolved path relative to DIR
--relative-base=DIRprint absolute paths unless paths below DIR
-s, --strip, --no-symlinksdon’t expand symlinks

rm

remove files or directories Usage: rm [OPTION]... [FILE]...

Options

OptionDescription
-f, --forceignore nonexistent files and arguments, never prompt
-iprompt before every removal
--one-file-systemwhen removing a hierarchy recursively, skip any directory that is on a file system different from that of the corresponding command line argument
-r, -R, --recursiveremove directories and their contents recursively
-d, --dirremove empty directories
-v, --verboseexplain what is being done

rmdir

remove empty directories Usage: rmdir [OPTION]... DIRECTORY...

Options

OptionDescription
-p, --parentsremove DIRECTORY and its ancestors; e.g., ‘rmdir -p a/b’ is similar to ‘rmdir a/b a’
-v, --verboseoutput a diagnostic for every directory processed

seq

print a sequence of numbers Usage:

  • seq [OPTION]... LAST
  • seq [OPTION]... FIRST LAST
  • seq [OPTION]... FIRST INCREMENT LAST

Options

OptionDescription
-f, --format=FORMATuse printf style floating-point FORMAT
-s, --separator=STRINGuse STRING to separate numbers (default: \n)
-w, --equal-widthequalize width by padding with leading zeroes

shred

overwrite a file to hide its contents, and optionally delete it Usage: shred [OPTION]... FILE...

Options

OptionDescription
-f, --forcechange permissions to allow writing if necessary
-n, --iterations=Noverwrite N times instead of the default (3)
--random-source=FILEget random bytes from FILE

shuf

generate random permutations Usage: shuf [OPTION]... [FILE]

Options

OptionDescription
-i, --input-range=LO-HItreat each number LO through HI as an input line
-n, --head-count=COUNToutput at most COUNT lines
-o, --output=FILEwrite result to FILE instead of standard output
--random-source=FILEget random bytes from FILE
-r, --repeatoutput lines can be repeated

sleep

delay for a specified amount of time Usage: sleep NUMBER[SUFFIX]...

sort

sort lines of text files Usage: sort [OPTION]... [FILE]...

Options

OptionDescription
-b, --ignore-leading-blanksignore leading blanks
-d, --dictionary-orderconsider only blanks and alphanumeric characters
-f, --ignore-casefold lower case to upper case characters
-g, --general-numeric-sortcompare according to general numerical value
-i, --ignore-nonprintingconsider only printable characters
-M, --month-sortcompare (unknown) < ‘JAN’ < … < ‘DEC’
-h, --human-numeric-sortcompare human readable numbers (e.g., 2K 1G)
-n, --numeric-sortcompare according to string numerical value
-r, --reversereverse the result of comparisons

split

split a file into pieces Usage: split [OPTION]... [FILE [PREFIX]]

Options

OptionDescription
-a, --suffix-length=Ngenerate suffixes of length N (default 2)
--additional-suffix=SUFFIXappend an additional SUFFIX to file names
-b, --bytes=SIZEput SIZE bytes per output file
-C, --line-bytes=SIZEput at most SIZE bytes of records per output file
-duse numeric suffixes starting at 0, not alphabetic
--numeric-suffixes[=FROM]same as -d, but allow setting the start value
-xuse hex suffixes starting at 0, not alphabetic
--hex-suffixes[=FROM]same as -x, but allow setting the start value
-l, --lines=NUMBERput NUMBER lines/records per output file
-n, --number=CHUNKSgenerate CHUNKS output files; see explanation below
--verboseprint a diagnostic just before each output file is opened

stat

display file or file system status Usage: stat [OPTION]... FILE...

Options

OptionDescription
-L, --dereferencefollow links
-f, --file-systemdisplay file system status instead of file status
-c --format=FORMATuse the specified FORMAT instead of the default; output a newline after each use of FORMAT

Format Modifiers

FormatDescription
%apermission bits in octal (note ’#’ and ‘0’ printf flags)
%Apermission bits and file type in human readable form
%bnumber of blocks allocated (see %B)
%Bthe size in bytes of each block reported by %b
%CSELinux security context string
%ddevice number in decimal (st_dev)
%Ddevice number in hex (st_dev)
%Hdmajor device number in decimal
%Ldminor device number in decimal
%fraw mode in hex
%Ffile type
%ggroup ID of owner
%Ggroup name of owner
%hnumber of hard links
%iinode number
%mmount point
%nfile name
%Nquoted file name with dereference if symbolic link
%ooptimal I/O transfer size hint
%stotal size, in bytes
%rdevice type in decimal (st_rdev)
%Rdevice type in hex (st_rdev)
%Hrmajor device type in decimal, for character/block device special files
%Lrminor device type in decimal, for character/block device special files
%tmajor device type in hex, for character/block device special files
%Tminor device type in hex, for character/block device special files
%uuser ID of owner
%Uuser name of owner
%wtime of file birth, human-readable; - if unknown
%Wtime of file birth, seconds since Epoch; 0 if unknown
%xtime of last access, human-readable
%Xtime of last access, seconds since Epoch
%ytime of last data modification, human-readable
%Ytime of last data modification, seconds since Epoch
%ztime of last status change, human-readable
%Ztime of last status change, seconds since Epoch
%afree blocks available to non-superuser
%btotal data blocks in file system
%ctotal file nodes in file system
%dfree file nodes in file system
%ffree blocks in file system
%ifile system ID in hex
%lmaximum length of filenames
%nfile name
%sblock size (for faster transfers)
%Sfundamental block size (for block counts)
%tfile system type in hex
%Tfile system type in human readable form

tac

concatenate and print files in reverse Usage: tac [FILE]...

tail

output the last part of files Usage: tail [OPTION]... [FILE]...

Options

OptionDescription
-c, --bytes=[+]NUMoutput the last NUM bytes; or use -c +NUM to output starting with byte NUM of each file
-foutput appended data as the file grows;
-n, --lines=[+]NUMoutput the last NUM lines, instead of the last 10; or use -n +NUM to skip NUM-1 lines at the start
--pid=PIDwith -f, terminate after process ID, PID dies

tee

read from standard input and write to standard output and files Usage: tee [OPTION]... [FILE]...

Options

OptionDescription
-a, --appendappend to the given FILEs, do not overwrite

touch

change file timestamps Usage: touch [OPTION]... FILE...

Options

OptionDescription
-achange only the access time
-c, --no-createdo not create any files
-d, --date=STRINGparse STRING and use it instead of current time
-r, --reference=FILEuse this file’s times instead of current time

tr

translate or delete characters Usage: tr [OPTION]... STRING1 [STRING2]

Options

OptionDescription
-d, --deletedelete characters in STRING1, do not translate

true

do nothing, successfully Usage: true

truncate

shrink or extend the size of a file to the specified size Usage: truncate OPTION... FILE...

Options

OptionDescription
-c, --no-createdo not create any files
-r, --reference=RFILEbase size on RFILE
-s, --size=SIZEset or adjust the file size by SIZE bytes

uname

print system information Usage: uname [OPTION]...

Options

OptionDescription
-a, --allprint all information
-s, --kernel-nameprint the kernel name
-n, --nodenameprint the network node hostname
-r, --kernel-releaseprint the kernel release
-v, --kernel-versionprint the kernel version
-m, --machineprint the machine hardware name

uniq

report or omit repeated lines Usage: uniq [OPTION]... [INPUT [OUTPUT]]

Options

OptionDescription
-c, --countprefix lines by the number of occurrences
-d, --repeatedonly print duplicate lines, one for each group
-i, --ignore-caseignore differences in case when comparing
-s, --skip-chars=Navoid comparing the first N characters
-u, --uniqueonly print unique lines

uptime

Tell how long the system has been running Usage: uptime [options]

Options

OptionDescription
-p, --prettyshow uptime in pretty format
-s, --sincesystem up since, in yyyy-mm-dd HH:MM:SS format

wc

print newline, word, and byte counts for each file Usage: wc [OPTION]... [FILE]...

Options

OptionDescription
-c, --bytesprint the byte counts
-m, --charsprint the character counts
-l, --linesprint the newline counts
-w, --wordsprint the word counts

whoami

print effective user name Usage: whoami