13
Using Linux Commands Lab 4 1

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

Embed Size (px)

Citation preview

Page 1: 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

Using Linux Commands

Lab 4

1

Page 2: 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

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

Page 3: 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

$ 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

Page 4: 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

Using file-matching metacharactersUsing file-matching metacharacters

This matches any one character ?

$ ls ????e

Apple grape

$ ls g???e*

grape grapefruit

4

Page 5: 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

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

Page 6: 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

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

Page 7: 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

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

Page 8: 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

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

Page 9: 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

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

Page 10: 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

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

Page 11: 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

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

Page 12: 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

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

Page 13: 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

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