103 GNU and Unix Commands KT Flashcards
(95 cards)
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]]