Brainscape Linux Flashcards

(102 cards)

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
using sed, print all of file EXCEPT section between 2 regular expressions
sed '/Iowa/,/Montana/d'
26
using sed, delete lines matching pattern
sed '/pattern/d'
27
using sed, add a leading angle bracket and space to each line (quote a message)
sed 's/^/> /'
28
using sed, delete leading angle bracket & space from each line (unquote a message)
sed 's/^> //'
29
sed command: q
print current pattern space and quit
30
sed command: d
delete current pattern space and immediately start next cycle
31
sed command: p
print the current pattern space (usually used in conjunction with "-n" option)
32
sed command: n
print pattern space (or not, if auto-print is disabled), and replace the pattern space with the next line of input (mnemonic: "next")
33
sed command: { and }
groups of commands can be enclosed between curly braces--this can be helpful when using addresses for multiple commands
34
sed command: "a text"
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)
35
sed command: "i text"
same as "a text", but inserts text BEFORE the line
36
sed command: "c text"
change text (same as "a text", except that this one deletes lines matching the address or address-range, and puts "text" in their place)
37
sed command: =
print the current line number, with a trailing newline
38
sed command: "r filename"
read filename and insert at end of cycle
39
sed command: "w filename"
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)
40
sed command: D
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")
41
sed command: N
add a newline and append the next line of input to pattern space (no more input, exit without processing any more commands)
42
sed command: P
print pattern space up to the first newline
43
sed command: h
overwrite the hold space with the contents of the pattern space
44
sed command: H
append a newline to hold space and append current pattern space to hold space
45
sed command: g
write the hold space into pattern space (overwrites) (mnemonic: "Go to the pattern space")
46
sed command: G
append newline to pattern space and add contents of hold space
47
sed command: x
swap contents of the hold and pattern spaces
48
sed command: ": label"
create a label for future branch commands
49
sed command: "b label"
branch unconditionally to label; if label is omitted, just start next cycle
50
sed command: "t label"
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
sed command: l (lower-case "L")
unambiguously print the pattern space (useful for debugging)
52
sed command: s///g
search and replace, all matches in line
53
sed command: s///2
replace only the second occurrence in each line
54
sed command: s///p
print the pattern space if the substitution was made
55
sed command: s///w file.txt
write result to file if successful substitution was made (will append subsequent references to the same file)
56
sed command: s///i
make regexp case-insensitive (can be lowercase or uppercase "i")
57
sed command: s///i2w file.txt
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
sed addressing: delete line three
3d
59
sed addressing: delete last line in stream
$d
60
sed addressing: delete all lines that are NOT the last line
$!d
61
sed addressing: match every "stepth" line, starting with "first"
first~step
62
sed addressing: delete lines matching regexp, also, how to use a different character for regexp addresses
/regexp/d \%regexp%d
63
sed addressing: case-insensitive regexp
/regexp/I (must be uppercase)
64
sed addressing: multi-line mode regexp
/regexp/M (must be uppercase)
65
how to use the delimiter character in a regexp
escape it with a backslash
66
sed addressing: reuse the last-used regexp
use address of "//" (works both for addressing and for the "s" command!)
67
sed addressing: print lines four through six
sed -n '4,6p'
68
what will the following print and why: seq 10 | sed -n '4,/[0-9]/p'
It will print "4" and "5". This is because regular expression matching begins only on the line *after* the first address.
69
sed addressing: match address and the "N" lines following the first address
address,+N e.g. '6,+2' or '/hey/,+2' (address can be either a number or a regular expression)
70
sed options: suppress automatic printing of pattern space
-n, --quiet, --silent
71
sed options: edit file in-place (and make backup if SUFFIX supplied)
-i [SUFFIX], --in-place[=SUFFIX]
72
sed options: use extended regular expressions instead of basic (ERE vs BRE)
-E, -r, --regexp-extended
73
sed options: add a short script of sed commands from the command line
-e (e.g. "sed -e '1d' -e '2s/a/b/'")
74
add the contents of a script file to the commands being executed
-f script-file, --file=script-file
75
what is the difference between BRE and ERE regular expressions
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
how to simulate "-n" right from within a Sed script
first two characters in file "#n"
77
using sed, make to work on each file separately (rather than as one continuous stream of concatenated files)
specify the -s, --separate option
78
using sed, convert DOS format (CRLF) to Unix format (LF)
sed 's/\r$//'
79
create a gzip/bzip2/xz compressed archive
tar czvf/cjvf/cJvf compressed.tar.gz/bz2/xz directory
80
peek inside a gzip/bzip2/xz compressed archive
tar tzvf/tjvf/tJvf compressed.tar.gz/bz2/xz
81
extract a gzip/bzip2/xz compressed archive
tar xzvf/xjvf/xJvf compressed.tar.gz/bz2/xz
82
what are the options you can use for compression using tar (short and long)
z --gzip j --bzip2 J --xz
83
tar argument used to specify output archive file name
f FILE, --file=FILE
84
tar function to create a new archive
c, --create
85
tar option to be verbose
v, --verbose
86
tar function to list the contents of an archive
t, --list (mnemonic "Tell me what's in this archive")
87
tar function to extract files from an archive
x, --extract, --get
88
tar function to append other TAR files to an existing archive
A, --catenate, --concatenate
89
tar function to calculate differences between the archive and the file system
d, --diff, --compare
90
tar function to append files to the end of a tar archive
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
tar function to append files, but only those that are newer than the copy in the archive
u, --update
92
what is the difference between --append and --update in tar
--append adds the files no matter what, whereas --update only adds them if the files are newer than those in archive
93
tar option to infer type of compression to use based on the file extension you use
-a, --autocompress (or --no-auto-compress to explicitly turn off this behavior)
94
tar option to exclude certain files or folders from the backup
--exclude=PATTERN (patterns are case sensitive by default; use --ignore-case to change this)
95
tar option to exclude version control system directories
--exclude-vcs
96
tar option to explicitly *not* overwrite existing files when extracting
k, --keep-old-files
97
tar option to not overwrite any files that are newer than the archived copies (when extracting)
--keep-newer-files
98
tar option to display its default options
--show-default
99
tar option to exclude files and patterns LISTED IN A FILE instead of from command line
-X, --exclude-from=FILE
100
when listing or extracting with tar, list each directory that does *not* match search criteria
--show-omitted-dirs
101
how to replace a file in an archive with a different copy
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
what is the basic tar syntax
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