various uses of CAT command

cat-catenate command

  • create files
  • Display contents of a file
  • concatenate files
  • Append files

Creating files

  • used to create small files
  • Takes input from keyboard
  • sends output to the monitor
  • syntax:   
                         $ cat -options file name

  • doesnot allow editing, therefore not used to create large files

Example

$cat>fruits
apple
banana
<ctrl d>

$cat >veg
beans
tomato 

Displaying contents of the file 

  • Display only the contents of the file.
  • Doesnot display file name , header or EOF marking
  • Can display contents of more than a file at a time.

Example

$cat fruits
apple
banana

$cat fruits veg
apple
banana
beans
tomato

Concatenate a file

  • Used to concatenate ( merge ) contents of two or more files and store them in another file.
                    $cat file1 file2 >file3
  • if file3 doesnot exist then it will create file3, if file exist then the contents in file3 are overwritten

Example

$cat fruits veg > food
$cat food
apple
banana
beans
tomato

Append files

  • used to add data to a file 
                            $cat >> fruits

Example

$cat >> fruits
pineapple
<ctrl d>

$cat fruits
apple
banana
pineapple

Cat options

  • -v : display nonprintable ASCII characters
  • -n : number of lines in a file
  • -s: silent no errors
ANY DOUBTS RELATED TO TOPIC WILL BE CLARIFIED IN COMMENT SECTION

Please check our youtube channel for visual explaination : 

https://youtu.be/dmzr_eKR0HE


You can join our whats group by clicking the link below:

https://chat.whatsapp.com/K9H81Lb746tH7wMroFuNTx

Comments

Popular Posts