Вы находитесь на странице: 1из 10

Copy , Move , Delete Files

Script -
[bsc@localhost ~]$ scriptmj.lst

Script started, file is mj.lst

Listing All Flies(ls) -


[bsc@localhost ~]$ ls

A bscty1 linux1 nohup.outsss.csurnm

add cat ltoclass.cpp object.cpp static.cpp surnm1

add1 class.cpp mahi odd.cpp staticm.cpp Templates

add1.c Desktop mahi.cperustatic.out terminal

add.c div marks.cpp peru.c stud this.cpp

Alpha1 div.cmj.lst Pictures stud1 typescript

alpha.lst Documents mj.txt Public students Videos

bsc Downloads mulr.out sub welcome.c

bsc1 file mul1 scope.cpp sub1

bsc4 files mul1.c sonu sub1.c

bsc5 flies mul.csonu.csub.c

bsctylinux Music sss suenm1

[bsc@localhost ~]$ cat>rdj.txt

omkar

aditysa

akash

prakash

ranjeet
1) Copying file -

[bsc@localhost ~]$ cat rdj.txt

omkar

aditysa

akash

prakash

ranjeet

[bsc@localhost ~]$ cp rdj.txt mj.lst

[bsc@localhost ~]$ catmj.lst

omkar

aditysa

akash

prakash

ranjeet

1.1) cp -f
[bsc@localhost ~]$ cp -f rdj.txt mj.lst

[bsc@localhost ~]$ lsmj.lst

mj.lst

[bsc@localhost ~]$ cat rdj.txt

omkar

aditysa

akash

prakash

ranjeet
[bsc@localhost ~]$ cp -i rdj.txt mj.lst

cp: overwrite ‘mj.lst’? y

[bsc@localhost ~]$ catmj.lst

omkar

aditysa

akash

prakash

ranjeet

1.2) cp –n

[bsc@localhost ~]$ cp -n rdj.txt mj.lst

[bsc@localhost ~]$ cat rdj.txt

omkar

aditysa

akash

prakash

ranjeet

[bsc@localhost ~]$ catmj.lst

omkar

aditysa

akash

prakash

ranjeet
1.3)cp –r
[bsc@localhost ~]$ cp -r rdj.txt mj.lst

[bsc@localhost ~]$ catmj.lst

omkar

aditysa

akash

prakash

ranjeet

[bsc@localhost ~]$ cat>mx.txt

rj

mj

oj

aj

[bsc@localhost ~]$ cp mx.txt rdx.lst

[bsc@localhost ~]$ catrdx.lst

rj

mj

oj

aj

2)Moving files-
[bsc@localhost ~]$ mvrdx.lst mx.txt

[bsc@localhost ~]$ cat mx.txt

rj

mj
oj

aj

2.1) mv –I
[bsc@localhost ~]$ cp mx.txt rdx.lst

[bsc@localhost ~]$ mv -i rdx.lst mx.txt

mv: overwrite ‘mx.txt’? y

[bsc@localhost ~]$ cat mx.txt

rj

mj

oj

aj

3 ) Removing files -
[bsc@localhost ~]$ cp mx.txt rdx.lst

[bsc@localhost ~]$ lsrdx.lst

rdx.lst

[bsc@localhost ~]$ rm -i rdx.lst

rm: remove regular file ‘rdx.lst’? y

[bsc@localhost ~]$ lsrdx.lst

ls: cannot access rdx.lst: No such file or directory

[bsc@localhost ~]$

4) Creating Directory -
[bsc@localhost ~]$ mkdir linux3

[bsc@localhost ~]$ ls
A alpha.lst bscty1 Documents linux1 mj.lst Music peru.csonustatic.out sub1.c
terminal

addbsc cat Downloads linux3 mj.txt mx.txt Pictures sonu.c stud


sub.c this.cpp

add1 bsc1 class.cpp file ltoclass.cpp mulnohup.out Public sss stud1


suenm1 typescript

add1.c bsc4 Desktop files mahi mul1 object.cpp rdj.txt sss.c students
surnm Videos

add.c bsc5 div flies mahi.cmul1.c odd.cppr.out static.cpp sub surnm1


welcome.c

Alpha1 bsctydiv.clinux marks.cpp mul.cperu scope.cpp staticm.cpp sub1


