Six Flashcards

1
Q

locate the binary file of a command

A

whereis command

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

short description of a command

A

whatis command

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

to repeat most recent command

A

!!

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

to turn on a environmental variable

A

set -o variable_name
set +o variable_name will turn it off
shopt -s optionName : enable it
shopt -u optionName: disable it

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

what is the if expression

A
if condition
then
elif condition
then
else
fi
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

grep format

A

grep pattern file

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

date

A

date +Format

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

positional parameters

A
$0 is the script itself
$1 is the first argument
$2 the second
.
after $9
it must be written as ${}
$# is the total number of inputs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

[ -z “string” ]

A

the length of the string is nonzero

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

case expression

A
case $var in
var1)
;;
var2)
;;
*)
;;
esac
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

translate string

A

tr [option] set1 set2

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

another way to avoid using tr

A

case $input in

[Ss][Oo])…….

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

Third way to turn on case-insensitiveness

A

shopt -s nocasematch
case $opt in
shopt -u nocasematch

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

for loop

A

for var in item1 item2
do
….
done

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

for loop (C heritage)

A

for (( EXP1; EXP2; EXP3))
do
done

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

command substitution

A

$(command)

this store the command output to a string or a variable

17
Q

while loop

A

while condition
do
done

18
Q

how to define a function in Bash

A
function function_name () {
statement
}
19
Q

function in a single line

A
function function_name () {; ; ;}
the last statement must have a semicolon.
20
Q

The limitation of the function

A

it must be defined before the first call

21
Q

A function cannot be empty

A

even if it has comments in it, it is empty. It shouldn’t be empty.

22
Q

command: basename

A

basename strips directory information and suffixes from filenames
-a –multiple : support multiple arguments and treat

23
Q

what does backtick mean

A

backtick ` runs the contents of the enclosed command and take the output as a string

24
Q

Leading dollar sign before single quotes

A

it causes escape sequences to be interpreted.

25
Q

what does (( t = a

A

if a

26
Q

How to use let command

A
let command let the expression to do arithmetic operation
ex. if you do var3=$var1*$var2, if $var1 is 1 and $var2 is 2, you will get $var3 as 1*2 which is plain text. But if we run:
let var3=$var1*$var2, we will get $var3 as an integer 2 instead.
It does what (()) does.
27
Q

how to use expr

A

concatenates and evaluates the arguments according to the operation give. Arguments must be separated by spcaes

28
Q

extract substring of $length characters, starting at $position

A

expr substr $string $position $length

29
Q

eval command

A

ex. pro=”ls -l”
if you type $pro, it will do nothing , becuase “ls -l “ is plain text. We can use eval to force the expression to execute

30
Q

let command

A

let command is used to erform arithmetic operations on shell variables

31
Q

what is ${parameter+alt_value}

A

no matter parameter is null or not, if it is set, it will be altered. This function is to determine if it is set or not
while ${parameter:+alter_value} will substitute it with null string if it is a null string

32
Q

Rename command syntax

A

rename is a perl script.
syntax: rename oldname newname *.files
ex. rename .bak .txt *.bak
rename all *.bak file as *.txt

33
Q

cut command

A

cut -cN1-N2 file : this will give specified columns
cut -d “delimiter” -fN1,N2-N3,N4
cut -d “delimiter” -s -fN1,N2-N3,N4 will not give the line that doesnt contain this delimiter