Linux FAQ: Can you share some examples of the Unix/Linux
cat command lets you view text files. If you're familiar with MS-DOS, the
cat command is similar to the DOS
cat command gets its name from the word concatenate, and as that name implies, it lets you merge several files together, as you'll see in the examples below.
cat command examples
In its most basic use, the
cat command lets you display the contents of a text file on your screen. For instance, to view the contents of the /etc/passwd file on your Unix/Linux system, use this command:
Combining the cat and more commands
If that file doesn't have many lines, it may all fit on your screen, but if the file has many lines, many of them will scroll off the top of your screen as fast as possible. Therefore, many people type a command like this:
cat my-long-file.txt | more
where they use the
more command to keep the contents from scrolling. However, if that's what you want to do, you're better off using the
more command like this:
Linux cat command: Creating one file from several files
As mentioned, the name
cat comes from the word "concatenate", and the
cat command lets you combine several files into one larger file, like this:
cat file1 file2 file3 > file4
This command combines the contents of the first three files into file4. With this command, file4 is created if it didn't already exist. (Or, it will overwrite file4 if file4 already existed.)
Linux cat command: Showing line numbers
You can show line numbers when "catting out" a file by using the
-n option, like this:
cat -n myfile.txt
This prints the line number before each line that is output.
Linux cat command: Showing non-printing characters
You can show non-printing characters with the
cat command. The
-T option shows TAB characters, like this:
cat -T myfile.txt
-v option shows all non-printing characters, except for line feed and tab, like this:
cat -v myfile.txt
You can also combine those options, like this:
cat -Tv myfile.txt
or use the lowercase
-t option, which is equivalent to using those two flags:
cat -t myfile.txt
More cat command information
For more information, type
man cat at your Linux command line to show the online "manual" for the
cat command. Or if you have examples of the Linux
cat command you'd like to share, feel free to do so in the comments section below.
There's also the standard Linus ethos and fun element here with the "cat -vET foo.txt"
-v (show non-printing)
-E (show Ends or linefeeds) - aka "feeding the cat"
-T (Show Tabs)
so cat -vET is also know as "taking the cat to the vet"
Does anyone know any other ways linux uses commands and switches to make up silly sayings?
Haha, very cool, thanks. I always used the sed command to look at these characters. It's very nice to learn that I can see them with the cat command. Many thanks.
I've got a video that has been split into over 100 pieces. I can't see typing cat zip.001 zip.002 zip.003 and so on forever. Is there some command to get it to roll them up for me?
Depending on the filenames (and the order in which you want them) you can do something like this:
cat * > bigfile.out
or this, which is essentially the equivalent:
for i in `ls` do cat $i >> bigfile.out done
Other than that, put all the filenames into another file named
myfiles, sort the names in that file in the order you want them, and then this should work:
for i in `cat myfiles` do cat $i >> bigfile.out done
I didn't test any of those cat commands, but they look correct.
im using this command
read name;sed /$name/d telephoneregister.txt > deletelist.txt; cat deletelist.txt > telephoneregister.txt;;
I would like an alternative command for
cat deletelist.txt > telephoneregister.txt;;