103 GNU and Unix Commands KT Flashcards

(95 cards)

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
paste
Command: Write lines consisting of the sequentially corresponding lines from each FILE, separated by TABs, to standard output. paste [OPTION]... [FILE]...
26
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]...
27
sha256sum
Command: Print or check SHA256 (256-bit) checksums. sha256sum [OPTION]... [FILE]...
28
sha512sum
Command: Print or check SHA512 (512-bit) checksums. sha512sum [OPTION]... [FILE]...
29
sort
Command: Write sorted concatenation of all FILE(s) to standard output. sort [OPTION]... [FILE]... sort [OPTION]... --files0-from=F
30
split
Command: Output pieces of FILE to PREFIXaa, PREFIXab, ...; default size is 1000 lines, and default PREFIX is 'x'. split [OPTION]... [FILE [PREFIX]]
31
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]...
32
tr
Command: Translate, squeeze, and/or delete characters from standard input, writing to standard output. tr [OPTION]... SET1 [SET2]
33
uniq
Command: Filter adjacent matching lines from INPUT (or standard input), writing to OUTPUT (or standard output). uniq [OPTION]... [INPUT [OUTPUT]]
34
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
35
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]...
36
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 ... ]
37
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 ```
38
cp
Command: Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY. cp [OPTION]... [-T] SOURCE DEST cp [OPTION]... SOURCE... DIRECTORY
39
find
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
mkdir
Command: Create the DIRECTORY(ies), if they do not already exist. mkdir [OPTION]... DIRECTORY...
41
mv
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
ls
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
rm
Command: rm removes each specified file. By default, it does not remove directories. rm [OPTION]... [FILE]...
44
rmdir
Command: Remove the DIRECTORY(ies), if they are empty. rmdir [OPTION]... DIRECTORY...
45
touch
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
tar
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
cpio
Command: GNU cpio copies files between archives and directories. cpio -o < name-list [> archive] cpio -p destination-directory < name-list
48
dd
Command: Copy a file, converting and formatting according to the operands. dd [OPERAND]... dd OPTION
49
file
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
gzip
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
gunzip
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
bzip2
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
bunzip2
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
xz
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
unxz
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
file globbing
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
103.4 Use streams, pipes and redirects
The following is a partial list of the used files, terms and utilities: tee xargs
58
tee
Command: Copy standard input to each FILE, and also to standard output. tee [OPTION]... [FILE]...
59
xargs
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
103.5 Create, monitor and kill processes
The following is a partial list of the used files, terms and utilities: ``` & bg fg jobs kill nohup ps top free uptime pgrep pkill killall watch screen tmux ```
61
&
Runs a job in the background when added at the end of a command line. sleep 100 &
62
bg
Command: Move jobs to the background. bg [job_spec ...]
63
fg
Command: Move job to the foreground. fg [job_spec ...]
64
jobs
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
kill
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
nohup
Command: Run COMMAND, ignoring hangup signals. nohup COMMAND [ARG]... nohup OPTION
67
ps
Command: ps displays information about a selection of the active processes. ps [options]
68
top
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
free
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
uptime
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
pgrep
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
pkill
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
killall
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
watch
Command: watch runs a command repeatedly, displaying its output and errors (the first screenfull). watch [options] command
75
screen
Command: Screen is a full-screen window manager that multiplexes a physical terminal between several processes (typically interactive shells). screen [ -options ] [ cmd [ args ] ]
76
tmux
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
103.6 Modify process execution priorities
The following is a partial list of the used files, terms and utilities: nice ps renice top
78
nice
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
ps
Command: ps displays information about a selection of the active processes. ps [options]
80
renice
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
top
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
103.7 Search text files using regular expressions
The following is a partial list of the used files, terms and utilities: ``` grep egrep fgrep sed regex(7) ```
83
grep
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
egrep
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
fgrep
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
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]...
87
regex(7)
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
103.8 Basic file editing
Terms and Utilities: ``` vi /, ? h,j,k,l i, o, a d, p, y, dd, yy ZZ, :w!, :q! EDITOR ```
89
vi
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
vi editor commands | /, ?
``` / = Repeat previous search forward ? = Repeat previous search backward ```
91
vi editor commands | h,j,k,l
``` h = Left j = Down k = Up l = Right ```
92
vi editor commands | i, o, a
``` i = Insert text before cursor o = Open new line for text below cursor a = Insert text after cursor ```
93
vi editor commands | d, p, y, dd, yy
``` 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
vi editor commands | ZZ, :w!, :q!
``` ZZ = Write the file and quit. :w! = Write the file overriding protection. :q! = Quit the file overriding protection. ```
95
EDITOR
``` Enables the editing of files. Some examples are: vi vim nano emacs ```