Files

123 lines
7.4 KiB
Plaintext
Raw Permalink Normal View History

Episode: 1273
Title: HPR1273: LiTS 032: cat
Source: https://hub.hackerpublicradio.org/ccdn.php?filename=/eps/hpr1273/hpr1273.mp3
Transcribed: 2025-10-17 22:44:37
---
Welcome to Linux in the Shell episode 31.
My name is Dan Waschko.
I'll be your host and before starting, as always, I'd like to thank Hacker Public Radio
for hosting the website and the audio files.
HackerPublicRadio.org, check it out for some really great content every day of the week
and consider contributing to Hacker Public Radio because they're always looking for new
and fresh voices.
HackerPublicRadio.org.
Today, we're going to talk about the Cat command.
Cat command stands for concatenate, and basically what it does is it takes a file or standard
in and concatenates it or displays it to standard out or, but through redirection to another
file or using a pipe to another command.
Cat basic, but very versatile.
Let's talk about some of the basics switches for Cat command.
Cat, let's say you have a file called test.txt.
Cat test.txt is just going to display the contents of test.txt out to standard out.
So you're going to see that file.
Dash N or dash-number is going to number each line of the output of the file.
So if you do dash cat dash n test.txt, each line of that file is going to have a number
preceding it.
Very basic.
Now you can use a dash B or dash dash number dash non-blank, where the line number will
only be be front or proceed any non-blank line.
So any line that has text or characters on it, it will have a number.
But if it's a blank line, it will not number it.
It will just be a gap there.
But it will still preserve the contents of the file.
If there's a blank line, you'll see the blank line.
There's a dash S or dash dash squeeze blank, which removes repeated empty lines of output.
So if your test file has a number of lines, like a number of sentences, and then you have
a blank line and then a number of sentences, you'll see that blank line.
But if you have, after that blank line, there's four other blank lines for a total of five
blank lines.
You will only see one blank line.
You'll be able to suppress any repeated empty lines in the output.
So the kind of squeezed out is what ends up happening.
The cat command can show non-printing characters with the dash V or dash dash show non-printing,
which can be very handy.
If you are looking at a file, you want to make sure it doesn't have any like DOS line breaks
or anything like that in there.
You could do a cat dash V on the file, and it will show you all the line breaks in their
DOS line breaks or non-printing characters.
If you just cat the file, you won't see them.
If you less or more, or, you know, VI, the file, chances are you may not see them either.
But with the dash V, you can see the non-printing characters pretty handy.
Now if you really want to test this out, a way to get non-printing characters into a file,
you can do like VI or VIM, like VIM test.txt, and if you want to put a non-printing character
in there, you do control M and then control some other character like V. You can put in
there, control M, control V, we give you a non-printable character, which you can test this
out.
The dash E or dash dash show ends to cat command displays a dollar sign at the end of
each line.
So if you're not clear on where a line ends or you want to see line ends, it will put
the dash E, capital E, will show a dollar sign at the end of the line.
And if it's in the blank line, it will show a dollar sign only on that line.
Now that's stuff that's not going to be printed or show up in the file itself regularly
unless you do the dash capital E. So it's not adding anything to your file, just be
aware of that.
You can show tabs in a file, well, technically what it does is it kind of shows tab replacement
tab character.
If the dash capital T or dash dash show tabs, show dash tabs.
And instead of seeing the space where a tab would be, you're going to see a carrot ends
an L instead of, or a carrot and a capital I, sorry, instead of the tab itself.
So you'll see, if you had two tabs, you'd see carrot, capital I, carrot, capital I,
with the dash capital C.
Now some of these commands can be aggregated, instead of having to show each and every,
you know, put each and switch in there, you could do dash lower case E. And what that
does is it combines dash lower case V and capital E together, which means show all non-printing
characters and show the ends of the files.
All right, there's dash T, which combines, you guessed it, lower case V and capital T,
which shows non-printing characters and tabs.
Tab substitution, instead of tabs, you see the tab character.
Then there's dash A for everything, which is combination of dash V, capital E and capital
T. Now it shows all non-printing characters, shows the ends of lines, and shows tabs as
tab replacement character.
If you do not specify a file to the cat commands, it will accept input from standard in, which
means anything you type in standard in and hit enter is going to be echoed back out
on standard out.
Similarly, a dash, or a, yeah, dash for a file will signify to use standard in also.
And you could do some pretty neat stuff with that.
I saw a couple of years ago that the Linux from scratch project, they talked about using
or showed you how to use the cat command as a text editor, a quick and dirty text editor.
So you would type in cat, and you would output that, or redirect the output with a greater
than symbol, to a file like text.txt, and then into that with two less than symbols, you
would put in double quotes, E-O-F, for end of file.
So anything that you typed out after that, standard in would be redirected to test.sh until
you typed on a blank line, capital E-O-F, for end of file, and hit enter, it would stop
the cat command, it would close out the file, and all the stuff that you put in there would
be redirected to the test.txt file, quick and dirty text editor.
You can use a pipe, you can cat a file to a page or like less or more, although you could
already use less or more on the file without having to cat it.
You can cat stuff to grab, cat stuff to cut, whatever other command that you want to cat
things to.
So cat is a very basic, very handy command that you could do a lot with.
By itself, you can get the output of a file, but used in conjunction with redirects and
pipes, it can be a really handy useful tool for cutting things apart and breaking up
information and doing text manipulation.
That's Linux and the Shell Episode 32, the cat command, my name is Dan Waschko, I thank
you for listening, head on over to the website for the full write up and the video of the
document of using the cat command.
We'll see you here again in a couple of weeks and listen to hacker public radio because
some great stuff.
You have been listening to Hacker Public Radio at Hacker Public Radio.
We are a community podcast network that releases shows every weekday on day through Friday.
Today's show, like all our shows, was contributed by a HPR listener like yourself.
If you ever consider recording a podcast, then visit our website to find out how easy
it really is.
Hacker Public Radio was founded by the Digital Dark Pound and the Infonomicom Computer
Club.
HPR is funded by the binary revolution at binref.com, all binref projects are crowd-responsive
by linear pages.
From shared hosting to custom private clouds, go to lunarpages.com for all your hosting
needs.
Unless otherwise stasis, today's show is released under a creative commons, attribution,
shared life, digital license.