Cat(concatenate) command reads data from the file and gives their content as output.
It helps us to create, view, concatenate files.
Here are some of the use cases of the command :
1. Creating a new file:
$ cat >newfile
Creates a new file called newfile
2. Reading a file:
You may have run into this while checking your os type.
$ cat /etc/os-release
On my Os this outputs:
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
3. Copy the contents of one file to another file.
$cat [filename-whose-contents-is-to-be-copied] > [destination-filename]
4. View multiple files
$ cat file1 file2
Outputs contents in file1 and file2 .
5. Append the contents of one file to the end of another file
$cat file1 >> file2
Will append contents of file1 to file 2
6. Cat command to open dashed files.
$cat -- "-dashfile"
Will display the content of -dashfile
7. Cat command if the file has a lot of content and can’t fit in the terminal.
$cat "filename" | more
8. Merge the contents of multiple files
$cat "filename1" "filename2" "filename3" > "merged_filename"
Will merge the contents of file in respective order and will insert that content in "merged_filename".
9. Display the content of all html files in the folder.
$cat *.html
Will show the content of all html files present in the folder.
10. Write in an already existing file
$cat >> geeks.txt
The newly added text.
Will append the text "The newly added text." to the end of the file.
Top comments (0)