Template

Creating Tree Structure -


[bsc@localhost ~]$ mkdir M M/N M/N/O M/N/O/Q

[bsc@localhost ~]$ ls M

[bsc@localhost ~]$ cd linux3 practical

[bsc@localhost linux3]$ pwd

/home/bsc/linux3

[bsc@localhost linux3]$ cd

[bsc@localhost ~]$ cp linux3 linux4

cp: omitting directory ‘linux3’

5) Removing Directories-
[bsc@localhost ~]$ rmdir linux3

[bsc@localhost ~]$ ls linux3

ls: cannot access linux3: No such file or directo


5.1) Deleting Tree Structure –

[bsc@localhost ~]$ rmdir M M/N M/N/O M/N/O/Q

rmdir: failed to remove ‘M’: Directory not empty

rmdir: failed to remove ‘M/N’: Directory not empty

rmdir: failed to remove ‘M/N/O’: Directory not empty

[bsc@localhost ~]$ ls m

ls: cannot access m: No such file or directory

5.2)rmdir -p
[bsc@localhost ~]$ mkdirrdx.lst

[bsc@localhost ~]$ rmdir -p rdx.lst

[bsc@localhost ~]$ lsrdx.lst

ls: cannot access rdx.lst: No such file or directory

6)chmod (Change file access permissions) -

6.1) List the Attributes (ls -l) -


[bsc@localhost ~]$ ls -l

total 364

drwxrwxr-x. 4 bscbsc 24 Oct 9 22:26 A

-rwxrwxr-x. 1 bscbsc 8360 Sep 21 20:06 add

-rwxrwxr-x. 1 bscbsc 8360 Sep 21 20:57 add1

-rw-rw-r--. 1 bscbsc 97 Sep 21 20:56 add1.c

-rw-rw-r--. 1 bscbsc 111 Sep 21 20:05 add.c

-rw-rw-r--. 1 bscbsc 12 Sep 25 13:56 Alpha1

--w--w----.1 bscbsc 12 Sep 19 16:28 alpha.lst


---xr--rwx. 1 bscbsc 69 Sep 19 13:14 bsc

-rw-rw-r--. 1 bscbsc 49 Sep 19 15:24 bsc1

drwxrwxr-x. 2 bscbsc 6 Sep 19 14:30 bsc4

drwxrwxr-x. 2 bscbsc 6 Sep 19 14:35 bsc5

-rw-rw-r--. 1 bscbsc 69 Sep 19 13:18 bscty

drwxrwxr-x. 2 bscbsc 32 Sep 19 13:55 bscty1

-rw-rw-r--. 1 bscbsc 0 Sep 19 13:13 cat

-rw-rw-r--. 1 bscbsc 138 Oct 9 16:56 class.cpp

drwxr-xr-x. 2 bscbsc 46 Sep 13 17:10 Desktop

-rwxrwxr-x. 1 bscbsc 8360 Sep 21 20:37 div

-rw-rw-r--. 1 bscbsc 109 Sep 21 20:37 div.c

drwxr-xr-x. 2 bscbsc 6 Sep 12 22:51 Documents

drwxr-xr-x. 2 bscbsc 6 Sep 12 22:51 Downloads

-rw-rw-r--. 1 bscbsc 0 Sep 19 15:34 file

-rw-rw-r--. 1 bscbsc 12232 Sep 25 13:39 files

-rw-rw-r--. 1 bscbsc 29959 Sep 25 15:00 flies

drwxrwxr-x. 2 bscbsc 6 Sep 25 13:38 linux

drwxrwxr-x. 2 bscbsc 6 Sep 25 14:15 linux1

-rw-rw-r--. 1 bscbsc 434 Oct 9 17:30 ltoclass.cpp

drwxrwxr-x. 3 bscbsc 15 Oct 9 22:27 M

-rwxrwxr-x. 1 bscbsc 8360 Sep 21 19:56 mahi

-rw-rw-r--. 1 bscbsc 45 Sep 21 19:55 mahi.c

-rw-rw-r--. 1 bscbsc 382 Sep 27 19:03 marks.cpp

-rw-rw-r--. 1 bscbsc 16384 Oct 9 22:31 mj.lst

-rw-rw-r--. 1 bscbsc 44 Oct 9 21:32 mj.txt

