The cat ("concatenate") is filter command of operating systems like Linux/Unix. cat command used to create one or more files, view content of file, concatenate different files and can redirect the output to files or terminal. In article of this post, we are going to find out the very basic use cat command and options related to the command with examples in Linux.
Syntax of the command
# cat /etc/test1
Shows content of the test1 file
(2) Content Display for Multiple Files in terminal
# cat test1 test2
Shows content of the test1 and test2 file
(3) cat command to Create file
# cat > test3
create file and open the blank file then, user can write and press CNTRL+D to exit the file and the written content will be saved to file test3.
(4) Redirection Operator Uses Standard Output to overwrite the file content.
# cat test3 > test4
test4 file content will be overwritten by the test file content.
(5) Redirection Operator Uses Standard input to display content in terminal.
# cat < test5
This is content of test5 file.
Here the content of the file test5 will be used as input to the terminal. So, terminal will display the file content.
(6) Multiple Files content Redirecting to a Single File
# cat test test1 test2 > test3
content $ cat sample.txt 1,2,3,4,5,6,7,8,9
$ cat sample.txt | cut -d \; -f 2 > output.txt
$ cat output.txt
2
Syntax of the command
cat [OPTION] [FILE]...
(1) Display File content in terminal# cat /etc/test1
Shows content of the test1 file
(2) Content Display for Multiple Files in terminal
# cat test1 test2
Shows content of the test1 and test2 file
(3) cat command to Create file
# cat > test3
create file and open the blank file then, user can write and press CNTRL+D to exit the file and the written content will be saved to file test3.
(4) Redirection Operator Uses Standard Output to overwrite the file content.
# cat test3 > test4
test4 file content will be overwritten by the test file content.
(5) Redirection Operator Uses Standard input to display content in terminal.
# cat < test5
This is content of test5 file.
Here the content of the file test5 will be used as input to the terminal. So, terminal will display the file content.
(6) Multiple Files content Redirecting to a Single File
# cat test test1 test2 > test3
content $ cat sample.txt 1,2,3,4,5,6,7,8,9
$ cat sample.txt | cut -d \; -f 2 > output.txt
$ cat output.txt
2
No comments:
Post a Comment