103 GNU and Unix Commands KT Flashcards
103.1 Work on the command line
The following is a partial list of the used files, terms and utilities:
bash echo env export pwd set unset type which man uname history .bash_history Quoting
bash
Command: Bash (Bourne Again SHell) is an sh-compatible command language interpreter that executes commands read from the standard input or from a file. Bash also incorporates useful features from the Korn and C shells (ksh and csh).
bash [options] [command_string | file]
echo
Command: Echo the STRING(s) to standard output.
echo [SHORT-OPTION]… [STRING]…
echo LONG-OPTION
env
Command: Set each NAME to VALUE in the environment and run COMMAND. Run a program in a modified environment.
env [OPTION]… [-] [NAME=VALUE]… [COMMAND [ARG]…]
export
Command: Set export attribute for shell variables. Marks each NAME for automatic export to the environment of subsequently executed commands. If VALUE is supplied, assign VALUE before exporting.
export [-fn] [name[=value] …]
export -p
pwd
Command: Print the full filename of the current working directory.
pwd [OPTION]…
set
Command: Set or unset values of shell options and positional parameters. Change the value of shell attributes and positional parameters, or display the names and values of shell variables.
set [-abefhkmnptuvxBCHP] [-o option-name] [–] [arg …]
unset
Command: Unset values and attributes of shell variables and functions. For each NAME, remove the corresponding variable or function.
unset [-f] [-v] [-n] [name …]
type
Command: Display information about command type. For each NAME, indicate how it would be interpreted if used as a command name.
type [-afptP] name [name …]
which
Command: which returns the pathnames of the files (or links) which would be executed in the current environment, had its arguments been given as commands in a strictly POSIX-conformant shell. It
does this by searching the PATH for executable files matching the names of the arguments. It does not canonicalize path names.
which [-a] filename …
man
Command: man is the system’s manual pager. Each page argument given to man is normally the name of a program, utility or function. The manual page associated with each of these arguments is then found and displayed.
man [OPTION…] [SECTION] PAGE…
uname
Command: Print certain system information. With no OPTION, same as -s.
-s, –kernel-name
print the kernel name
uname [OPTION]…
history
Command: The GNU History library is able to keep track of those lines, associate arbitrary data with each line, and utilize information from previous lines in composing new ones.
history [-c] [-d offset] [n] or history -anrw [filename]
history -ps arg [arg…]
.bash_history
File that stores a history of commands executed by a user.
It can generally be found in the users home directory:
~/home/user/.bash_history
Quoting
“
‘
\
Unix Shell provides various metacharacters which have special meaning while using them in any Shell Script and causes termination of a word unless quoted.
The double quote ( “quote” ) protects everything enclosed between two double quote marks except $, ‘, “ and .Use the double quotes when you want only variables and command substitution.
- Variable - Yes
- Wildcards - No
- Command substitution - yes
The single quote ( ‘quote’ ) protects everything enclosed between two single quote marks. It is used to turn off the special meaning of all characters.
- Variable - No
- Wildcards - No
- Command substitution - No
Use backslash to change the special meaning of the characters or to escape special characters within the text such as quotation marks.
103.2 Process text streams using filters
The following is a partial list of the used files, terms and utilities:
bzcat cat cut head less md5sum nl od paste sed sha256sum sha512sum sort split tail tr uniq wc xzcat zcat
bzcat
Command: bzcat (or bzip2 -dc) decompresses all specified files to the standard output.
- d –decompress
- c –stdout
bzcat [flags and input files in any order]
cat
Command: Concatenate FILE(s) to standard output.
cat [OPTION]… [FILE]…
cut
Command: Print selected parts of lines from each FILE to standard output.
cut OPTION… [FILE]…
head
Command: Print the first 10 lines of each FILE to standard output. With more than one FILE, precede each with a header giving the file name.
head [OPTION]… [FILE]…
less
Command: less is a filter for paging through text one screenful at a time. Less is a program similar to more (1), but it has many more features. Less does not have to read the entire input file before starting, so with large input files it starts up faster than other text editors.
less [filename]…
md5sum
Command: Print or check MD5 (128-bit) checksums.
md5sum [OPTION]… [FILE]…
nl
Command: Write each FILE to standard output, with line numbers added.
nl [OPTION]… [FILE]…
od
Command: Write an unambiguous representation, octal bytes by default, of FILE to standard output. With more than one FILE argument, concatenate them in the listed order to form the input.
od [OPTION]… [FILE]…
od [-abcdfilosx]… [FILE] [[+]OFFSET[.][b]]
paste
Command: Write lines consisting of the sequentially corresponding lines from each FILE, separated by TABs, to standard output.
paste [OPTION]… [FILE]…
sed
Command: Sed is a stream editor. A stream editor is used to perform basic text transformations on an input stream (a file or input from a pipeline).
sed [OPTION]… {script-only-if-no-other-script} [input-file]…
sha256sum
Command: Print or check SHA256 (256-bit) checksums.
sha256sum [OPTION]… [FILE]…
sha512sum
Command: Print or check SHA512 (512-bit) checksums.
sha512sum [OPTION]… [FILE]…
sort
Command: Write sorted concatenation of all FILE(s) to standard output.
sort [OPTION]… [FILE]…
sort [OPTION]… –files0-from=F
split
Command: Output pieces of FILE to PREFIXaa, PREFIXab, …; default size is 1000 lines, and default PREFIX is ‘x’.
split [OPTION]… [FILE [PREFIX]]
tail
Command: Print the last 10 lines of each FILE to standard output. With more than one FILE, precede each with a header giving the file name.
tail [OPTION]… [FILE]…
tr
Command: Translate, squeeze, and/or delete characters from standard input, writing to standard output.
tr [OPTION]… SET1 [SET2]
uniq
Command: Filter adjacent matching lines from INPUT (or standard input), writing to OUTPUT (or standard output).
uniq [OPTION]… [INPUT [OUTPUT]]
wc
Command: Print newline, word, and byte counts for each FILE, and a total line if more than one FILE is specified. A word is a non-zero-length sequence of characters delimited by white space.
wc [OPTION]… [FILE]…
wc [OPTION]… –files0-from=F
xzcat
Command: xzcat is an alias of the xz utility. It is a basic way of doing the following commands:
xz –decompress –stdout.
xz -dc
xzcat [OPTION]… [FILE]…
zcat
Command: Uncompress FILEs to standard output. zcat is identical to gunzip -c. (On some systems, zcat may be installed as gzcat to preserve the original link to compress.)
/usr/bin/zcat [OPTION]… [FILE]…
zcat [ -fhLV ] [ name … ]
103.3 Perform basic file management
The following is a partial list of the used files, terms and utilities:
cp find mkdir mv ls rm rmdir touch tar cpio dd file gzip gunzip bzip2 bunzip2 xz unxz file globbing
cp
Command: Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.
cp [OPTION]… [-T] SOURCE DEST
cp [OPTION]… SOURCE… DIRECTORY