Tools Flashcards
Libraries:
Static Linking
vs
Dynamic Linking
- Static Linking
- Every routine needed from the library is included in the executable file
- Routines are PART OF the program
- Dynamic Linking
- References to library routines are left to resolve during execution
- Library objects not loaded until they are needed at runtime
Libaries:
What are
“Shared Libraries”?
Libraries that are prepared for
Dynamic Linking
These are also called
Dynamic Linking Libraries (DLLs)
Shell Scripts:
Overview
- A shell script is just a sequence of shell commands
- Stored in an executable text file
- The “x” bit in the file permissions must be turned on with “chmod”
- The shell finds programs by looking for executable files in the path ( $PATH )
Shell Utility Toolkit:
Basic
Line Oriented Processing Tools (8)
- grep
- find patterns
- sed
- edit lines
- cut
- extract columns
- sort
- sort lines into specified order
- uniq
- display unique lines in a sorted file
- tail
- display last lines of a file
- head
- display fist lines of a file
- wc
- count words, lines or characters
Shell Utility Toolkit:
grep
- Grep is used to find lines or patterns in text
- Use:
- grep [-e pattern]
- This will output any lines that contain any of the patterns
Shell Utility Toolkit:
sed
- Used to edit/rewrite lines within the text
- Use:
- sed [-e action]
- Copies input to output, performing all actions on each line
- Possible Actions
- Delete: /pattern/d
- Delete line if pattern found
- Read: /pattern/r
- Read file after the line where pattern occurs
- Replace: s/pattern/replace/g
- Substitute “replace” at occurrences of “pattern”
- Delete: /pattern/d
Shell Utility Toolkit:
cut
Extract the columns of text
Shell Utility Toolkit:
sort
Sort lines of text into a specified order
Shell Utility Toolkit:
uniq
Display unique lines in a sorted file
Shell Utility Toolkit:
tail
Display the last lines of a file
Shell Utility Toolkit:
head
Display the first lines of a file
Shell Utility Toolkit:
wc
Counts words, lines or characters in text
Shell Utility Toolkit:
File System
Manipulation Tools (8)
- cp - copy
- mv - move
- rm - remove
- ls - list
- chmod - change file access modes
- chown - change file owner
- find - navigate directory structure, testing files for attibutes
- touch - change last-modified time on a file to current
Shell Utility Toolkit:
Miscellaneous Tools (5)
- echo - echo arguments on stdout
- cat - copy a file, or files, to stdout
- tr - translate characters
- date - echo current date and time
- man - see manual page of a command
Shell Utility Toolkit:
Scripting Languages
In addition to simple shell scripts:
- awk
- Process files based on
- rich pattern matching
- text manipulation
- Process files based on
- perl
- Works similarly, but with more c-like facilities
Difference between
C Programming
and
Shell Programming
C Programming deals with:
- Data Structures
- Algorithms
Shell Programming deals with:
- The file system
- Utilities
A professional uses both language types for their unique strengths.
Shell Utility Toolkit:
echo
Writes text to stdout
Can pass plain or quoted text
Special Characters:
- *
- represents the contents of the directory
- $
- used for substitution variables
- ’ ‘
- surrounding text with single quotes means special characters are ignored
The Shell:
Using pipelines
Use the “|” to connect Filter programs int a pipeline
Example:
% ls -a | sort | uniq
Each step along the pipeline will perform the function
on the results of the previous step
Shell Command Format
[command] [-switch] …. [argument(s)] …
- Command file names are located in /bin/
- Built in verbs like “cd”
- Switches are a single letter, such as -a
- can combine switches by adding the letters: -a1
- some switches require you to add a value
What doe the Shell Provide?
- Interactive Interface
- Allows use of all system capabilities
- Navigate and manipulate file system
- Invoke System Commands and Programs
- Customize your environment
- Programming Environment
- For system programmers
- Automate interactions
- “glue” together smaller programs
- Prototype solutions
The Shell:
Redirection of
Input
By Default, input is normally stdin
Use “<” to specify a different file descriptor.
This allows a file to be used as input.
Example:
% grep -e “abc” < myFile.txt
The Shell:
Redirection of
Output
By default, output of programs is to stdout.
Use “>” to redirect the output to a different file descriptor.
This allows output of a program to be written to file.
Alternatively, use “>>” to append the file instead of writing over it.
Example:
% grep -e “abc” > my_output_file.txt
% grep -e “abc” >> my_output_file.txt
The Shell:
Redirection of
Error
By default, errors are printed to stderr
Use “ 2> “ to redirect to a different file descriptor
Example:
% grep -e “abc” 2> my_error_file.txt
Libraries:
How Dynamically Linked Library
routines are used when called
- The Executable File is by itself
- A call to a routine in the library goes to a Loader routine that has the name of the routine as an argument
- The Loader copies the needed routine from the library and loads it into memory
- Copying may be skipped if the routine is already loaded in memory
- The call is redirected to this routine