103 GNU and Unix Commands KT Flashcards

1
Q

103.1 Work on the command line

A

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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

bash

A

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]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

echo

A

Command: Echo the STRING(s) to standard output.

echo [SHORT-OPTION]… [STRING]…
echo LONG-OPTION

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

env

A

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]…]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

export

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

pwd

A

Command: Print the full filename of the current working directory.

pwd [OPTION]…

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

set

A

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 …]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

unset

A

Command: Unset values and attributes of shell variables and functions. For each NAME, remove the corresponding variable or function.

unset [-f] [-v] [-n] [name …]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

type

A

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 …]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

which

A

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 …

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

man

A

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…

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

uname

A

Command: Print certain system information. With no OPTION, same as -s.

-s, –kernel-name
print the kernel name

uname [OPTION]…

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

history

A

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…]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

.bash_history

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Quoting


\

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

103.2 Process text streams using filters

A

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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

bzcat

A

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]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

cat

A

Command: Concatenate FILE(s) to standard output.

cat [OPTION]… [FILE]…

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

cut

A

Command: Print selected parts of lines from each FILE to standard output.

cut OPTION… [FILE]…

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

head

A

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]…

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

less

A

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]…

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

md5sum

A

Command: Print or check MD5 (128-bit) checksums.

md5sum [OPTION]… [FILE]…

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

nl

A

Command: Write each FILE to standard output, with line numbers added.

nl [OPTION]… [FILE]…

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

od

A

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]]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

paste

A

Command: Write lines consisting of the sequentially corresponding lines from each FILE, separated by TABs, to standard output.

paste [OPTION]… [FILE]…

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

sed

A

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]…

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

sha256sum

A

Command: Print or check SHA256 (256-bit) checksums.

sha256sum [OPTION]… [FILE]…

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

sha512sum

A

Command: Print or check SHA512 (512-bit) checksums.

sha512sum [OPTION]… [FILE]…

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

sort

A

Command: Write sorted concatenation of all FILE(s) to standard output.

sort [OPTION]… [FILE]…
sort [OPTION]… –files0-from=F

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

split

A

Command: Output pieces of FILE to PREFIXaa, PREFIXab, …; default size is 1000 lines, and default PREFIX is ‘x’.

split [OPTION]… [FILE [PREFIX]]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

tail

A

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]…

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

tr

A

Command: Translate, squeeze, and/or delete characters from standard input, writing to standard output.

tr [OPTION]… SET1 [SET2]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

uniq

A

Command: Filter adjacent matching lines from INPUT (or standard input), writing to OUTPUT (or standard output).

uniq [OPTION]… [INPUT [OUTPUT]]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

wc

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

xzcat

A

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]…

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

zcat

A

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 … ]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

103.3 Perform basic file management

A

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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

cp

A

Command: Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.

cp [OPTION]… [-T] SOURCE DEST
cp [OPTION]… SOURCE… DIRECTORY

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

find

A

Command: GNU find searches the directory tree rooted at each given starting-point by evaluating the given expression from left to right, according to the rules of precedence until the outcome is known, at which point find moves on to the next file name.

find [-H] [-L] [-P] [-D debugopts] [-Olevel] [starting-point…] [expression]

40
Q

mkdir

A

Command: Create the DIRECTORY(ies), if they do not already exist.

mkdir [OPTION]… DIRECTORY…

41
Q

mv

A

Command: Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.

mv [OPTION]… [-T] SOURCE DEST
mv [OPTION]… SOURCE… DIRECTORY
mv [OPTION]… -t DIRECTORY SOURCE…

42
Q

ls

A

Command: List information about the FILEs (the current directory by default). Sort entries alphabetically if none of -cftuvSUX nor –sort is specified.

ls [OPTION]… [FILE]…

43
Q

rm

A

Command: rm removes each specified file. By default, it does not remove directories.

rm [OPTION]… [FILE]…

44
Q

rmdir

A

Command: Remove the DIRECTORY(ies), if they are empty.

rmdir [OPTION]… DIRECTORY…

45
Q

touch

A

Command: Update the access and modification times of each FILE to the current time. A FILE argument that does not exist is created empty, unless -c or -h is supplied.

touch [OPTION]… FILE…

46
Q

tar

A

Command: GNU tar is an archiving program designed to store multiple files in a single file (an archive), and to manipulate such archives.

tar {A|c|d|r|t|u|x}[GnSkUWOmpsMBiajJzZhPlRvwo] [ARG…]
tar -A [OPTIONS] ARCHIVE ARCHIVE
tar –create [–file ARCHIVE] [OPTIONS] [FILE…]

47
Q

cpio

A

Command: GNU cpio copies files between archives and directories.

cpio -o < name-list [> archive]
cpio -p destination-directory < name-list

48
Q

dd

A

Command: Copy a file, converting and formatting according to the operands.

dd [OPERAND]…
dd OPTION

49
Q

file

A

