CLI Flashcards

1
Q

What is Bash?

A

Bash is an sh-compatible shell that allows us to run complex commands and perform different tasks from a terminal window. It incorporates useful features from both the KornShell and C shell.

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

How to view content of given enviroment variables?

A

echo $PATH

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

Useful enviroment variables

A

$USER
$PWD
$HOME

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

How to display the process ID of the current shell instance?

A

echo “$$”

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

What “export” command does?

A

The export command makes the variable accessible to any subprocesses we might spawn from our current Bash instance. If we set an environment variable without export it will only be available in the current shell.

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

How to view enviroment variables defined by default in Linux?

A

By env command.

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

How to check history of commands that have been entered?

A

By history command.

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

How to re-run first command from your history?

A

!1

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

How to repeat last command that was executed during terminal session?

A

!!

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

Where is command history saved to?

A

.bash_history in the user home directory.

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

Two enviroment variables control the history size

A

HISTSIZE and HISTFILESIZE

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

HISTSIZE

A

Controls the number of commands stored in memory for the current session.

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

HISTFILESIZE

A

Configures how many commands are kept in the history file.

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

How to invoke reverse-i-search facility?

A

CTRL + R

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

How to inspect your bash history?

A

By history command

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

How to use history expansion to re-run a command from it?

A

!number

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

Standard Input (STDIN)

A

Data fed into the program

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

Standard Output (STDOUT)

A

Output from the program (defaults to terminal)

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

Standard Error (STDERR)

A

Error messages (defaults to terminal)

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

Standard Error (STDERR)

A

Error messages (defaults to terminal)

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

Piping operator

A

|

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

Redirection Operators

A

<>

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

Which operator is used to save the output to a file to keep it for future?

A

>

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

How to save “test” string to file “redirection_test.txt”?

A

echo “test” > redirection_test.txt

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

Which operand is used to append additional data to an existing file?

A

> >

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

How to append two lines of strings, to one file names “redirection_test.txt”?

A

echo “1”&raquo_space; redirection_test.txt

echo “2”&raquo_space; redirection_test.txt

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

What is doing “wc” command?

A

Print newline, word, and byte counts for each file.

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

How to redirect standard error (STDERR) to file?

A

ls ./test 2>error.txt

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

File Descriptor for STDIN?

A

0

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

File Descriptor for STDOUT?

A

1

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

File Descriptor for STDERR?

A

2

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

What is POSIX?

A

Portable Operating System Interface for UNIX

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

How to count by “wc” file.txt and return the data to “count.txt” using piping?

A

cat file.txt | wc -m > count.txt

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

How to use a cat command in conjuction with sort to reorder the content of the /etc/passwd?

A

sudo cat /etc/passwd | sort 1>passwd.txt

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

Text Searching and Manipulation main commands

A

grep
sed
cut
awk

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

What is regular expression?

A

A regular expression is a special text string for describing a search pattern.

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

What is grep?

A

In a nutshell, grep searches text files for the occurrence of a given regular expression and outputs any line containing a match to the standard output, which is usually the terminal screen.

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

grep -r stands for?

A

Recursive searching

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

grep -i stands for?

A

Ignore test case.

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

How to list all files in the /usr/bin directory and pipe the output, which searches for any line containing the string “zip”?

A

ls -la /usr/bin | grep zip

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

What is sed?

A

Sed is a powerful stream editor. It is also very complex. At a very high level, sed performs text editing on a stream of text, either a set of specific files or standard output.

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

How to create a stream of text “I need to try hard”?

A

echo “I need to try hard”

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

How to replace word “hard” with “harder” by sed?

A

sed ‘s/hard/harder/’

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

How to create a stream of text “I need to try harder” using the echo command and then pipe it to sed in order to replace the word “hard” with “harder”?

A

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

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

What is cut?

A

The cut command is simple, but often comes in quite handy. It is used to extract a section of text from a line and output it to the standard output.

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

Most commonly-used switches for cut?

A
  • f

- d

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

What -f switch means in cut command?

A

Field Number

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

What -d switch means in cut command?

A

Field Delimiter

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

How to extract list of users on Linux system?

A

cut -d “:” -f 1 /etc/passwd

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

What is the output of this command?

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

A

web apps

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

What is the field delimiter in this command?

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

A

(,)

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

What is AWK?

A

AWK is a programming language designed for text processing and is typically used as a data extraction and reporting tool. It is also extremely powerful and can be quite complex.

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

Commonly used switch with AWK?

A

-F

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

What is -F switch in awk?

A

Field separator, and the print command, which outputs the result text.

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

What is the output of this command?

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

A

hello friend

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

What is the difference between cut and awk?

A

Awk is much more flexible.

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

What does the head command do?

A

The head command displays the first 10 lines in a file.

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

What does wc -l command do?

