Monday, 7 March 2016

Creating a file using cat and touch command and Deleting files using rm command

Cat: This command is used to display,concatenate files,create new files ,open and append data in existing files.


a)Create a new file:
                             Syntax:$cat >  <filename>
                                                  ---statements---
                                                      control d
Ex:
$cat>file1
India is a beautiful country and with huge population.In India people belongs to different-different religion and culture living together peacefully.
control d                                    

b)Open an existing file:
                                   Syntax:$cat< <filename>
                                                          or
                                               $cat <filename>
Ex:
$cat file1                                                                      

c)Appending data to the file:
                                                Synatx:$cat>> <filename>
Ex:
$cat>>file1
                                                                   
After append
                                                                         

To open multiple files:
                                      Syntax:$cat <filename1> <filename2> <filename3>...<filenamen>
Ex:
$cat file1 file2 file3
                                                                           

d)touch: Touch is standard unix command line interface program which is used to create empty file (zero byte file). Basically it is used to update the access date and/or modification  date of a file or directory. In it's default usage, it is equivalent of creating or opening a file and saving it without any change to the file contents.
Touch command is used to create several empty files quickly and also it does not allow to store anything in a file.

                                      Syntax:$touch <filename>
Ex:
$touch Demo

we can also create multiple empty file(zero byte) files using touch command
                                Syntax:$touch <filename1><filename2><filename3>.......<filenamen>
Ex:
$touch f1 f2 f3

touch command having following options:
i) -a, change the access time only
ii) -c, if the file does not exist, do not create it
iii) -d, update the access and modification times
iv) -m, change the modification time only
v) -r, use the access and modification times of file
vi) -t, creates a file using a specified time

Deleting Files:
                     
a) rm: rm command is used to delete a file
                                      Syntax:$rm <filename>
Ex:
$rm file1
                                     

b)rm -i <filename> : It deletes a file with confirmation.
Ex:
$rm -i file2
It ask for confirmation, press y for yes or n for no
                                                                   

c)rm -f <filename> : It deletes a file forcibly.
Ex:
$rm -f file3


To deleting multiple files : By using rm command we can delete multiple files.
                                    Syntax:$rm <filename1> <filename2><filename3>...<filenamen>
Ex:
$rm f1 f2 f3
d)rm * : To remove all files from current directory.
first we check all files in current directory by using ls command and then then remove all files using rm * command.








No comments:

Post a Comment