-rwxrwxr-x. 1 bscbsc 8360 Sep 21 21:02 mul


-rwxrwxr-x. 1 bscbsc 8360 Sep 21 21:02 mul1

-rw-rw-r--. 1 bscbsc 97 Sep 21 21:01 mul1.c

-rw-rw-r--. 1 bscbsc 109 Sep 21 20:33 mul.c

drwxr-xr-x. 2 bscbsc 6 Sep 12 22:51 Music

-rw-rw-r--. 1 bscbsc 13 Oct 9 22:11 mx.txt

-rw-------. 1 bscbsc 102 Oct 9 21:34 nohup.out

-rw-rw-r--. 1 bscbsc 389 Oct 4 17:28 object.cpp

-rw-rw-r--. 1 bscbsc 411 Sep 27 18:21 odd.cpp

-rwxrwxr-x. 1 bscbsc 8360 Sep 21 20:44 peru

-rw-rw-r--. 1 bscbsc 45 Sep 21 20:44 peru.c

drwxr-xr-x. 2 bscbsc 6 Sep 12 22:51 Pictures

drwxr-xr-x. 2 bscbsc 6 Sep 12 22:51 Public

-rw-rw-r--. 1 bscbsc 36 Oct 9 21:57 rdj.txt

-rwxrwxr-x. 1 bscbsc 9032 Oct 9 18:04 r.out

-rw-rw-r--. 1 bscbsc 248 Sep 13 17:02 scope.cpp

-rwxrwxr-x. 1 bscbsc 8360 Sep 21 20:41 sonu

-rw-rw-r--. 1 bscbsc 45 Sep 21 20:40 sonu.c

-rwxrwxr-x. 1 bscbsc 8360 Sep 21 20:48 sss

-rw-rw-r--. 1 bscbsc 98 Sep 21 20:48 sss.c

-rw-rw-r--. 1 bscbsc 393 Oct 9 17:51 static.cpp

-rw-rw-r--. 1 bscbsc 420 Oct 9 18:10 staticm.cpp

-rwxrwxr-x. 1 bscbsc 8984 Oct 4 17:23 static.out

-rw-rw-r--. 1 bscbsc 61 Sep 25 13:26 stud

-rw-rw-r--. 1 bscbsc 61 Sep 25 13:27 stud1

-rw-rw-r--. 1 bscbsc 62 Sep 25 13:44 students

-rwxrwxr-x. 1 bscbsc 8360 Sep 21 20:16 sub


-rwxrwxr-x. 1 bscbsc 8360 Sep 21 20:53 sub1

-rw-rw-r--. 1 bscbsc 45 Sep 21 20:52 sub1.c

-rw-rw-r--. 1 bscbsc 112 Sep 21 20:15 sub.c

-rw-rw-r--. 1 bscbsc 63 Sep 19 16:08 suenm1

-rw-rw-r--. 1 bscbsc 63 Sep 19 16:01 surnm

-rw-rw-r--. 1 bscbsc 63 Sep 25 13:30 surnm1

drwxr-xr-x. 2 bscbsc 6 Sep 12 22:51 Templates

-rw-rw-r--. 1 bscbsc 12 Sep 18 21:06 terminal

-rw-rw-r--. 1 bscbsc 321 Oct 9 17:49 this.cpp

-rw-rw-r--. 1 bscbsc 0 Sep 25 15:05 typescript

drwxr-xr-x. 2 bscbsc 6 Sep 12 22:51 Videos

-rw-rw-r--. 1 bscbsc 55 Sep 13 20:41 welcome.c

6.2) Current Permission :


[bsc@localhost ~]$ ls -l mx.txt

-rw-rw-r--. 1 bscbsc 13 Oct 9 22:11 mx.txt

Chmod (changing user and other permissions to rw only)

Using Symbolic notifications –

[bsc@localhost ~]$ chmoduo=rw mx.txt

[bsc@localhost ~]$ ls -l mx.txt

-rw-rw-rw-. 1 bscbsc 13 Oct 9 22:11 mx.txt

[bsc@localhost ~]$ chmod 220 mx.txt

[bsc@localhost ~]$ ls -l mx.txt

--w--w----. 1 bscbsc 13 Oct 9 22:11 mx.txt