• No results found

$ cat chap1 chap2

N/A
N/A
Protected

Academic year: 2020

Share "$ cat chap1 chap2"

Copied!
40
0
0

Loading.... (view fulltext now)

Full text

(1)

UNIX

Reference:

UNIX Concepts and Applications – 4th Edition

By

(2)

Handling Ordinary Files

• cat, more and less

• cp, rm and mv

• lp

• wc

• cmp, comm and diff

• tar

• gzip and gunzip

(3)

cat: Displaying and Creating Files

cat is mainly used to display the contents of a

small file on the terminal.

$ cat dept.lst

cat can also accept more than one filename as

arguments.

$ cat chap1 chap2

(4)

Using cat to create a file

$ cat > foo ……..

(5)

cp: Copying a File

The cp command copies a file or a group of files. It creates an exact image of the file on the disk with a different name.

(6)

cp: Copying a File

The following example shows two ways of copying a file to the progs directory.

$ cp chap1 progs/unit1

(chap1 copied to unit1 under progs)

$ cp chap1 progs

(7)

cp: Copying a File

To copy a file .profile from /home/sharma to your current directory

$ cp /home/sharma/.profile .profile

(Destination is a file)

$ cp /home/sharma/.profile .

(8)

cp: Copying a File

To copy the files chap1, chap2 and chap3 to the progs directory

$ cp chap1 chap2 chap3 progs

(9)

cp: Copying a File

$ cp chap* progs

(Copying all files beginning with chap.)

The cp –R command behaves recursively to copy an entire directory structure, say progs to newprogs

$ cp –R progs newprogs

(10)

cp: Copying a File

If newprogs does not exists, cp creates it along with the associated subdirectories. But if

newprogs exists, progs becomes a

(11)

rm: Deleting File

The rm command deletes one or more files.

$ rm chap1 chap2 chap3

(command to delete 3 files)

• A file once deleted can’t be recovered.

rm won’t normally remove a directory, but it

(12)

rm: Deleting File

$ rm progs/chap1 progs/chap2

or

$ rm progs/chap[12]

• To delete all files

(13)

rm: Deleting File

$ rm –r *

(14)

rm: Deleting File

$ rm –rf *

(15)

mv: Renaming File

• The mv command renames (moves) files. It has two distinct functions –

– It renames a file (or directory)

(16)

rm: Deleting File

$ mv chap1 man1

(To rename the file chap1 to man1. If the destination file does not exists, it will be created.)

$ mv chap1 chap2 chap3 progs

(17)

rm: Deleting File

$ mv pis perdir

(mv command rename a directory pis to perdir.)

CHECK IT YOURSELF –

(18)
(19)

more: Paging output

UNIX offers the more pager (originally from Berkeley) which has today replaced pg, the original pager of UNIX.

Linux also offers more but less is its standard pager.

(20)

more: Paging output

$ more chap1

(press q to exit)

(21)

lp: Printing a file

• No user is allowed direct access to the printer. Instead, one has to spool (line up) a job along with others in a print queue.

(22)

lp: Printing a file

$ lp rfc822.ps $_

(23)

file: Knowing the file type

• We know that files are of three types.

• We may often need to know more about these files.

• For example, a regular file may contain plain text, a C program or executable code.

(24)

file: Knowing the file type

$ file a.zip

a.zip:ZIP archive

$ file * (* signifies all files)

fork1.c: c program text a.sh: commands text

(25)

file: Knowing the file type

• This command identifies the file type by examining the magic number that is embedded in the first few bytes of the file.

• Every file has a unique magic number.

file recognizes text files and can distinguish

(26)

wc: Counting lines, words and

characters

$ wc chap1

3 20 103 chap1

wc counts 3 lines, 20 words and 103

(27)

wc: Counting lines, words and

characters

A line is any group of characters not containing a newline.

A word is a group of characters not containing a space, tab or newline.

(28)

wc: Counting lines, words and

characters - options

$ wc –l chap1

3 chap1 (Number of lines)

$ wc –w chap1

20 chap1 (Number of words)

$ wc –c chap1

103 chap1 (Number of

(29)

cmp: Comparing two files

$ cmp chap1 chap2

chap1 chap2 differ: char 9, line 1

(30)

cmp: Comparing two files

By default, cmp does not bother about possible subsequent mismatches but displays a detailed list when used with –l option.

If the two files are identical, cmp displays no message, but simply returns the prompt.

(31)

comm: What is common

File1 File2

c.k. shukla anil aggarwal

chanchal singhvi barun sengupta

s.n. dasgupta c.k. shukla

sumit chakrobarty lalit chowdury

(32)

comm: What is common

To use comm command we require two

sorted files.

$ comm file1 file2

(33)

comm: What is common

• The first column contains lines unique to the first file.

• The second column contains lines unique to the second file.

(34)

comm: What is common

• To drop a particular column, simply use its column number as an option.

$ comm -3 file1 file2

(selects lines not common to both files)

$ comm -13 file1 file2

(35)

diff: Converting one file to another

diff command can be used to display file

differences.

(36)

diff: Converting one file to another

• Here are the contents of files email and addresses used in this example.

(37)

diff: Converting one file to another

• To compare the contents of two files:

$ diff email addresses

2a3,4

> Jean [email protected] > Jim jim@frolix8

(38)

diff: Converting one file to another

diff email addresses 2a3,4

> Jean [email protected] > Jim jim@frolix8

(39)

tar: Creating an archive file

• To create an archive file use the command:

tar cvf tarfile_name.tar filenames

(directory_name)

The command options cvf modify the way the tar command works.

• See the manual page for details.

(40)

tar: Creating an archive file

• When you create a tarfile of a directory all the subdirectories are added; this can result in very large tarfiles.

References

Related documents

The student has knowledge of an interdisciplinary, defines the nature and scope of the concept of national security, identifies and describes the conditions of the various

If you want to copy all your files from one directory to another directory starting from A letter and ending with any two letter and extension is .TXT type the following

Section 5 discusses the propagation of a weather shock, assesses the consequences of a drought and its implication in terms of business cycles statistics, presents the

PART 1 The total risk approach to prevention of cardiovascular disease 7 reduced by 10–15 mmHg (systolic) and 5–8 mmHg (diastolic) and blood cholesterol by about 20%

The independent variables comprise of: (i-ii) binary variables for whether the merger appointed a better performing operating or financial CEO, respectively; (iii) a

We recommended that the PVAHCS Interim Facility Director ensure that (1) resources are in place to deliver timely urological care to patients; (2) non-VA care providers’

At Nightingale, Sectra Breast Imaging PACS integrates five mammography modalities from three different vendors, a number of other imaging modalities and an existing RIS and