Bif703
This presentation is the property of its rightful owner.
Sponsored Links
1 / 28

BIF703 PowerPoint PPT Presentation


  • 97 Views
  • Uploaded on
  • Presentation posted in: General

BIF703. Miscellaneous Commands. File related commands. grep - print lines matching a pattern head - output the first part of files tail - output the last part of files sort - sort lines of text files diff - find differences between two files file - determine file type.

Download Presentation

BIF703

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Bif703

BIF703

Miscellaneous Commands


File related commands

File related commands

  • grep - print lines matching a pattern

  • head - output the first part of files

  • tail - output the last part of files

  • sort - sort lines of text files

  • diff - find differences between two files

  • file - determine file type


Utility commands

Utility commands

  • who –show who is logged in

  • date –print or set the system date and time

  • which –show the full path of (shell) commands

  • finger –user information lookup program

  • mail –send and receive mail


Print commands

Print commands

  • lpr – print files

  • lpq – show print queue status

  • lprm – cancel print jobs


Bif703

grep

  • grep takes a pattern, read standard input or a list of files, and outputs the lines containing matches for the pattern.

    Example:

    grep foo *

    Print lines in any of the files in the current directory that contain the pattern “foo”.


Grep options

grep options

Major options for grep:

-ldisplay name of the file that has matching line

-rsearch all the files in the current directory and all its subdirectory for the given pattern

-nprefix each output with line number

-wsearch for matching word

-voutput lines that do not contain the given pattern


Grep examples

grep examples

  • grep -r foo .

    Print all the lines in all the files in the current directory and all its subdirectories that contains the pattern “foo”.

  • grep -lr foo .

    Similar as above but only print the names of the files that contains the pattern “foo”


Grep examples1

grep examples

Print all the lines in the file “bar” that contains the pattern “foo”

[[email protected] misc]$ grep foo bar

This line contains the word foo and bar.

Do you like to play football or basket ball?

Same as above but prefix each line of output with the line number within the file “bar”

[[email protected] misc]$ grep -n foobar

3:This line contains the word foo and bar.

4:Do you like to play football or basket ball?


Grep examples2

grep examples

Print all the lines in the file “bar” that contains the word “foo”

[[email protected] misc]$ grep -w foo bar

This line contains the word foo and bar.

Print all the lines in the file “bar” that does not contain the pattern “foo”

[[email protected] misc]$ grep -v foobar

The name of this file is called bar.

This file has only five line.

This is the end of the file.


Head tail

head & tail

  • head bar

    • Display the first 10 line of the file “bar”

  • head -5 bar

    • Display the first 5 lines of the file “bar”

  • tail bar

    • Display the last 10 lines of the file “bar”

  • tail-5bar

    • Display the last 5 lines of the file “bar”


Bif703

sort

Sort line of text file

cat numbers

2314 5678

345 2231

101 984

4842 6543

98 11001

[root] sort numbers

101 984

2314 5678

345 2231

4842 6543

98 11001

[root] sort -n numbers

98 11001

101 984

345 2231

2314 5678

4842 6543

String

order

Numeric order


Sort examples

sort examples

cat numbers

2314 5678

345 2231

101 984

4842 6543

98 11001

sort numbers

101 984

2314 5678

345 2231

4842 6543

98 11001

sort-k2 numbers

98 11001

345 2231

2314 5678

4842 6543

101 984

Sort by

the 2nd

field

Sort by

the 1st

field


Sort examples1

sort examples

cat numbers

2314 5678

345 2231

101 984

4842 6543

98 11001

sort numbers

101 984

2314 5678

345 2231

4842 6543

98 11001

sort-r numbers

98 11001

4842 6543

345 2231

2314 5678

101 984

Sort in

reverse

order


Bif703

diff

Display the differences between two files

Syntax:

  • diff [options] file1 file2

  • When using “diff” without any options, it produces a series of lines containing:

    • Add (a)

    • Delete (d), and

    • Change (c) instructions

      Each of these lines is followed by the lines from the file that you need to add, delete, or change to make the files the same.


Diff examples

diff examples

cat file1

blue

red

white

yellow

orange

cat file2

blue

yellow

black

red

orange

Steps to convert file1 to file2:

$diff file1file2

2,3d1

< red

< white

4a3,4

> black

