Vous êtes sur la page 1sur 5

Exercise 3

Exercise using commands for handling Files

1. Give the command to display the contents of a text file on the


screen.

[16pcsa514@linuxserver ~]$ cat > test2.txt


hello
this is a sample test file
only text is present here.

[16pcsa504@linuxserver ~]$ cat test2.txt


hello
this is a sample text
only text is present here.

2. Give the command to display the contents of multiple text files.

[16pcsa504@linuxserver ~]$ cat test test2.txt


cat: test: Is a directory
hello
this is a sample text
only text is present here.

3. Create a file called cat_test using the cat command. What is the other
way to create a file. When is cat command for creating files used?

[16pcsa504@linuxserver ~]$ cat>cat_test


I love my mom
[16pcsa504@linuxserver ~]$ touch cat_test2
4. Copy the file ex1.doc to cp_ex1.doc. Observe the contents of the files
in ex1.doc and cp_ex1.doc.

[16pcsa504@linuxserver ~]$ cat>ex1.dox


bava
viji
^C
[16pcsa504@linuxserver ~]$ cat ex1.dox
bava
viji
[16pcsa504@linuxserver ~]$ cp ex1.dox cp_ex1.dox
[16pcsa504@linuxserver ~]$ cat cp_ex1.dox
bava
viji

5.Copy the file ex1.doc to unixbackup directory

[16pcsa504@linuxserver ~]$ mkdir unixbkup


mkdir: cannot create directory `unixbkup': File exists
[16pcsa504@linuxserver ~]$ mkdir unixbackup
[16pcsa504@linuxserver ~]$ cp ex1.dox unixbackup
[16pcsa504@linuxserver ~]$ ls
cat_test dept_wise empdata ex33.doc staff test.txt
cat_test2 dir1 empdatt ex3.doc test trans.doc
cp_ex1.dox dir1bkp ex1.dox exp.dat test1.txt unixbackup
cust.dat dir6 ex2.doc file1 test2.text unixbkup
deptgr_wise emp1 ex2.docc file1.doc test2.txt unixpracs
6. Copy the file ex2.doc from unixbackup directory to the current directory
without using path names. Also give a warning option to the user before
copying.

[16pcsa504@linuxserver ~]$ cd unixbackup


[16pcsa504@linuxserver unixbackup]$ cat>ex2.doc
line1 line2 lune3
^C
[16pcsa504@linuxserver unixbackup]$ ls
ex1.dox ex2.doc
[16pcsa504@linuxserver unixbackup]$ cp -i ex2.doc ~/
cp: overwrite `/home/16pcsa504/ex2.doc'? y

7. Move the file ex2.doc from unixbackup to unixpracs with a new name
ex3.doc

[16pcsa504@linuxserver ~]$ mkdir unixpracs


[16pcsa504@linuxserver ~]$ cat > ex33.doc
bava in unixpracs directory
[16pcsa504@linuxserver ~]$ ls
cat_test dir1 ex1.dox ex33.doc staff test.txt
cat_test2 dir1bkp ex2.doc ex3.doc test unixbkup
cp_ex1.dox dir6 ex2.docc file1.doc test2.text unixpracs
[16pcsa504@linuxserver ~]$ mv unixbkup/ex2.docc unixpracs/ex33.doc
[16pcsa504@linuxserver ~]$ cd unixpracs
[16pcsa504@linuxserver unixpracs]$ ls
ex33.doc
[16pcsa504@linuxserver unixpracs]$ cat ex33.doc
line1,line22,line33
8. Rename the ex1.doc in unixpracs to ex4.doc

[16pcsa504@linuxserver unixpracs]$ touch ex1.doc (#touch=for


creating a file#)
[16pcsa504@linuxserver unixpracs]$ mv ex1.doc ex4.doc
[16pcsa504@linuxserver unixpracs]$ ls
ex33.doc ex4.doc

9. Rename the directory unixbackup to temp_backup.

[16pcsa504@linuxserver ~]$ mv unixbackup temp_bkup


[16pcsa504@linuxserver ~]$ ls
cat_test dept_wise empdata ex33.doc staff test2.txt unixpracs
cat_test2 dir1 empdatt ex3.doc temp_bkup test.txt
cp_ex1.dox dir1bkp ex1.dox exp.dat test trans.doc
cust.dat dir6 ex2.doc file1 test1.txt unixbkup
deptgr_wise emp1 ex2.docc file1.doc test2.text unixprac

10. Remove the file ex2 from unixpracs.

[16pcsa504@linuxserver ~]$ cd unixpracs


[16pcsa504@linuxserver unixpracs]$ ls
ex1.doc ex1.docc ex33.doc ex3.doc ex4 ex4.doc file11.doc
[16pcsa504@linuxserver unixpracs]$ rm ex3.doc
[16pcsa504@linuxserver unixpracs]$ ls
ex1.doc ex1.docc ex33.doc ex4 ex4.doc file11.doc

11. Give the command to remove all files from the directory
temp_backup and get a confirmation from the user.

[16pcsa504@linuxserver unixpracs]$ rm -i temp_bkup/*


rm: cannot remove `temp_bkup/*': No such file or directory
[16pcsa504@linuxserver unixpracs]$ cd ..
[16pcsa504@linuxserver ~]$ rm -i temp_bkup/*
rm: remove regular file `temp_bkup/ex1.dox'? y

12.Give the command to display the contents of a file page by page.


Navigate forward and backward.

[16pcsa514@linuxserver ~]$ more -1 ex1.doc


line1
--More--(50%)
line2

Vous aimerez peut-être aussi