Create file and display file contents in Linux using cat command.

 

Create file and display file contents in Linux using cat command.

 

   There is many way display the contents of file to the screen and there is so many way to creating a file in Linux. The most simples way to create file is using the cat command.  Linux cat command ( concatenate ) also can be use to display files contents to you computer screen for viewing.

 

Linux command name: cat

 

Cat command description:

   The cat command is short for concatenate files and the command will print the file contents to the standard output (normally your PC screen), and cat also can be use to create file on Linux system.

 

Command type:

   External Linux command (disk file) and the execution file for cat located in /bin directory.

 

[root@fedora ~]# type cat

cat is hashed (/bin/cat)

[root@fedora ~]# type -t cat

file

[root@fedora ~]#

 

The cat command is short for concatenate files and the command will print the file contents to the standard output (normally on your PC screen), and cat also can be use to create file on Linux system.

 

Create a file in Linux using cat command.

 

Below is an example to create using cat command to create file.

 

[root@fedora ~]# cat > create-linux-file.txt

this is my file

Create file in linux using cat command

my filename is create-linux-file.txt

 

[root@fedora ~]# ls

anaconda-ks.cfg Desktop install.log.syslog

create-linux-file.txt install-fedora.log X.txt

[root@fedora ~]#

 

[root@fedora ~]# cat create-linux-file.txt

this is my file

Create file in linux using cat command

my file name is create-linux-file.txt

[root@fedora ~]#

 

   The command above will create a file called linux-command-list and to finish your work press Ctrl+d after the line break (press Enter key after your last line of text) to denote the end of file.  Please note that the standard symbol of redirection ' > ' (greater than) sign is necessary to create a new file.  The ls command use on above example is to verify the existence of the newly created file.

 

Appends text to file using cat command.

 

  The example below show the cat command with the appends ' >> ' redirection symbol to add more text to the file that we create earlier (create-linux-file.txt file).

 

[root@fedora ~]# cat >> create-linux-file.txt

this is the line appends to create-linux-file.txt

this is an example on using redirection to appends text

 

[root@fedora ~]# ls

[root@fedora ~]# cat create-linux-file.txt

this is my file

Create file in linux using cat command

my file name is create-linux-file.txt

this is the line appends to create-linux-file.txt

this is an example on using redirection to appends text

[root@fedora ~]#

 

To finish your work press Ctrl+d after the line break.  The next shell prompt suppose to appear after you press Ctrl+d key.

 

Display file contents on Linux system using cat command.

 

  There is many way to display file contents in Linux system, one of the easiest and simplest way to display the file contents is using cat command.

 

Note: Remember that we already create text file name create-linux-file.txt, now the procedure below show how to use cat command to display the file contents to the screen.

 

[root@fedora ~]# cat create-linux-file.txt

this is my file

Create file in linux using cat command

my file name is create-linux-file.txt

this is the line appends to create-linux-file.txt

this is an example on using redirection to appends text

[root@fedora ~]#

 

Note:

To display the file contents you don't need any redirections sign (no '>' or '>>'), just issue the cat command and the filename of file that you wish to display.

All the file contents display immediately after you issue the command.

The file contents display on the line after the command, and the file content finish before the next shell prompt.

 

There is many options for the cat command that you can experiment with.

 

[root@fedora ~]# cat -n create-linux-file.txt

    1   this is my file

    2   Create file in linux using cat command

    3   my file name is create-linux-file.txt

    4   this is the line appends to create-linux-file.txt

    5   this is an example on using redirection to appends text

[root@fedora ~]#

 

The cat command with the '-n' option will display the file contents with the numbered output lines on the screen.

 

The following are some of the flags and arguments that can be used for the cat command:

 

-A, --show-all   =>   equivalent to -vET

-b, --number-nonblank   =>   number nonblank output lines

-e   =>   equivalent to -vE

-E, --show-ends   =>   display $ at end of each line

-n, --number   =>   number all output lines

-s, --squeeze-blank   =>   never more than one single blank line

-t   =>   equivalent to -vT

-T, --show-tabs   =>   display TAB characters as ^I

-u   =>   (ignored)

-v, --show-nonprinting   =>   use ^ and M- notation, except for LFD and TAB

    --help   =>   display this help and exit

    --version   =>   output version information and exit

 

NAME:

cat - concatenate files and print on the standard output

Usage: cat [OPTION] [FILE]...

 

For more in formations on using cat command:

[root@fedora ~]# info cat

[root@fedora ~]# man cat

[root@fedora ~]# cat --help

 

Keywords: append file, append text, open file, read file, create file, create linux file, read linux file, create file using cat, cat command, cat file, concatenate file, display file, print output to screen, display to computer screen.

 

7 comments

8
Jan

software programming & designning

I want to know about how creat a file command with fedora..

8
Jan

for thanks

thanks veryyyyy muchhhhhh

18
Apr

Linux Administrator

hi I am rajasekaran, i am a windows based admin, i am a new commer for linux, so please help me learn linux

18
May

How to Install Linux

I don't know how to install the linux operating system....
Anybody knw how to install linux os...

12
Dec

Help me

I need someone help me to learn about use fedora command ......

29
Jun

cat as a filter

Hi there.
Can any ony tell me how to merge two similar files and then filter the results to only show the differences in fedora core 6?
HEEELPPPPPPPPPP.

25
Sep

Very Very Thank you to a

Very Very Thank you to a website Administrator for this Help.
this command is very very helpful to my project.

it's really awesome......................;)

aaaaaaaaaaa