Command: file tests each argument in an attempt to classify it. There are three sets of tests, performed in this order: filesystem tests, magic tests, and language tests. The first test that succeeds causes the file type to be printed.

file [OPTION…] [FILE…]

50
Q

gzip

A

Command: Gzip reduces the size of the named files using Lempel-Ziv coding (LZ77). Whenever possible, each file is replaced by one with the extension .gz, while keeping the same ownership modes, access and modification times.

gzip [OPTION]… [FILE]…
gzip [ -acdfhklLnNrtvV19 ] [-S suffix] [ name … ]

51
Q

gunzip

A

Command: gunzip can currently decompress files created by gzip, zip, compress, compress -H or pack. The detection of the input format is automatic.

gunzip [ -acfhklLnNrtvV ] [-S suffix] [ name … ]
/usr/bin/gunzip [OPTION]… [FILE]…

52
Q

bzip2

A

Command: bzip2 compresses files using the Burrows-Wheeler block sorting text compression algorithm, and Huffman coding. Compression is generally considerably better than that achieved by more conventional LZ77/LZ78-based compressors, and approaches the performance of the PPM family of statistical compressors.

bzip2 [ -cdfkqstvzVL123456789 ] [ filenames … ]

53
Q

bunzip2

A

Command: bunzip2 (or bzip2 -d) decompresses all specified files. Files which were not created by bzip2 will be detected and ignored, and a warning issued.

bunzip2 [ -fkvsVL ] [ filenames … ]

54
Q

xz

A

Command: xz is a general-purpose data compression tool with command line syntax similar to gzip(1) and bzip2(1).
The native file format is the .xz format, but the legacy .lzma format used by LZMA Utils and raw compressed streams with no container format headers are also supported.

xz [option…] [file…]

55
Q

unxz

A

Command: Alias used to decompress FILEs in the .xz format. unxz stems from the xz command.

unxz is equivalent to xz –decompress.

unxz [OPTION]… [FILE]…

56
Q

file globbing

A

File globbing is the operation that recognises wildcard patterns and does the job of file path expansion. Here is an example of some wildcards it accepts:

* - represents zero or more characters
? - represents a single character
[] - represents a range of characters
57
Q

103.4 Use streams, pipes and redirects

A

The following is a partial list of the used files, terms and utilities:

tee
xargs

58
Q

tee

A

Command: Copy standard input to each FILE, and also to standard output.

tee [OPTION]… [FILE]…

59
Q

xargs

A

Command: xargs reads items from the standard input, delimited by blanks (which can be protected with double or single quotes or a backslash) or newlines, and executes the command (default is /bin/echo) one or more times with any initial-arguments followed by items read from standard input.

xargs [options] [command [initial-arguments]]

60
Q

103.5 Create, monitor and kill processes

A

The following is a partial list of the used files, terms and utilities:

&amp;
bg
fg
jobs
kill
nohup
ps
top
free
uptime
pgrep
pkill
killall
watch
screen
tmux
61
Q

&

A

Runs a job in the background when added at the end of a command line.

sleep 100 &

62
Q

bg

A

Command: Move jobs to the background.

bg [job_spec …]

63
Q

fg

A

Command: Move job to the foreground.

fg [job_spec …]

64
Q

jobs

A

Command: Lists the active jobs. JOBSPEC restricts output to that job. Without options, the status of all active jobs is displayed.

jobs [-lnprs] [jobspec …]
jobs -x command [args]

65
Q

kill

A

Command: Send the processes identified by PID or JOBSPEC the signal named by SIGSPEC or SIGNUM. If neither SIGSPEC nor SIGNUM is present, then SIGTERM is assumed.

kill [options] […]

66
Q

nohup

A

Command: Run COMMAND, ignoring hangup signals.

nohup COMMAND [ARG]…
nohup OPTION

67
Q

ps

A

Command: ps displays information about a selection of the active processes.

ps [options]

68
Q

top

A

Command: top provides a dynamic real-time view of a running system.

It can display system summary information as well as a list of processes or threads currently being managed by the Linux kernel.

top -hv|-bcEHiOSs1 -d secs -n max -u|U user -p pid -o fld -w [cols]

69
Q

free

A

Command: free displays the total amount of free and used physical and swap memory in the system, as well as the buffers and caches used by the kernel.

free [options]

70
Q

uptime

A

Command: uptime gives a one line display of the following information. The current time, how long the system has been running, how many users are currently logged on, and the system load averages for the past 1, 5, and 15 minutes.

uptime [options]

71
Q

pgrep

A

Command: pgrep looks through the currently running processes and lists the process IDs which match the selection criteria to stdout. All the criteria have to match.

pgrep [options] pattern

72
Q

pkill

A

Command: pkill looks through the currently running processes and will send the specified signal (by default SIGTERM) to each process that matches the criteria. It will not list them on stdout.

pkill [options] pattern

73
Q

killall

A

Command: killall sends a signal to all processes running any of the specified commands. If no signal name is specified, SIGTERM is sent.

