Linux cat command FAQ: Can you share some examples of the Unix/Linux cat command?
The Linux cat command lets you view text files. If you're familiar with MS-DOS, the cat command is similar to the DOS type command.
However, the cat command gets its name from the word concatenate, and as that name implies, the Linux cat command can let you merge several files together, as you'll see in the examples below.
In its most basic use, the Linux 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:
cat /etc/passwd
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 Linux more command like this:
more my-long-file.txt
As I 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.)
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.
You can show non-printing characters with the cat command. The -T option shows TAB characters, like this:
cat -T myfile.txt
The -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 flags:
cat -t myfile.txt
For more information, type "man cat" at your Linux command line to get help. 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.
taking the cat to the vet
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
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.
what about 100 files?
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?
How to cat many files
Depending on the filenames (and the order in which you want them) you can do something like this:
or this, which is essentially the equivalent:
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:I didn't test any of those cat commands, but they look correct.
Urgent
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;;
sed - edit a file in place
Post new comment