Brainscape Linux Flashcards

1
Q

how do you specify a delimiter, also, what is the default delimiter if not specified

A

-d, –delimiter (e.g. “cut -d ‘,’”) tab is default

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

what are the three ways you can specify what is to be sliced

A

-b, –bytes -c, –characters -f, –fields

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

how do you select the inverse the fields you specify (e.g. everything but)

A

–complement

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

how do you ignore any lines that don’t contain the delimiter character

A

-s, –only-delimited

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

how do you specify a different delimiter for the OUTPUT of what is cut

A

–output-delimiter=STRING

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

how do you specify the following: from N to end of line from beginning of line to M from N to M columns 2 through four and column 6

A

N- -M N-M 2-4,6

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

are ranges inclusive or exclusive

A

ranges are inclusive

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

what do fields begin counting from

A

fields begin at at “1” for cut

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

using sed, double space a file

A

sed G

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

using sed, double space a file that already has blank lines in it (the output should have no more than one blank line between lines of text)

A

sed ‘/^$/d;G’ (delete any lines that meet the address flag of being blank, and double space file)

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

using sed, undo double-spacing (assuming even-numbered lines are always blank)

A

sed ‘n;d’

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

using sed, convert Unix format (LF) to DOS format (CRLF)

A

sed ‘s/$/\r/’

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

using sed, delete leading whitespace (tabs, spaces) from beginning of each line

A

sed ‘s/^[ \t]*//’

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

using sed, delete trailing whitespace (tabs, spaces) from each end of line

A

sed ‘s/[ \t]*$//’

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

using sed, replace only the first instance in each line

A

sed ‘s/foo/bar/’

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

using sed, replace only the fourth instance in each line

A

sed ‘s/foo/bar/4’

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

using sed, replace all instances in a line

A

sed ‘s/foo/bar/g’

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

using sed, substitute “foo” with “bar” ONLY for lines which contain “baz”

A

sed ‘/baz/s/foo/bar/g’

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

using sed, substitute “foo” with “bar” EXCEPT for lines which contain “baz”

A

sed ‘/baz/!s/foo/bar/g’

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

using sed, change “scarlet” or “ruby” or “puce” to “red”

A

sed ‘s/scarlet|ruby|puce/red/g’

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

using sed, add a blank line every 5 lines (after lines 5, 10, 15, 20, etc.)

A

sed ‘1~5G’

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

using sed, print the first 10 lines of file (emulate “head”), print the first line of the file

A

sed 10q (remember that “q” will print the current pattern space before quitting sed q)

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

using sed, print only lines which match regular expression (emulate “grep”)

A

sed -n ‘/regexp/p’ OR sed ‘/regexp/!d’

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

using sed, print only lines that do NOT match regexp (emulate “grep -v”)

A

sed -n ‘/regexp/!p’ OR sed ‘/regexp/d’

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

using sed, print all of file EXCEPT section between 2 regular expressions

A

sed ‘/Iowa/,/Montana/d’

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

using sed, delete lines matching pattern

A

sed ‘/pattern/d’

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

using sed, add a leading angle bracket and space to each line (quote a message)

A

sed ‘s/^/> /’

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

using sed, delete leading angle bracket & space from each line (unquote a message)

A

sed ‘s/^> //’

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

sed command: q

A

print current pattern space and quit

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

sed command: d

A

delete current pattern space and immediately start next cycle

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

sed command: p

A

print the current pattern space (usually used in conjunction with “-n” option)

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

sed command: n

A

print pattern space (or not, if auto-print is disabled), and replace the pattern space with the next line of input (mnemonic: “next”)

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

sed command: { and }

A

groups of commands can be enclosed between curly braces–this can be helpful when using addresses for multiple commands

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

sed command: “a text”

A

append “text” after a line (at the end of the cycle), ignoring leading whitespace (text to add is read to the end of the line)

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

sed command: “i text”

A

same as “a text”, but inserts text BEFORE the line

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

sed command: “c text”

A

change text (same as “a text”, except that this one deletes lines matching the address or address-range, and puts “text” in their place)

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

sed command: =

A

print the current line number, with a trailing newline

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

sed command: “r filename”

A

read filename and insert at end of cycle

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

sed command: “w filename”

A

write the pattern space to filename (file will be created (or overwritten) at the beginning of the script, and all “w” commands pointed to the same filename will be appended to the file throughout the script)

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

sed command: D

A

delete text in the pattern space up to the first newline, and start a new cycle without reading a new line of input (if only one line in pattern space, works just like lower-case “d”)

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

sed command: N

A

add a newline and append the next line of input to pattern space (no more input, exit without processing any more commands)

42
Q

sed command: P

A

print pattern space up to the first newline

43
Q

sed command: h

A

overwrite the hold space with the contents of the pattern space

44
Q

sed command: H

A

append a newline to hold space and append current pattern space to hold space

45
Q

sed command: g

A

write the hold space into pattern space (overwrites) (mnemonic: “Go to the pattern space”)

46
Q

sed command: G

A

append newline to pattern space and add contents of hold space

47
Q

sed command: x

A

swap contents of the hold and pattern spaces

48
Q

sed command: “: label”

A

create a label for future branch commands

49
Q

sed command: “b label”

A

branch unconditionally to label; if label is omitted, just start next cycle

50
Q

sed command: “t label”

A

branch to label only if there has been a successful substitution since the last input line was read or conditional branch was taken (if label is omitted, just start the next cycle)

51
Q

sed command: l (lower-case “L”)

A

unambiguously print the pattern space (useful for debugging)

52
Q

sed command: s///g

A

search and replace, all matches in line

53
Q

sed command: s///2

A

replace only the second occurrence in each line