killall [ -Z CONTEXT ] [ -u USER ] [ -y TIME ] [ -o TIME ] [ -eIgiqrvw ] [ -s SIGNAL | -SIGNAL ] NAME…

74
Q

watch

A

Command: watch runs a command repeatedly, displaying its output and errors (the first screenfull).

watch [options] command

75
Q

screen

A

Command: Screen is a full-screen window manager that multiplexes a physical terminal between several processes (typically interactive shells).

screen [ -options ] [ cmd [ args ] ]

76
Q

tmux

A

Command: tmux is a terminal multiplexer: it enables a number of terminals to be created, accessed, and controlled from a single screen.

tmux [-28lquvV] [-c shell-command] [-f file] [-L socket-name] [-S socket-path] [command [flags]]

77
Q

103.6 Modify process execution priorities

A

The following is a partial list of the used files, terms and utilities:

nice
ps
renice
top

78
Q

nice

A

Command: Run COMMAND with an adjusted niceness, which affects process scheduling. With no COMMAND, print the current niceness.

Niceness values range from -20 (most favorable to the process) to 19 (least favorable to the process).

nice [OPTION] [COMMAND [ARG]…]

79
Q

ps

A

Command: ps displays information about a selection of the active processes.

ps [options]

80
Q

renice

A

Command: renice alters the scheduling priority of one or more running processes.

renice [-n] [-p|–pid] …
renice [-n] -g|–pgrp …
renice [-n] -u|–user …

81
Q

top

A

Command: top provides a dynamic real-time view of a running system.

It can display system summary information as well as a list of processes or threads currently being managed by the Linux kernel.

top -hv|-bcEHiOSs1 -d secs -n max -u|U user -p pid -o fld -w [cols]

82
Q

103.7 Search text files using regular expressions

A

The following is a partial list of the used files, terms and utilities:

grep
egrep
fgrep
sed
regex(7)
83
Q

grep

A

Command: grep searches for PATTERNS in each FILE. PATTERNS is one or patterns separated by newline characters, and grep prints each line that matches a pattern.

grep [OPTION…] PATTERNS [FILE…]
grep [OPTION…] -e PATTERNS … [FILE…]
grep [OPTION…] -f PATTERN_FILE … [FILE…]

84
Q

egrep

A

Command: egrep interprets PATTERNS as extended regular expressions and is a variant of grep. egrep is the same as grep -E. The -E option is as follows:
-E, –extended-regexp

egrep [OPTION…] PATTERNS [FILE…]

85
Q

fgrep

A

Command: fgreg interprets PATTERNS as fixed strings, not regular expressions. and is a variant of grep. fgrep is the same as grep -F. The -F option is as follows:
-F, –fixed-strings

fgrep [OPTION…] PATTERNS [FILE…]

86
Q

sed

A

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]…

87
Q

regex(7)

A

Regular expressions (“RE”s), come in two forms: modern REs and obsolete REs.

A (modern) RE is one(!) or more nonempty(!) branches, separated by ‘|’. It matches anything that matches one of the branches.
A branch is one(!) or more pieces, concatenated. It matches a match for the first, followed by a match for the second, and so on.
A piece is an atom possibly followed by a single(!) ‘’, ‘+’, ‘?’, or bound. An atom followed by ‘’ matches a sequence of 0 or more matches of the atom.
A bound is ‘{‘ followed by an unsigned decimal integer, possibly followed by ‘,’ possibly followed by another unsigned decimal integer, always followed by ‘}’.

Obsolete (“basic”) regular expressions differ in several respects. ‘|’, ‘+’, and ‘?’ are ordinary characters and there is no equivalent for their functionality.

For more: man regex.7

88
Q

103.8 Basic file editing

A

Terms and Utilities:

vi
/, ?
h,j,k,l
i, o, a
d, p, y, dd, yy
ZZ, :w!, :q!
EDITOR
89
Q

vi

A

Editor launched from the command line: vi (visual) utility is a screen-oriented text editor.

vi [−rR] [−c command] [−t tagstring] [−w size] [file…]

90
Q

vi editor commands

/, ?

A
/ = Repeat previous search forward
? = Repeat previous search backward
91
Q

vi editor commands

h,j,k,l

A
h = Left
j = Down
k = Up
l = Right
92
Q

vi editor commands

i, o, a

A
i = Insert text before cursor
o = Open new line for text below cursor
a = Insert text after cursor
93
Q

vi editor commands

d, p, y, dd, yy

A
d = Deletes characters and lines in the direction of choice. Choices are h, j, k, l. 
p = Paste buffer contents.
y = Copies(Yank) a single character after the cursor into the buffer.
dd = Deletes a current line.
yy = Copies a current line into the buffer.
94
Q

vi editor commands

ZZ, :w!, :q!

A
ZZ = Write the file and quit.
\:w! = Write the file overriding protection.
\:q! = Quit the file overriding protection.
95
Q

EDITOR

A
Enables the editing of files. Some examples are:
vi
vim
nano
emacs