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
Which operand is used to append additional data to an existing file?
>>
26
How to append two lines of strings, to one file names "redirection_test.txt"?
echo "1" >> redirection_test.txt | echo "2" >> redirection_test.txt
27
What is doing "wc" command?
Print newline, word, and byte counts for each file.
28
How to redirect standard error (STDERR) to file?
ls ./test 2>error.txt
29
File Descriptor for STDIN?
0
30
File Descriptor for STDOUT?
1
31
File Descriptor for STDERR?
2
32
What is POSIX?
Portable Operating System Interface for UNIX
33
How to count by "wc" file.txt and return the data to "count.txt" using piping?
cat file.txt | wc -m > count.txt
34
How to use a cat command in conjuction with sort to reorder the content of the /etc/passwd?
sudo cat /etc/passwd | sort 1>passwd.txt
35
Text Searching and Manipulation main commands
grep sed cut awk
36
What is regular expression?
A regular expression is a special text string for describing a search pattern.
37
What is grep?
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.
38
grep -r stands for?
Recursive searching
39
grep -i stands for?
Ignore test case.
40
How to list all files in the /usr/bin directory and pipe the output, which searches for any line containing the string "zip"?
ls -la /usr/bin | grep zip
41
What is sed?
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.
42
How to create a stream of text "I need to try hard"?
echo "I need to try hard"
43
How to replace word "hard" with "harder" by sed?
sed 's/hard/harder/'
44
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”?
echo "I need to try hard" | sed 's/hard/harder'
45
What is cut?
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.
46
Most commonly-used switches for cut?
- f | - d
47
What -f switch means in cut command?
Field Number
48
What -d switch means in cut command?
Field Delimiter
49
How to extract list of users on Linux system?
cut -d ":" -f 1 /etc/passwd
50
What is the output of this command? | echo "I hack binaries,web apps,mobile apps, and just about anything else"| cut -f 2 -d ","
web apps
51
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 ","
(,)
52
What is AWK?
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.
53
Commonly used switch with AWK?
-F
54
What is -F switch in awk?
Field separator, and the print command, which outputs the result text.
55
What is the output of this command? | echo "hello::there::friend" | awk -F "::" '{print $1, $3}'
hello friend
56
What is the difference between cut and awk?
Awk is much more flexible.
57
What does the head command do?
The head command displays the first 10 lines in a file.
58
What does wc -l command do?
Display the total number of lines in a file.
59
What gunzip command do?
Comrpess or expand files.
60
Gunzip alternatives
gzip, zcat
61
How to unzip "access_log.txt.gz"
gunzip access_log.txt.gz
62
How to print first 10 lines of file "access.log"?
head access.log
63
What sort -u do?
Sorts and showing only unique lines.
64
What does uniq command do?
Report or omit repeated lines.
65
What the -c option for uniq do?
This will prefix the output line with the number of occurrences.
66
What command using /etc/passwd, extract the user and home directory fields for all users on your Linux.
cat /etc/passwd | awk -F ":" '{print "The user " $1, " home directory is " $6}'
67
How to copy the /etc/passwd file to your home directory (/home/kali)?
cp /etc/passwd /home/kali/passwd
68
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”.
cat passwd | sed -i 's/Light Display Manager/LDM/g' passwd
69
Linux Text Editors
gedit leafpad nano vi
70
What is nano?
Nano is one of the simplest-to-use text editors.
71
What does CTRL + O shortcut in nano?
Write changes to the file.
72
What does CTRL + K shortcut in nano?
Cut the current line.
73
What does CTRL + U shortcut in nano?
Un-cut a line and paste it at the cursor location.
74
What does CTRL + W shortcut in nano?
Search.
75
What does CTRL + X shortcut in nano?
Exit.
76
What is vi?
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.
77
How to enable insert-text mode to begin typing in vi?
Press I key and start typing away.
78
How to disable insert-text mode and go back to command mode?
Press the ESC key.
79
What does dd in command mode in vi?
Delete the current line.
80
What does yy in command mode in vi?
Copy the current line.
81
What does p in command mode in vi?
Paste the clipboard contents.
82
What does x in command mode in vi?
Delete the current character.
83
What does :w in command mode in vi?
Write the current file to disk and stay in vi.
84
What does :q! in command mode in vi?
Quit without writing the file to disk.
85
What does :wq in command mode in vi?
Save and quit.
86
Why use vi?
Vi can save a great deal of time in the hands of experienced user and vi is installed on every POSIX-compliant system.
87
What does comm command?
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
How to scan with comm two text files "scan-a.txt", "scan-b.txt" and check uniques?
comm scan-a.txt scan-b.txt
89
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?
comm -12 scan-a.txt scan-b.txt
90
What is diff comand used to?
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
Two of the most popular formats of diff?
``` context format (-c) unified format (-u) ```
92
The most notable difference between unified and context format?
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
What does vimdiff?
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
What do shortcut in vim does?
Gets changes from the other window into the current one.
95
What dp shortcut in vim does?
Puts the changes from the current window into the other one.
96
What ]c shortcut in vim does?
Jumps to the next change.
97
What [c shortcut in vim does?
Jumps to the previous change.
98
What CTRL + W shortcut in vim does?
Switches to the other split window.
99
How to check two text files "scan-a.txt" and "scan-b.txt" with vimdiff?
vimdiff scan-a.txt scan-b.txt
100
What is PID?
Process ID
101
How to create a backgrounding process?
Append ampersand to the end of the command.
102
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?
ping -c 400 localhost > ping_results.txt &
103
What is a shortcut for canceling operations in Terminal?
CTRL + C
104
What is the shortcut to suspend a job in Terminal?
CTRL + Z
105
What is the shortcut to suspend a job in Terminal?
CTRL + Z
106
How to check backgrounding processes?
By bg command.
107
How to quickly check the status of ICMP echo requests?
By "jobs" and "fg" commands.
108
What is "jobs" command used to?
To look at jobs.
109
What is "fg" command used to?
To bring one job into the foreground.
110
What the "^C" character represents?
Keystroke combination CTRL + C.
111
By which shortcut can we terminate a long-running process and regain control of the terminal?
CTRL + C
112
One of the most useful commands to monitor processes on mostly any Unix-like operating system?
ps (short for process status).
113
What ps do?
ps lists processes systemwide, not only for the current terminal session.
114
What are the first things to check after obtaining remote access to a system?
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
What the -e option do in ps?
Select all processes.
116
What the -f option do in ps?
Display full format listing (UID, PID, PPID, etc.)
117
What the -C option do in ps?
Select by command name.
118
How to stop the Leafpad process without interacting with the GUI?
kill leafpad_pid
119
What kill command do?
Send a specific signal to a process.
120
What is the default signal to kill?
SIGTERM (request termination).
121
How to run a command in the background?
bigjob &
122
How to find files that have changed on your Kali virtual machine within the past 7 days?
find / -mtime -7
123
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?
find / -mtime -7 &
124
How to find files and directories modified more than n days ago?
find / -mtime +n
125
How to find the files and directories modified less than n days ago?
find / -mtime -n
126
How to get the files modified on ‘2019-07-24’?
find . -type f -newermt 2019-07-24 ! -newermt 2019-07-25
127
How to show the long format of the files and to sort the output by modification time by ls?
ls -lt
128
How to filter listing based on a specific date or time by applying the grep command by date?
ls -lt | grep 'Jul 27'
129
How to filter listing based on a specific date or time by applying the grep command by time?
ls -lt | grep '17:'
130
How to enable the recursive capability on the ls command?
ls -R
131
How to check "Firefox" PID?
ps -ef | grep firefox
132
How to terminate Firefox via CLI using its PID?
kill firefox_process_id
133
Commands to monitor files and commands in real-time.
tail and watch.
134
What tail command do?
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
What -f option in tail do?
The -f option (follow) is very useful as it continuously updates the output as the target file grows.
136
What -nX option in tail do?
-nX, which outputs the last “X” number of lines, instead of the default value of 10.
137
What the watch command is used to?
The watch command is used to run a designated command at regular intervals.
138
Which option specify different intervals for watch?
-n X option to have it run every “X” number of seconds.
139
How to list logged-in users?
By "w" command.
140
How to list logged-in users once every 5 seconds?
watch -n 5 w
141
How to start apache2 web service?
sudo systemctl start apache2
142
How to monitor apache2 access.log file in real-time?
watch tail /var/log/apache2/access.log
143
How to use a combination of watch and ps to monitor the most CPU-intensive processes on your Kali machine in a terminal window?
watch "ps aux | sort -nrk 3,3"
144
Commands for downloading files?
wget curl axel
145
What is wget command doing?
Downloads files using the HTTP/HTTPS and FTP protocols.
146
What "wget -O" does?
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
What is curl?
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
What is axel?
axel is a download accelerator that transfers a file from a FTP or HTTP server through multiple connections.
149
For what "-n" option in "axel" is used?
-n is used to specify the number of multiple connections to use.
150
For what "-a" option in "axel" is used?
For a more concise progress indicator.
151
For what "-o" option in "axel" is used?
To specify a different file name for the downloaded file.
152
Using "axel" initialise 20 multiple connections and save the file named "report.pdf" from the link "https://www.facebook.com/reports/report.pdf".
axel -a -n 20 -o report.pdf https://www.facebook.com/reports/report.pdf
153
Using "curl" download the file from the link "https://facebook.com/report/report.pdf" and save it under the name "report.pdf".
curl -o report.pdf https://facebook.com/report/report.pdf
154
Using "wget" download the file from the link "https://facebook.com/report/report.pdf" and save it under the name "report_wget.pdf".
wget -O report_wget.pdf https://facebook.com/report/report.pdf
155
What is PoC code?
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
Where can you download the PoC code for an exploit?
https://www.exploit-db.com
157
By which commands can you download an exploit from exploit-db?
curl wget axel
158
What is HISTCONTROL?
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
How to use HISTCONTROL to remove duplicates from bash history?
export HISTCONTROL=ignoredups
160
What the HISTIGNORE is for?
The HISTIGNORE variable is particularly useful for filtering out basic commands that are run frequently, such as ls, exit, history, bg, etc.
161
How to use HISTIGNORE to filter basic, common commands? E.g. ls, pwd, history, exit, bg.
export HISTIGNORE="&:ls:[bf]g:exit:history"
162
What the HISTTIMEFORMAT do?
HISTTIMEFORMAT controls date and/or time stamps in the output of the history command.
163
How to use HISTTIMEFORMAT to include the date/time in bash history.
export HISTTIMEFORMAT='%F %T '
164
What %F stands for in HISTTIMEFORMAT?
Year-Month-Day ISO 8601 format
165
What %T stands for in HISTTIMEFORMAT?
24-hour time
166
Where can you search for time formats for history command?
man history 3
167
What is alias?
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
How to replace "ls -la" command by "lsa" using "alias"?
alias lsa='ls -la'
169
How to define your own command "lsa" which is doing "ls" but with "-la" option without having to type any arguments at all?
alias lsa='ls -la'
170
How to check the list of defined aliases?
alias
171
How to unset an alias "mkdir"?
unalias mkdir
172
The behavior of interactive shells in Bash is determined by the system-wide _ file?
bashrc
173
Where bashrc is located?
In /etc/bash.bashrc.
174
How to override system-wide Bash settings?
Edit .bashrc file.
175
When .bashrc script is executed?
Everytime user logs in.
176
What type of file is .bashrc?
Shell script.
177
What is the default path of .bashrc?
/home/kali/.bashrc
178
How to examine the .bashrc default file?
cat ~/.bashrc
179
How to create an alias named “..” to change to the parent directory and make it persistent across terminal sessions?
Add in .bashrc alias ..="cd .."
180
How to permanently configure the history command to store 10000 entries and include full date in its output?
Add to .bashrc "export HISTSIZE=10000" and "export HISTTIMEOFRMAT='%F %T '"
181
How to print PATH enviroment variable?
echo $PATH
182
How to print USER enviroment variable?
echo $USER
183
How to print PWD enviroment variable?
echo $PWD
184
How to print HOME enviroment variable?
echo $HOME
185
What is sed?
Stream editor.
186
Print "hello::there::friend" and print only "hello friend" using echo and awk.
echo "hello::there::friend" | awk -F "::" '{print $1, $3}'
187
How to count lines in "access.log" file?
wc -l access.log
188
How to count lines in "access.log" file?
wc -l access.log
189
How to list all jobs running in current session?
jobs
190
How to continue second stopped job?
fg %2