54
Q

sed command: s///p

A

print the pattern space if the substitution was made

55
Q

sed command: s///w file.txt

A

write result to file if successful substitution was made (will append subsequent references to the same file)

56
Q

sed command: s///i

A

make regexp case-insensitive (can be lowercase or uppercase “i”)

57
Q

sed command: s///i2w file.txt

A

You can specify more than one flag (this one will be case-insensitive, sub the second match on a line, and write result to file).

58
Q

sed addressing: delete line three

A

3d

59
Q

sed addressing: delete last line in stream

A

$d

60
Q

sed addressing: delete all lines that are NOT the last line

A

$!d

61
Q

sed addressing: match every “stepth” line, starting with “first”

A

first~step

62
Q

sed addressing: delete lines matching regexp, also, how to use a different character for regexp addresses

A

/regexp/d \%regexp%d

63
Q

sed addressing: case-insensitive regexp

A

/regexp/I (must be uppercase)

64
Q

sed addressing: multi-line mode regexp

A

/regexp/M (must be uppercase)

65
Q

how to use the delimiter character in a regexp

A

escape it with a backslash

66
Q

sed addressing: reuse the last-used regexp

A

use address of “//” (works both for addressing and for the “s” command!)

67
Q

sed addressing: print lines four through six

A

sed -n ‘4,6p’

68
Q

what will the following print and why: seq 10 | sed -n ‘4,/[0-9]/p’

A

It will print “4” and “5”. This is because regular expression matching begins only on the line after the first address.

69
Q

sed addressing: match address and the “N” lines following the first address

A

address,+N e.g. ‘6,+2’ or ‘/hey/,+2’ (address can be either a number or a regular expression)

70
Q

sed options: suppress automatic printing of pattern space

A

-n, –quiet, –silent

71
Q

sed options: edit file in-place (and make backup if SUFFIX supplied)

A

-i [SUFFIX], –in-place[=SUFFIX]

72
Q

sed options: use extended regular expressions instead of basic (ERE vs BRE)

A

-E, -r, –regexp-extended

73
Q

sed options: add a short script of sed commands from the command line

A

-e (e.g. “sed -e ‘1d’ -e ‘2s/a/b/’”)

74
Q

add the contents of a script file to the commands being executed

A

-f script-file, –file=script-file

75
Q

what is the difference between BRE and ERE regular expressions

A

In the POSIX standard, Basic Regular Syntax (BRE) requires that the metacharacters ? + | ( ) and { } and | must be escaped to make them special (e.g. () and {}), whereas Extended Regular Syntax (ERE) does not.

76
Q

how to simulate “-n” right from within a Sed script

A

first two characters in file “#n”

77
Q

using sed, make to work on each file separately (rather than as one continuous stream of concatenated files)

A

specify the -s, –separate option

78
Q

using sed, convert DOS format (CRLF) to Unix format (LF)

A

sed ‘s/\r$//’

79
Q

create a gzip/bzip2/xz compressed archive

A

tar czvf/cjvf/cJvf compressed.tar.gz/bz2/xz directory

80
Q

peek inside a gzip/bzip2/xz compressed archive

A

tar tzvf/tjvf/tJvf compressed.tar.gz/bz2/xz

81
Q

extract a gzip/bzip2/xz compressed archive

A

tar xzvf/xjvf/xJvf compressed.tar.gz/bz2/xz

82
Q

what are the options you can use for compression using tar (short and long)

A

z –gzip j –bzip2 J –xz

83
Q

tar argument used to specify output archive file name

A

f FILE, –file=FILE

84
Q

tar function to create a new archive

A

c, –create

85
Q

tar option to be verbose

A

v, –verbose

86
Q

tar function to list the contents of an archive

A

t, –list (mnemonic “Tell me what’s in this archive”)

87
Q

tar function to extract files from an archive

A

x, –extract, –get

88
Q

tar function to append other TAR files to an existing archive

A

A, –catenate, –concatenate

89
Q

tar function to calculate differences between the archive and the file system

A

d, –diff, –compare

90
Q

tar function to append files to the end of a tar archive

A

r, –append (mnemonic: “r” is at the end of the word “tar”, and this command will append a file to the end of the archive)

91
Q

tar function to append files, but only those that are newer than the copy in the archive

A

u, –update

92
Q

what is the difference between –append and –update in tar

A

–append adds the files no matter what, whereas –update only adds them if the files are newer than those in archive

93
Q

tar option to infer type of compression to use based on the file extension you use

A

-a, –autocompress (or –no-auto-compress to explicitly turn off this behavior)

94
Q

tar option to exclude certain files or folders from the backup

A

–exclude=PATTERN (patterns are case sensitive by default; use –ignore-case to change this)

95
Q

tar option to exclude version control system directories

A

–exclude-vcs

96
Q

tar option to explicitly not overwrite existing files when extracting

A

k, –keep-old-files

97
Q

tar option to not overwrite any files that are newer than the archived copies (when extracting)

A

–keep-newer-files

98
Q

tar option to display its default options

A

–show-default

99
Q

tar option to exclude files and patterns LISTED IN A FILE instead of from command line

A

-X, –exclude-from=FILE

100
Q

when listing or extracting with tar, list each directory that does not match search criteria

A

–show-omitted-dirs

101
Q

how to replace a file in an archive with a different copy

A

delete the file first using “tar –delete –file=archive.tar file1”, then use append to add the new file (tar does not delete any files from archive automatically)

102
Q

what is the basic tar syntax

A

tar {function} [options] [pathname …] (e.g. tar af archive.tar fileone.txt filetwo.txt), so one of the tar functions (e.g. –create, –update, –extract, etc.) has to be first in line for your arguments