How To Assemble Files With Cat Command In Linux/Unix?
 

How To Assemble Files With Cat Command In Linux/Unix?

 

This post was last updated on August 1st, 2020 at 12:38 pm

Linux or Unix provides cat command that can be used to create, view, and concatenate files. It reads the content of a file and prints it on the terminal. As I already discussed to split a large file into multiple smaller files in an article. We can use the cat command to assemble or concatenate these files. In this article, we will discuss creating, viewing, and concatenating files with the cat command.

Syntax of cat command

Following is the syntax of cat command –

cat [options] filename

Or use –

cat > filename

Or use-

cat file1 file2 >file3

You see the details of cat command with the options that can be used with it by using the following command-

man cat

How to create a new file using the cat command?

To create a text file in Linux, use the following command in your terminal –

cat >filename.txt

Now once the above command gets executed, you can start entering your text in the terminal.

And when you are done with writing text, you need to press ctrl+d to save the content of the file.

How to display the content of a text file?

Cat command is frequently used in Linux to display the content of a text file in the terminal. Now use the following command to show the content of a file –

cat filename.txt

 

How to join two text files in Linux using cat command?

You can use the cat command for joining or concatenating files in Linux. Here we will join two files filename.txt and filename1.txt. You can see the content of these two files by using-

cat filename.txt

cat filename1.txt

To join these files, you can use the following command –

cat filename.txt filename1.txt > filename2.txt

Now if you display the content of filename2.txt then you will see that the text of both the files is merged into one file –

cat filename2.txt

How to join binary files using cat command?

You can also concatenate binary files using cat command. Here we will join the pieces of a large backup.tar.gz file. The pieces of this file are created using the split command. You can see the parts of the backup.tar.gz file in the following image-

To combine these parts into original_backup.tar.gz we will use the following command in the terminal –

cat backup* > original_backup.tar.gz

It can take a few minutes to combine these files. Once it gets done, run the following command to see the original_backup.tar.gz file –

ls -lh

Conclusion

In this article, you have learned to create, view, and concatenate files in Linux or Unix. Now if you have any queries related to this topic then please write it in the comments below.

Previous How To Check Current Version Of Ubuntu Using lsb_release Command?
Next How To Split A Large File Into Multiple Smaller Files In Linux/Unix?
 

About author

You might also like

System Security 0 Comments

How To Disable Secure Boot In A System?

This post was last updated on August 1st, 2020 at 12:47 pmSecure boot is a feature of UEFI which ensures that your PC boots only through the firmware that is

Linux Topics 0 Comments

How Systemd Is Different From SysVinit?

This post was last updated on August 2nd, 2020 at 08:03 pmContents1 What Is init2 What is SystemV (SysV)2.1 Runlevels –2.2 Mostly used SysV service commands are –3 What is

FreeBSD 0 Comments

How To Remove A User From A Group In FreeBSD?

This post was last updated on August 1st, 2020 at 12:12 pmI already discussed how to add a user to a group in FreeBSD. This article is about removing a

0 Comments

No Comments Yet!

You can be first to comment this post!

Leave a Reply