Linux

Linux Cat Command Examples for Beginners

Linux Cat Command Examples for Beginners

Insight: Linux Cat Command Examples for Beginners

If you are a regular or let’s say experienced Linux users then you must be aware of Cat command in Linux. This Linux cat command tutorial is for beginner level of users who are new into the Linux command environment.

10 Linux Cat Command Examples for Beginners

Cat command is basically used for displaying contents of a file.

1. Display the contents of a file:

Run the following command to display the contents of a file:

cat filename.txt

2. Display the contents of multiple file:

Run the following  command if you want to display the contents of multiple file:

cat filename1.txt  filename2.txt

3. Display contents of file with line numbers

Run the following command if you want to display contents of a file with line numbers printed at the beginning of each line.

$ cat -n  filename.txt

4. Copy the contents of one file to another file

Run the following command to copy the contents of one file to another file in Linux:

cat filename1.txt > filename2.txt

 

5. Create file using cat command

Run the following command to create a file using cat command. Follow the onscreen instructions. Once you’re done, just press CTRL+d.

cat > newfile.txt

6. Make cat suppress repeated empty lines

Run the following command to suppress repeated empty lines in output with -s command line option.

cat -s [filename]

For example:

cat -s filename.txt


7. Display non printing characters

If you want to display non-printable characters. This can be done using the -v option.

cat -v [filename]

For example:

cat -v filename.txt

8. Display tab characters as ^I 

READ THIS ALSO  Replicate SELinux Policies In Linux Machines [CentOS]

This can be done by using the tool’s -T option.

cat -T [filename]

For example:

cat -T filename.txt


9. How to make cat highlight line-ends

Run the cat command using -E command line option.

cat -E [filename]

For example:

cat -E filename.txt

10. Cat  command with the -A option

Use the -A option if you need to use the -v, -E and -T option together. It will be easy to use -A option instead of writing -vET in the command.

cat -A  [filename]

For example:

cat -A filename.txt