Chapter 3: Command Line Fun Flashcards

1
Q

How do you view the PATH variable?

A

echo $PATH

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

How do you view the USER variable?

A

echo $USER

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

How do you view the HOME variable?

A

echo $HOME

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

What is the export command?

A

The export command defines a variable.

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

Why is the export command useful?

A

If we don’t want to repeatedly type out some sort of string, for example an IP address, the export command allows us to define a variable.

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

How do you define a variable using export?

A

E.g. export b=192.168.116.114

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

How do you then use that variable in a practical example?

A

ping -c 10 $b

The variable must have a $ accompanying it.

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

What command and variable do we use to view the current PID (Process ID) of the bash shell?

A

echo “$$”

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

How do we view all environment variables?

A

env

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

How do we view command history?

A

history

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

After viewing the history, what is a fast way to execute a command?

A

Using the numbers next to the command, type !3 (for example).

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

Where is all command history saved?

A

In the .bash_history file.

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

What two variables dictate the command history save?

A

HISTSIZE and HISTFILESIZE

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

What does HISTSIZE do?

A

Controls the number of commands kept for the current session.

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

What does HISTFILESIZE do?

A

Configures how many commands are kept in the overall history file.

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

Where are HISTSIZE and HISTFILESIZE stored?

A

.bashrc - bash configuration file

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

How do we use the reverse-i-search facility?

A

Ctrl + R

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

What are the three data streams connected to the programs run through bash?

A
Standard Input (STDIN)
Standard Output (STDOUT)
Standard Error (STDERR)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

How is piping related to the data streams?

A

Piping connects the data streams between programs and files.

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

What command counts the words and lines of a document?

A

wc

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

What is the command for counting the number of lines in a document?

A

wc -l

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

What is the command for counting the number of characters in a document?

A

wc -m

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

How do you create a new document through redirecting data streams?

A

echo “hello bob” > redirection.txt

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

How do you append data using data streams?

A

echo “hello jane”&raquo_space; redirection.txt

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

What are the file descriptors for STDIN, STDOUT and STDERR respectively?

A

0, 1 and 2 respectively.

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

How do we redirect error messages?

A

After a command, use 2>error.txt as an example.

Another example is 2>/dev/null - which is a file used for discard error output.

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

What is an example of piping a command?

A

cat error.txt | wm -m > count.txt

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

What does the grep command do?

A

Searches for a line containing a given string of text.

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

What does the i switch for grep do?

A

Ignores text case in strings.

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

What does the r switch for grep do?

A

Searches recursively through a file or directory.

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

What does sed do?

A

sed is a stream editor that performs editing functions on a stream of text.

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

Use an example of the sed command and explain the components.

A

echo ‘I need to try hard’ | sed ‘s/hard/harder/’

The single quote starts the argument. s means substitute, hard is the word to replace and harder is the word to replace it with.

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

What does the cut command do?

A

The cut command extracts a section of text from a line and outputs it to standard output.

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

What does the d switch do in cut?

A

The d switch defines the delimiter.

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

What does the f switch do in cut?

A

The f switch defines the field number of the line to cut.

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

Use cut in an example.

A

echo “I hack binaries,web apps,mobile apps, and just about anything else” | cut -d “,” -f 2

the output is “web apps”

37
Q

What is awk?

A

awk is a data extraction and reporting tool similar to cut.

38
Q

How do we define a field separator (delimiter) in awk?

A

-F

39
Q

How do we print which field in awk?

A

‘{print $1, $3}’

40
Q

Use awk in an example.

A

echo “hello::there::friend” | awk -F “::” ‘{print $1, $3}’

41
Q

What is the main difference between awk and cut?

A

Cut can only use one character as a delimiter while awk can use multiple.

42
Q

What does the sort command do?

A

sort the output.

43
Q

What does the uniq command with a c switch do?

A

uniq -c will prefix each line with the number of occurances.

44
Q

How do we write changes to nano?

A

Ctrl + O

45
Q

How do we cut the current line in nano?

A

Ctrl + K

46
Q

How do we uncut the current line and paste in nano?

A

Ctrl + U

47
Q

How do you search in nano?

A

Ctrl + W

48
Q

How do you exit nano?

A

Ctrl + X

49
Q

