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.
- 78949 reads
- Email this page
7 comments
software programming & designning
Submitted by Curie Rathnayake on Fri, 01/08/2010 - 07:57.I want to know about how creat a file command with fedora..
for thanks
Submitted by Curie Rathnayake on Fri, 01/08/2010 - 08:03.thanks veryyyyy muchhhhhh
Linux Administrator
Submitted by rajasekaran on Sun, 04/18/2010 - 08:14.hi I am rajasekaran, i am a windows based admin, i am a new commer for linux, so please help me learn linux
How to Install Linux
Submitted by Nagaraj on Tue, 05/18/2010 - 17:44.I don't know how to install the linux operating system....
Anybody knw how to install linux os...
Help me
Submitted by Simple (not verified) on Mon, 12/12/2011 - 01:57.I need someone help me to learn about use fedora command ......
cat as a filter
Submitted by Kev Chauval (not verified) on Fri, 06/29/2012 - 08:56.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.
Very Very Thank you to a
Submitted by Deepak Kumar Gupta (not verified) on Tue, 09/25/2012 - 12:47.Very Very Thank you to a website Administrator for this Help.
this command is very very helpful to my project.
it's really awesome......................;)