UNIX

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

cat command- concatenate files

You can redirect the output as follows using shell standard output redirection: $ cat /etc/hosts /etc/resolv.conf /etc/fstab > /tmp/outputs.txt $ cat /tmp/outputs.txt You can also use a pipe to filter data. In this example send output of cat to the less command using a shell pipe as the file is too large for all of the text to fit on the screen at a time: $ cat /etc/passwd | less

cat - create a file

You can use cat command for file creation. To create a file called foo.txt, enter: $ cat > foo.txt Sample outputs: This is a test. To save and exit press the CONTROL and d keys (CTRL+D). Please note that if a file named foo.txt already exists, it will be overwritten. You can append the output to the same file using >> operator: $ cat >> bar.txt he existing bar.txt file is preserved, and any new text is added to the end of the existing file called bar.txt. To save and exit press the CONTROL and d keys (CTRL+D).

cat command syntax

cat filename cat options filename cat file1 file2 cat file1 file2 > newcombinedfile

cat command - Concatenate files

Concatenation means putting multiple file contents together. The original file or files are not modified or deleted. In this example, cat will concatenate copies of the contents of the three files /etc/hosts, /etc/resolv.conf, and /etc/fstab: $ cat /etc/hosts /etc/resolv.conf /etc/fstab

cat command - Displaying The Contents of Files

$ cat /etc/passwd The above command will display the contents of a file named /etc/passwd. By default cat will send output to the monitor screen. But, you can redirect from the screen to another command or file using redirection operator as follows: $ cat /etc/passwd > /tmp/test.txt In the above example, the output from cat command is written to /tmp/text.txt file instead of being displayed on the monitor screen. You can view /tmp/text.txt using cat command itself: $ cat /tmp/test.txt

cat - copy a file

The cat command can also be used to create a new file and transfer to it the data from an existing file. To make copy of $ cat oldfile.txt > newfile.txt To output file1's contents, then standard input, then file2's contents, enter: $ cat file1 - file2 A hyphen indicates that input is taken from the keyboard. In this example, to create a new file file2 that consists of text typed in from the keyboard followed by the contents of file1, enter: $ cat - file1 > file2 cat command options To number non-blank output lines, enter (only works with GNU cat command version): $ cat -b /etc/passwd

cat Command

The cat command is considered as one of the most frequently used commands on Linux or UNIX like operating systems. It can be used for the following purposes under UNIX or Linux: Display text files on screen. Copy text files. Combine text files. Create new text files.


संबंधित स्टडी सेट्स

PrepU Chapter 27: Safety, Security, and Emergency Preparedness

View Set

Measurement, reliability and validity

View Set

Ch 13: Labor and Birth Processes

View Set

Tech Enabled Business Transformation

View Set

Precalculus Chapter 2: Polynomial and Rational Functions - LIONS

View Set

Introduction to AP Government & Politics

View Set

VTHT 1349 Veterinary Pharamcology

View Set