A

Display the total number of lines in a file.

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

What gunzip command do?

A

Comrpess or expand files.

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

Gunzip alternatives

A

gzip, zcat

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

How to unzip “access_log.txt.gz”

A

gunzip access_log.txt.gz

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

How to print first 10 lines of file “access.log”?

A

head access.log

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

What sort -u do?

A

Sorts and showing only unique lines.

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

What does uniq command do?

A

Report or omit repeated lines.

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

What the -c option for uniq do?

A

This will prefix the output line with the number of occurrences.

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

What command using /etc/passwd, extract the user and home directory fields for all users on your Linux.

A

cat /etc/passwd | awk -F “:” ‘{print “The user “ $1, “ home directory is “ $6}’

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

How to copy the /etc/passwd file to your home directory (/home/kali)?

A

cp /etc/passwd /home/kali/passwd

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

How to use cat in a one-liner to print the output of the /kali/passwd and replace all instances of the “Light Display Manager” string with “LDM”.

A

cat passwd | sed -i ‘s/Light Display Manager/LDM/g’ passwd

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

Linux Text Editors

A

gedit
leafpad
nano
vi

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

What is nano?

A

Nano is one of the simplest-to-use text editors.

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

What does CTRL + O shortcut in nano?

A

Write changes to the file.

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

What does CTRL + K shortcut in nano?

A

Cut the current line.

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

What does CTRL + U shortcut in nano?

A

Un-cut a line and paste it at the cursor location.

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

What does CTRL + W shortcut in nano?

A

Search.

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

What does CTRL + X shortcut in nano?

A

Exit.

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

What is vi?

A

Vi is an extremely powerful text editor, capable of blazing speed especially when it comes to automating repetitive tasks. However, it has a relatively steep learning curve and is nowhere near as simple to use as Nano.

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

How to enable insert-text mode to begin typing in vi?

A

Press I key and start typing away.

78
Q

How to disable insert-text mode and go back to command mode?

A

Press the ESC key.

79
Q

What does dd in command mode in vi?

A

Delete the current line.

80
Q

What does yy in command mode in vi?

A

Copy the current line.

81
Q

What does p in command mode in vi?

A

Paste the clipboard contents.

82
Q

What does x in command mode in vi?

A

Delete the current character.

83
Q

What does :w in command mode in vi?

A

Write the current file to disk and stay in vi.

84
Q

What does :q! in command mode in vi?

A

Quit without writing the file to disk.

85
Q

What does :wq in command mode in vi?

A

Save and quit.

86
Q

Why use vi?

A

Vi can save a great deal of time in the hands of experienced user and vi is installed on every POSIX-compliant system.

87
Q

What does comm command?

A

Comm command compares two text files, displaying the lines that are unique to each one, as well as the lines they have in common. It outputs three space-offset columns: the first contains lines that are unique to the first file or argument; the second contains lines that are unique to the second file or argument; and the third column contains lines that are shared by both files. The -n switch, where “n” is either 1, 2, or 3, can be used to suppress one or more columns, depending on the need.

88
Q

How to scan with comm two text files “scan-a.txt”, “scan-b.txt” and check uniques?

A

comm scan-a.txt scan-b.txt

89
Q

How to scan with comm two text files “scan-a.txt”, “scan-b.txt” and display only the lines that were found in both files?

A

comm -12 scan-a.txt scan-b.txt

90
Q

What is diff comand used to?

A

The diff command is used to detect differences between files, similar to the comm command. However, diff is much more complex and supports many output formats.

91
Q

Two of the most popular formats of diff?

A
context format (-c)
unified format (-u)
92
Q

The most notable difference between unified and context format?

A

The most notable difference between these formats is that the unified format does not show lines that match between files, making the results shorter. The indicators have identical meaning in both formats.

93
Q

What does vimdiff?

A

Vimdiff opens vim with multiple files, one in each window. The differences between files are highlighted, which makes it easier to visually inspect them.

94
Q

What do shortcut in vim does?

A

Gets changes from the other window into the current one.

95
Q

What dp shortcut in vim does?

A

Puts the changes from the current window into the other one.

96
Q

What ]c shortcut in vim does?

A

Jumps to the next change.

97
Q

