Bash Shell Flashcards

1
Q

make a local variable

A

VAR1=variableAttributeHere

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

how do you make variable environmental variable?

A

export VAR1
VAR1 is the variable

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

delete environmental variable

A

unset VAR1

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

prevent inadvertent overwriting

A

set -o noclobber

to disable run:
set +o noclobber

when using this > operator

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

redirect standard error

A

find / -name core -print 2> /dev/null

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

redirect both standard and output error

A

ls /usr /cdr &> outerr.out

This example will produce a listing of the /usr directory and save the result in outerr.out. At the same time, it will generate an error message complaining about the non-existence of /cdr, and it will send it to the same file as well.

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

see all previously run commands

A

history

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

move cursor to beginning of command line

A

Ctrl a
home

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

erase the entire line

A

ctrl u

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

erase from the cursor to the end of the command line

A

ctrl k

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

move curse to the right by one word

A

alt f

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

move cursor to the left one word

A

alt b

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

display previous working directory

A

echo ~-

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

make an alias

A

alais rm=’rm -i’

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

list all hidden directories

A

ls -d .*

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

match exactly one character

A

?
ls /var/log/????
This will fine everything in var/log with exactly 4 characters

17
Q

match either a set of characters or a range of characters for a single character position

A

[] - square brackets
ls /usr/bin/[yw]* = will find all file starting with y and w
ls -d /etc/systemd/system/[m-o]* = all file with m through o
ls -d /etc/systemd/system/[!m-o]* = ! excludes m through o

18
Q

search for user in passwd file

A

grep user1 /etc/passwd

19
Q

search for things at the beginning of the line

A

grep ^root /etc/passwd

20
Q

search for things at the end of a line

A

$
grep bash$ /etc/passwd

21
Q

show entire login.defs file but EXCLUDE all empty lines

A

grep -v ^$ /etc/login.defs
-v - inverts so it excludes all the empty lines - ^$

22
Q

case insensitive search

A

-i
grep -i path /etc/bashrc
will find path, PATH,Path etc….

23
Q

which character can be used as an OR operator within grep

A

- pipe
ls -l /etc | grep -E ‘cron|ly’ = cron pipe ly
will find all file with cron or ly in the title

24
Q

run the top command in the background

A

top &

25
Q

list all jobs

A

jobs -l

26
Q

name the three system-wide startup files

A

/etc/bashrc
/etc/profile
/etc/profile.d

27
Q

name the per-user shell start up files

A

.bachrc
.bash_profile
.gnome2/

28
Q

hostcustomize your prompt

A

export PS1=”< $LOGNAME on $(hostname) in $PWD > “

prompt will not look like:
< user1 on server1 in /home/user1 >

Edit .bash_profile with the exact same command to make persistent

29
Q

which directory location stores most privileged commands

A

/usr/sbin