> red

1. Delete line 2 through 3 from file1

2. Append lines 3 through 4 fromfile2after line 4 infile1


Bif703

file

Displays the classification (type) of a file. Considered useful if a file extension is missing, or if user is unsure of file extension.

  • Syntax: file [option] file-list

    Examples:

file assign01.html

assign01.html: HTML document text

file a.out

a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), not stripped

file mydoc.doc

mydoc.doc: Microsoft Office Document

file 1

1: empty


Bif703

who

Shows which users are logged on to server

Phobos: /home/rchan>$ who

rchan pts/0 Oct 30 02:08 (toronto-hse-ppp3)

sslui pts/1 Oct 30 01:11 (CPE00112f0fe590-)

Phobos: /home/rchan>$ who -H

Name Line Time Hostname

rchan pts/0 Oct 30 02:08 (toronto-hse-ppp3)

sslui pts/1 Oct 30 01:11 (CPE00112f0fe590-)

Phobos: /home/rchan>$ who -qH

Name Hostname

rchan (toronto-hse-ppp3)

sslui (CPE00112f0fe590-)

Total users: 2


Who options

who options

Major options for grep:

-Hdisplays column headings

-Tincludes message reception status: + message reception on - message reception off

-i includes column indicating number of minutes of user inactivity.


Who examples

who examples

Show who is logged on

Column headings

who -H

Name Line Time Hostname

root pts/0 Mar 02 09:11 (142.204.20.17)

msaul pts/1 Mar 02 09:21 (CPE0040f4df2fef-)

who -i

root pts/0 Mar 02 09:11 0:03 42368 (142.204.20.17)

msaul pts/1 Mar 02 09:21 . 37790

who -T

root - pts/0 Mar 02 09:11

msaul + pts/1 Mar 02 09:21

Less than 1 minute inactivity

Allows message reception


Bif703

date

Displays the system time and date

[[email protected] week8]$ date

Sun Oct 30 01:48:10 EST 2005

[[email protected] week8]$ date +"%D"

10/30/05

[[email protected] week8]$ date +"%T"

01:54:05

[[email protected] week8]$ date +"%D %T"

10/30/05 01:54:13

  • Refer to the man page for more formatting codes


Which

which

Shows the full path of (shell) commands

[[email protected] week8]$ which mkdir

/bin/mkdir

[[email protected] week8]$ which type

/usr/bin/which: no type in (/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/ray/bin)


Finger

finger

User information lookup program

Phobos: /home/rchan>$ finger rchan

Login name: rchan In real life: Raymond Chan

Directory: /home/rchan Shell: /usr/bin/ksh

On since Oct 30 02:08:55 on pts/0

from toronto-hse-ppp3

(messages off)

No Plan.


Bif703

mail

  • Send and receive mail

  • To read your mail on phobos, type the “mail” command by itself:

    Phobos: /home/rchan>$ mail

    Mail [5.2 UCB] [AIX 4.1] Type ? for help.

    "/var/spool/mail/rchan": 1 message 1 new

    >N 1 rchan Wed Oct 26 00:24 10/340 "Mail testing"


Sending mail

Sending mail

To send a file called “letter” through email on phobos to the user “rchan”:

Phobos: /home/rchan>$ mail -s “subject” rchan < letter


Lpr lpq lprm

lpr, lpq, lprm

  • lpr – submit file for printing

    lpr [ -P printer-name ] [ -# copies ] file-name

    [ -P printer-name] : send files to the named printer

    [ -# copies ] :sets the number of copies to print

    between 1 and 100

    file-name : name of file to be printed


Printer queue status

printer queue status

  • lpq - show printer queue status

    lpq [ -P printer-name] [ -a ] [ -l]

    [ -P printer-name] : show status on the named printer

    [ -a ] : reports jobs on all printers

    [ -l ] : display more verbose (long) format


Cancel print jobs

Cancel Print Jobs

  • lprm – cancel print jobs

    lprm [ - ] [ -P printer-name] [ job ID(s)]

    [ - ] : all print jobs

    [ -P printer-name] : print jobs on the named printer

    [ job ID(s) ]: jobs to be cancel


Additional resources

Additional Resources

  • Here are some Related-Links for Interest Only:

    • Linux manual pages (online):

      • http://man.he.net/


  • Login