Upload
antonia-hopkins
View
217
Download
0
Embed Size (px)
Citation preview
Using Linux Commands
Lab 4
1
Create empty files
To create an empty file
$ touch apple banana grape grapefruit watermelon
$ ls -l
Using file-matching metacharacters Metacharacters help to match one or more files without typing
each filename completely. * This matches any number of characters. ? This matches any one character. […] This matches any one of the characters between the
brackets, which can include a dash-separated rang of letters or numbers.
2
$ ls a*
apple
$ ls g*
grape grapefruit
$ ls g*t
grapefruit
$ ls *e*
apple grape grapefruit watermelon
$ ls *n*
banana watermelon
Using file-matching metacharactersUsing file-matching metacharacters
This matches any number of characters *
3
Using file-matching metacharactersUsing file-matching metacharacters
This matches any one character ?
$ ls ????e
Apple grape
$ ls g???e*
grape grapefruit
4
Using file-matching metacharactersUsing file-matching metacharacters
This matches any one of the characters between the brackets […]
$ ls [abw]*
apple banana watermelon
$ ls [agw] * [ne]
grape grapefruit
$ ls [a-g] *
apple banana grape grapefruit
5
Using file-redirection metacharactersUsing file-redirection metacharacters
$ mail root < ~/.bashrc
$ echo “I finished the project on $(date)” > ~/projects
• Direct the contents of a file to the command <
• Direct the output of a command to a file, overwritingoverwriting any existing file >
• Direct the output of a command to a file, addingadding the output to the end of existing file >>
$ echo “I finished the project on $(date)” >> ~/projects
6
date commandsdate commands
Change or set current date and time.Syntax date [date or time string ]Examples Show current date & time
Set date to 2011-Mar-15
Set date as well as time
$ date
$date --date=“2011-3-15
$date --date=“2001-3-15 11:59 AM” 7
echo Commandecho Command
Use echo command to display text or value of variable.
echo [options] [string, variables...] Displays text or variables value on screen.
8
echo Commandecho Command
Options-n Do not output the trailing new line.-e Enable interpretation of the following backslash escaped characters in the strings:
\a alert (bell)\b backspace\n new line\t horizontal tab
9
QuotesQuotes
"Double Quotes" - Anything enclose in double quotes removed meaning of that characters (except \ and $).
'Single quotes' - Enclosed in single quotes remains unchanged.
`Back quote` -To execute command
10
Examples of quoting special Examples of quoting special characterscharacters
$ echo ' My working directory is `pwd`'
My working directory is`pwd`
$ echo "My working directory is `pwd`”
My working directory is /home/jane
$ echo -e "An apple a day keeps away \a\t\tdoctor\n"
11
Sort commandSort commandPiping commandPiping command
sort {file-name}sort {file-name} Options -r Reverse normal order (so "Z" starts the list instead of "A").
-n Sort in numeric order-nr Sort in reverse numeric order
$ ls /etc/password | sort | less
12
Sequential commandsSequential commands
To run a sequence of commands type several commands on the same command line and separating them with semicolons(;)
$ mkdir ng ; cd ng ; touch tom
13