You are on page 1of 16

1

Er. Lalit Matoliya

Team Co-Ordinator, CDAC-ACTS

August 30, 2016

LINUX
COMMANDS

CP: COPYING A FILE


August 30, 2016

The cp (Copy) command copies a file or a group of files.


Example:
$ cp chap01 unit1
Note: If the destination file(unit1) doesnt exist, it will first
be created before copying takes place. If not, it will simply
be overwritten without any warning from the system.
cp can be used to copy more than one file with a single invocation
of the command. In that case, the last filename must be a
directory.
$ cp chap01 chap02 chap03 progs
$ cp chap* progs
cp options:
Interactive Copying(-i)
$ cp i chap01 unit1
Copying Directory Structures(-R)
$ cp R progs newprogs

RM: DELETING FILES


August 30, 2016

The rm(Remove) command deletes one or more files. It normally


operates silently and should be used with caution.
$ rm chap01 chap02 chap03
$ rm *

[All files gone!]

rm options:
Interactive Deletion (-i)
$ rm i chap01 chap02 chap03
Recursive Deletion (-r or R)
$ rm r *
Youll delete all files in the current directory and all its
subdirectories. If you dont have a backup, then these files will be
lost forever.
Forcing Removal (-f)
$ rm rf *

[Deletes everything in the current directory]

Note: If the root user (the super user) invokes rm rf * in the /


directory, the entire UNIX system will be wiped out from the hard
disk!

MV : RENAMING FILES
August 30, 2016

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


functions:
1. It renames a file (or directory).
2. It moves a group of files to a different directory.
Example:
$ mv chap01 man01
A group of files can be moved to a directory. The following
command moves three files to the progs directory:
$ mv chap01 chap02 chap03 progs
mv can be used to rename a directory.
$ mv lalit kumar
4

FILE: KNOWING THE FILE TYPES


August 30, 2016

Files are divided into three categories:


1. Ordinary File : Also known as regular file. It contains only
data as a stream
of characters. (Text Files, Binary
Files)
2. Directory File : Its commonly said that a directory
contains files and other
directories, but it
contains their names and a number
associated with each name.
3. Device File : All devices and peripherals are represented
by files.
Example:
$ file archieve.zip
$ file *
5

August 30, 2016

WC: COUNTING LINES, WORDS


AND
CHARACTERS
$ cat infile
I am the wc command
I count characters, words and lines
With options I can also make a selective count
You can now use wc without options to make a word count of
the data in the file:
$ wc infile
3

20

103

infile

wc counts 3 lines, 20 words and 103 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.

A character is the smallest unit of information, and includes a


space, tab and newline.

$wc l infile

[Number of Lines]

$ wc w infile

[Number of words]

$ wc c infile

[Number of characters]

GZIP AND GUNZIP


August 30, 2016

Example:
$ wc c libc.html
3875302 libc.html
$ gzip libc.html
$ wc c libc.html.gz
788096 libc.html.gz
Uncompressing a gzipped file (-d)
$ gzip d libc.html.gz
$ gunzip libc.html.gz
$ gunzip libc.html.gz
multiple files]
$ gzip r progs

User_Guide.ps.gz

[Works

with

[Compress all files in progs recursively]

TAR: THE ARCHIVAL PROGRAM


August 30, 2016

For creating a disk archive that contains a group of files or an


entire directory structure, we need to use tar.
-c

Create an archive

-x

Extract files from archive

-t

Display files in archive

-f

Specify the archive

[Creating an Archive (-c)]


$ tar cvf archive.tar libc.html User_Guide.ps
$ tar cvf progs.tar c_progs java_progs shell_scripts
$ tar xvf progs.tar [Extracts three directories]
$tar tvf archive.tar [Viewing the archive (-t)]

the remaining arguments are


directories to be compressed.

interpreted

as

files

August 30, 2016

ZIP AND UNZIP : COMPRESSION


AND
ARCHIVING
zip requires the first argument to be the compressed filename;
and

$ zip archive.zip libc.html User_Guide.ps


$unzip archive.zip
$ unzip v archive.zip

[Viewing Archive(-v)]

LISTING FILE ATTRIBUTES


$ ls l
-rw- r- -r- -

kumar metal

19514

May 10 13:45 chap01

-rw- r- -r- -

kumar metal

4174

May 10 15:01 chap02

drwxr-xr-x

kumar metal

512

May 10 10:45

helpdir

drwxr-xr-x

kumar metal

512

May 10 09:45

progs

$ ls ld

August 30, 2016

ls l command is used to list all files and directories with long listing
format.

[Listing Directory Attributes]

File Type and Permissions


Links
Ownership
Group Ownership
File Size
Last Modification Time
Filename

10

CHANGING FILE PERMISSIONS


chmod category operation permission filename(s)

User category (user, group, others)

The operation to be performed (assign or remove a permission)

The type of permission (read, write , execute)

August 30, 2016

Relative Permissions

$ chmod u+x xstart


$ ls l xstart
-rwx r- -r- xstart

kumar

metal

1906

May 10 13:45

metal

1906

May 10 13:45

$ chmod ugo+x xstart


$ ls l xstart
-rwx r-xr-x
xstart

kumar

$ chmod u+x note note1 note2


permissions]

[Assign the same set of

11

CHANGING FILE PERMISSIONS


Binar

Octal Permissions

Significance

y
000

---

No Permission

001

--x

Executable Only

010

-w-

Writable Only

011

-wx

Writable and Executable

100

r--

Readable only

101

r-x

Readable and Executable

110

rw-

Readable and Writable

111

rwx

Readable, Writable and Executable

August 30, 2016

Absolute Permissions

$ chmod 666 xstart ; ls l xstart


-rw-rw-rwxstart

kumar

metal

1906

May 10 13:45
12

CHANGING FILE OWNER


-rwxr- - - -x

kumar metal

347

May 10 01:45 note

$chown sharma note ; ls l note


-rwxr- - - -x
note

sharma

metal

347

May 10 01:45

347

May 10 01:45

347

May 10 01:45

August 30, 2016

$ ls l note

Changing Group Owner


$ ls l note
-rwxr- - - -x
note

kumar

metal

$chgrp sharma note ; ls l note


-rwxr- - - -x
note

kumar

sharma

13

MODES IN VI EDITOR

Command Mode : The default mode of the editor where every


key pressed is interpreted as a command to run on text.
Input Mode : Every key pressed after switching to this mode
actually shows up as test.

August 30, 2016

ex Mode : The mode used to handle files (like saving) and


perform substitution. Pressing a : in the command mode invokes
this mode.

14

THE THREE MODES


ex Mode
[Esc]
I,i, a, A, o, O,
r, R, s, S and c
Operator

August 30, 2016

Input Mode

[Enter]

Command
Mode

:x, :q
and ZZ

vi foo

Shell

15

August 30, 2016

THANK
S

16

You might also like