Bash Shell Flashcards
make a local variable
VAR1=variableAttributeHere
how do you make variable environmental variable?
export VAR1
VAR1 is the variable
delete environmental variable
unset VAR1
prevent inadvertent overwriting
set -o noclobber
to disable run:
set +o noclobber
when using this > operator
redirect standard error
find / -name core -print 2> /dev/null
redirect both standard and output error
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.
see all previously run commands
history
move cursor to beginning of command line
Ctrl a
home
erase the entire line
ctrl u
erase from the cursor to the end of the command line
ctrl k
move curse to the right by one word
alt f
move cursor to the left one word
alt b
display previous working directory
echo ~-
make an alias
alais rm=’rm -i’
list all hidden directories
ls -d .*
match exactly one character
?
ls /var/log/????
This will fine everything in var/log with exactly 4 characters
match either a set of characters or a range of characters for a single character position
[] - 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
search for user in passwd file
grep user1 /etc/passwd
search for things at the beginning of the line
grep ^root /etc/passwd
search for things at the end of a line
$
grep bash$ /etc/passwd
show entire login.defs file but EXCLUDE all empty lines
grep -v ^$ /etc/login.defs
-v - inverts so it excludes all the empty lines - ^$
case insensitive search
-i
grep -i path /etc/bashrc
will find path, PATH,Path etc….
which character can be used as an OR operator within grep
- pipe
ls -l /etc | grep -E ‘cron|ly’ = cron pipe ly
will find all file with cron or ly in the title
run the top command in the background
top &
list all jobs
jobs -l
name the three system-wide startup files
/etc/bashrc
/etc/profile
/etc/profile.d
name the per-user shell start up files
.bachrc
.bash_profile
.gnome2/
hostcustomize your prompt
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
which directory location stores most privileged commands
/usr/sbin