• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/24

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

24 Cards in this Set

  • Front
  • Back
  • 3rd side (hint)
$man bash
displays the linux bash shell manual
$echo $?
displays exit status (0 = ok, other=error)
Wild Cards

*
?
[..]
* matches any number of characters
? matches exactly one character
$ ls /bin/[a-c]* - will find any files in the bin directory that begins with an a, b or c and is followed by anything else.
! or ^ - does not match expression that follows
adding more then one command on a line
separate commends with a semicolon

date;who
read
accepts input from user and stores it in variable.

read fname:

Example: read user_name
$#
holds number of arguments specified on command line
$* or $@
refer to all arguments passed to script. Or $1..$9 refers to the 1st thru the 9th parameters passed.
$0
Contains the name of the script.
Comparing String Variable to Literal
userName=""
targetName="Jack"
echo -n "Enter your name: "
read userName
if [ $userName == "Jack" ]
then
echo "Hello $userName"
else
echo "Go away $userName"
fi
chmod a+rx filename

or

chmod 755 filename
makes a file executable, by setting the executable bit, and readable by setting the read bit.
#!/bin/sh
tells Unix that the file is to be executed by /bin/sh. This is the standard location of the Bourne shell on just about every Unix system. If you're using GNU/Linux, /bin/sh is normally a symbolic link to bash.
mkdir rc{0,1,2,3,4,5,6,S}.d

or

for runlevel in 0 1 2 3 4 5 6 S
do
mkdir rc${runlevel}.d
done
creates multiple directories rc0..rcS
while loop
while [ condition ]
do
...
executable code
...
done

Example:

while [ "$user_name != "Quit" ] (note space)
do
read user_name
echo $user_name
done
for loop
for i in <set of values>
do
...
executable code
...
done
Examples:

i=1
for day in "Mon Tue Wed Thu Fri"
do
echo "Weekday $((i++)) : $day"
done


i=1
weekdays="Mon Tue Wed Thu Fri"
for day in $weekdays
do
echo "Weekday $((i++)) : $day"
done


i=1
for day
do
echo "Weekday $((i++)) : $day"
done

i=1
for username in `awk -F: '{print $1}' /etc/passwd`
do
echo "Username $((i++)) : $username"
done


i=1
cd ~
for item in *
do
echo "Item $((i++)) : $item"
done


i=1
for file in /etc/[abcd]*.conf
do
echo "File $((i++)) : $file"
done
if statement
if [ ... ]
then
# if-code
else
# else-code
fi
if else elsif statement
if [ something ]; then
echo "Something"
elif [ something_else ]; then
echo "Something else"
else
echo "None of the above"
fi
awk '{ print $0 }' /etc/passwd
Prints the entire line of the file /etc/passwd. In awk, when a print command appears by itself, the full contents of the current line are printed. So awk '{ print $0 }' /etc/passwd and awk '{ print } do exactly the same thing.
$0 (in awk)
Represents the entire current line. So awk '{ print $0 }' /etc/passwd and awk '{ print }' do exactly the same thing.
AWK Variables
awk variables are initialized to either zero or the empty string the first time they are used.
Variables
Variable declaration is not required
May contain any type of data, their data type may change over the life of the program
Must begin with a letter and continuing with letters, digits and underscores
Are case sensitive
Some of the commonly used built-in variables are:

NR -- The current line's sequential number
NF -- The number of fields in the current line
FS -- The input field separator; defaults to whitespace and is reset by the -F command line parameter
FS - Input Field Seperator
RS - Input Field Seperator
OFS - Output Field Separator
ORS - Output Record Separator
write shell script to read a text file with multiple columns and then create a new file with the columns in reverse order.
awk -F, '{ print $3","$2","$1 }' names.txt > names2.txt
first_name,last_name,age

to

age,last_name,first_name
awk OFS
Output Field Seperator
OFS=\;

sets the output field separator to a semicolon ;
create a output file called dataout.txt using input from file data.txt. creating new data field layout separated by semicolons. new data fields are created fom substrings of original datafields as follows:

Column1 contains first six characters of first number in text file
Column2 contains last five characters of first number in text file
Column3 contains complete semicolon separated number of text file
Column4 contains first six characters of last number in text file
Column4 contains last four characters of last number in text file
awk '{ print substr($1,1,6), substr($1,7,11),$2,substr($3,1,6)
, substr($3,7,11)}' OFS=\; data.txt > dataout.txt
awk \t
awk tab
Example:

print $1"\t"$3"\t"$4"\t"$6;
awk FILENAME
gives the file name of the file awk is processing.
awk BEGIN {