How do you enter insert mode in vi?

A

i

50
Q

How do you go back to command mode in vi?

A

esc

51
Q

In what mode in vi do you need to be in in order to copy, paste and so on?

A

command mode

52
Q

How do you copy the current line in vi?

A

yy

53
Q

How do you paste a line you copied in vi?

A

p

54
Q

How do you delete a current character in vi?

A

x

55
Q

In vi how do you write the current file to disk (save) and stay in vi?

A

:w

56
Q

In vi how do you quit without saving?

A

:q!

57
Q

In vi how do you save and quit?

A

:wq

58
Q

How do you use compare files using comm?

A

comm

59
Q

When reading the output for comm, how do you interpret the results?

A

The first column consists of data unique to the first file. The second column consists of data unique to the second file.
The third column consists of data contained in both files.

60
Q

How do we suppress output in comm?

A

comm -12 will suppress output in the first two columns.

61
Q

How do you use vimdiff to compare files?

A

vimdiff

62
Q

How do you extract files using tar?

A

tar -zxvf scans.tar.gz

63
Q

Explain jobs within a linux kernel.

A

The kernel manages multitasking through the use of processes. The kernel keeps information about each process to keep things organised and assigns each process an identifier or PID.

64
Q

How do we background a job?

A

While running a command append an ampersand or ‘&’ (no quotes) to the end of it. You’ll then be given a PID.

65
Q

How do we suspend a job?

A

Ctrl + Z

66
Q

Once a job is suspended, how do you resume it in the background?

A

bg

67
Q

How do you view jobs currently running or suspended?

A

jobs

68
Q

What command will send a job to the foreground?

A

fg %1 where 1 is the job number

69
Q

What is ps and how is it different to the jobs command?

A

ps lists processes running system-wide, not just in the current session like jobs.

70
Q

How do we view all system wide processes with full formatting?

A

ps -ef

71
Q

If we are looking for a certain process, how do we use the ps command to narrow down the results?

A

ps -fC

72
Q

How do we kill a process?

A

After running ps -ef, find the PID number and use the kill command on the number.

73
Q

What does the tail command do?

A

tail monitors log entries as they are being written.

74
Q

How can we use tail?

A

sudo tail -f /var/log/apache2/access.log

75
Q

What do the -f and -nX switches in tail do?

A

-f is used to follow a file as it’s updated. -nX is used to output the last X lines instead of the default 10.

76
Q

What does the watch command do?

A

the watch command runs a designated command at regular intervals. by default it runs every 2 seconds.

77
Q

How do we specify a different interval when using watch?

A

we use the -n X option to have it run every X seconds

78
Q

Use an example of wget.

A

wget -O hello.txt www.offensive-security.com/pdf/file.txt

79
Q

What protocols can curl use as opposed to wget?

A

wget can only use http, https and ftp while curl can use IMAP/S,
POP3/S, SCP, SFTP, SMB/S, SMTP/S, TELNET, TFTP.
curl is a lot more versatile.

80
Q

Use an example of curl.

A

curl -O hello.txt www.google.com/drive/dog.txt

81
Q

What does the HISTCONTROL variable do?

A

defines whether or not to remove duplicate commands, commands
that begin with spaces from the history, or both

82
Q

How can we use the HISTCONTROL variable to remove duplicates?

A

export HISTCONTROL=ignoredups

83
Q

What does the HISTIGNORE variable do?

A

filtering out basic commands that are used frequently such as cd, ls, pwd etc.

84
Q

How do we use HISTIGNORE?

A

export HISTIGNORE=”&:ls:[bf]g:exit:history”

85
Q

What is an alias?

A

An alias is a string that replaces a command that we define ourself.

86
Q

How is an alias different to a variable?

A

An alias utilises a string to execute a command with it’s switches and arguments.
A variable is a string.

87
Q

Demonstrate the use of an alias command.

A

alias lsa=’ls -la’

88
Q

Alias don’t have any restrictions. For example, if mkdir was accidently aliased as ping -c 400 localhost, the consequences would be a lose of function. How do we counter this?

A

Either exit the bash session or use unalias mkdir.

89
Q

If we want an alias to be persistent, what do we do?

A

Place the alias into the .bashrc file in the /home/kali directory.