What [c shortcut in vim does?

A

Jumps to the previous change.

98
Q

What CTRL + W shortcut in vim does?

A

Switches to the other split window.

99
Q

How to check two text files “scan-a.txt” and “scan-b.txt” with vimdiff?

A

vimdiff scan-a.txt scan-b.txt

100
Q

What is PID?

A

Process ID

101
Q

How to create a backgrounding process?

A

Append ampersand to the end of the command.

102
Q

How to sent 400 ICMP echo requests to the local interface with the ping command and wrote the results to a file called ping_results.txt using backgrounding processes?

A

ping -c 400 localhost > ping_results.txt &

103
Q

What is a shortcut for canceling operations in Terminal?

A

CTRL + C

104
Q

What is the shortcut to suspend a job in Terminal?

A

CTRL + Z

105
Q

What is the shortcut to suspend a job in Terminal?

A

CTRL + Z

106
Q

How to check backgrounding processes?

A

By bg command.

107
Q

How to quickly check the status of ICMP echo requests?

A

By “jobs” and “fg” commands.

108
Q

What is “jobs” command used to?

A

To look at jobs.

109
Q

What is “fg” command used to?

A

To bring one job into the foreground.

110
Q

What the “^C” character represents?

A

Keystroke combination CTRL + C.

111
Q

By which shortcut can we terminate a long-running process and regain control of the terminal?

A

CTRL + C

112
Q

One of the most useful commands to monitor processes on mostly any Unix-like operating system?

A

ps (short for process status).

113
Q

What ps do?

A

ps lists processes systemwide, not only for the current terminal session.

114
Q

What are the first things to check after obtaining remote access to a system?

A

Understand what software is currently running on the compromised machine. This could
help us elevate our privileges or collect additional information in order to acquire further access
into the network.

115
Q

What the -e option do in ps?

A

Select all processes.

116
Q

What the -f option do in ps?

A

Display full format listing (UID, PID, PPID, etc.)

117
Q

What the -C option do in ps?

A

Select by command name.

118
Q

How to stop the Leafpad process without interacting with the GUI?

A

kill leafpad_pid

119
Q

What kill command do?

A

Send a specific signal to a process.

120
Q

What is the default signal to kill?

A

SIGTERM (request termination).

121
Q

How to run a command in the background?

A

bigjob &

122
Q

How to find files that have changed on your Kali virtual machine within the past 7 days?

A

find / -mtime -7

123
Q

How to find files that have changed on your Kali virtual machine within the past 7 days by running a
specific command in the background?

A

find / -mtime -7 &

124
Q

How to find files and directories modified more than n days ago?

A

find / -mtime +n

125
Q

How to find the files and directories modified less than n days ago?

A

find / -mtime -n

126
Q

How to get the files modified on ‘2019-07-24’?

A

find . -type f -newermt 2019-07-24 ! -newermt 2019-07-25

127
Q

How to show the long format of the files and to sort the output by modification time by ls?

A

ls -lt

128
Q

How to filter listing based on a specific date or time by applying the grep command by date?

A

ls -lt | grep ‘Jul 27’

129
Q

How to filter listing based on a specific date or time by applying the grep command by time?

A

ls -lt | grep ‘17:’

130
Q

How to enable the recursive capability on the ls command?

A

ls -R

131
Q

How to check “Firefox” PID?

A

ps -ef | grep firefox

132
Q

How to terminate Firefox via CLI using its PID?

A

kill firefox_process_id

133
Q

Commands to monitor files and commands in real-time.

A

tail and watch.

134
Q

What tail command do?

A

The most common use of tail is to monitor log file entries as they are being written. For example, we may want to monitor the Apache logs to see if a web server is being contacted by a given client we are attempting to attack via a client-side exploit.

135
Q

What -f option in tail do?

A

The -f option (follow) is very useful as it continuously updates the output as the target file grows.

136
Q

What -nX option in tail do?

A

-nX, which outputs the last “X” number of lines, instead of the default value of 10.

137
Q

What the watch command is used to?

A

The watch command is used to run a designated command at regular intervals.

138
Q

Which option specify different intervals for watch?

A

-n X option to have it run every “X” number of seconds.

139
Q

How to list logged-in users?

A

By “w” command.

140
Q

How to list logged-in users once every 5 seconds?

A

watch -n 5 w

141
Q

How to start apache2 web service?

A

sudo systemctl start apache2

142
Q

How to monitor apache2 access.log file in real-time?

A

watch tail /var/log/apache2/access.log

143
Q

How to use a combination of watch and ps to monitor the most CPU-intensive processes on your
Kali machine in a terminal window?

A

watch “ps aux | sort -nrk 3,3”

144
Q

Commands for downloading files?

A

wget
curl
axel

145
Q

What is wget command doing?

A

Downloads files using the HTTP/HTTPS and FTP protocols.

146
Q

What “wget -O” does?

A

Downloads files using the HTTP/HTTPS and FTP protocols. “wget” along with the -O switch save the destination
file with a different name on the local machine.

147
Q

What is curl?

A

curl is a tool to transfer data to or from a server using a host of protocols including IMAP/S, POP3/S, SCP, SFTP, SMB/S, SMTP/S, TELNET, TFTP, and others. A penetration tester can use this to download or upload files and build complex requests.

148
Q

What is axel?

A

axel is a download accelerator that transfers a file from a FTP or HTTP server through multiple connections.

149
Q

For what “-n” option in “axel” is used?

A

-n is used to specify the number of multiple connections to use.

150
Q

For what “-a” option in “axel” is used?

A

For a more concise progress indicator.

151
Q

For what “-o” option in “axel” is used?

A

To specify a different file name for the downloaded file.

152
Q

Using “axel” initialise 20 multiple connections and save the file named “report.pdf” from the link “https://www.facebook.com/reports/report.pdf”.

A

axel -a -n 20 -o report.pdf https://www.facebook.com/reports/report.pdf

153
Q

Using “curl” download the file from the link “https://facebook.com/report/report.pdf” and save it under the name “report.pdf”.

A

curl -o report.pdf https://facebook.com/report/report.pdf

154
Q

Using “wget” download the file from the link “https://facebook.com/report/report.pdf” and save it under the name “report_wget.pdf”.

A

wget -O report_wget.pdf https://facebook.com/report/report.pdf

155
Q

What is PoC code?

A

PoC code is a term used to describe a code that was developed to demonstrate security flaws in software or networks during a PoC exploit. IT departments use it to simulate attacks to identify vulnerabilities and patch them. PoC code can also be used to determine a threat level.

156
Q

Where can you download the PoC code for an exploit?

A

https://www.exploit-db.com

157
Q

By which commands can you download an exploit from exploit-db?

A

curl
wget
axel

158
Q

What is HISTCONTROL?

A

The HISTCONTROL variable defines whether or not to remove duplicate commands, commands that begin with spaces from the history, or both. By default, both are removed but you may find it more useful to only omit duplicates.

159
Q

How to use HISTCONTROL to remove duplicates from bash history?

A

export HISTCONTROL=ignoredups

160
Q

What the HISTIGNORE is for?

A

The HISTIGNORE variable is particularly useful for filtering out basic commands that are run frequently, such as ls, exit, history, bg, etc.

161
Q

How to use HISTIGNORE to filter basic, common commands? E.g. ls, pwd, history, exit, bg.

A

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

162
Q

What the HISTTIMEFORMAT do?

A

HISTTIMEFORMAT controls date and/or time stamps in the output of the history command.

163
Q

How to use HISTTIMEFORMAT to include the date/time in bash history.

A

export HISTTIMEFORMAT=’%F %T ‘

164
Q

What %F stands for in HISTTIMEFORMAT?

A

Year-Month-Day ISO 8601 format

165
Q

What %T stands for in HISTTIMEFORMAT?

A

24-hour time

166
Q

Where can you search for time formats for history command?

A

man history 3

167
Q

What is alias?

A

An alias is a string we can define that replaces a command name. Aliases are useful for replacing commonly-used commands and switches with a shorter command, or alias, that we define. In other words, an alias is a command that we define ourselves, built from other commands.

168
Q

How to replace “ls -la” command by “lsa” using “alias”?

A

alias lsa=’ls -la’

169
Q

How to define your own command “lsa” which is doing “ls” but with “-la” option without having to type any arguments at all?

A

alias lsa=’ls -la’

170
Q

How to check the list of defined aliases?

A

alias

171
Q

How to unset an alias “mkdir”?

A

unalias mkdir

172
Q

The behavior of interactive shells in Bash is determined by the system-wide _ file?

A

bashrc

173
Q

Where bashrc is located?

A

In /etc/bash.bashrc.

174
Q

How to override system-wide Bash settings?

A

Edit .bashrc file.

175
Q

When .bashrc script is executed?

A

Everytime user logs in.

176
Q

What type of file is .bashrc?

A

Shell script.

177
Q

What is the default path of .bashrc?

A

/home/kali/.bashrc

178
Q

How to examine the .bashrc default file?

A

cat ~/.bashrc

179
Q

How to create an alias named “..” to change to the parent directory and make it persistent across terminal sessions?

A

Add in .bashrc alias ..=”cd ..”

180
Q

How to permanently configure the history command to store 10000 entries and include full date in its output?

A

Add to .bashrc “export HISTSIZE=10000” and “export HISTTIMEOFRMAT=’%F %T ‘”

181
Q

How to print PATH enviroment variable?

A

echo $PATH

182
Q

How to print USER enviroment variable?

A

echo $USER

183
Q

How to print PWD enviroment variable?

A

echo $PWD

184
Q

How to print HOME enviroment variable?

A

echo $HOME

185
Q

What is sed?

A

Stream editor.

186
Q

Print “hello::there::friend” and print only “hello friend” using echo and awk.

A

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

187
Q

How to count lines in “access.log” file?

A

wc -l access.log

188
Q

How to count lines in “access.log” file?

A

wc -l access.log

189
Q

How to list all jobs running in current session?

A

jobs

190
Q

How to continue second stopped job?

A

fg %2