Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 22 Sep 2003 15:11:08 -0400 (EDT)
From:      Jerry McAllister <jerrymc@clunix.cl.msu.edu>
To:        mikael.karlsson@hel.fi (Karlsson Mikael HKI/SOSV)
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Re:Re: Cat a directory
Message-ID:  <200309221911.h8MJB8jE012561@clunix.cl.msu.edu>
In-Reply-To: <JA8AAAAAAgMHPAABYQADV7qgzdhU@master.hel.fi> from "Karlsson Mikael HKI/SOSV" at Sep 22, 2003 09:06:00 AM

next in thread | previous in thread | raw e-mail | index | archive | help
> 
> Read my first post before reading this thing so you'll be on the right track!!!!
> 
> >
> >> Other *NIX systems seem to have done this to their cat program so why
> >> can't FreeBSD?
> >
> >See above.

FreeBSD has a better view of the world than some of the kiddie OSes.

> Try to run for example "cat /bin" in Linux, HP-UX, Solaris and other *NIXes 
> and
> I'm 90% certain that they will not show the directory but an error message
> saying something. But then FreeBSD spits out crap which I can't see the point
> of ever using anywhere even when piping a tube up your ass! But since newbies
> do this frequently it shouldn't be possible to do so.
> 
> >> and why is this already done to less and not cat?
> >
> >less is made to display files.  It's the correct tool for the job.
> 
> And you mean that cat is built to show directories and that's the right job 
> for
> cat. Man I must of mised that in school as I thought ls was meant to show
> directories, but hey that's my problem, right? So you mean you use ls to show
> file contents and cat to show directories which workes fine, Or?

You need to review your thinking.  Cat's job is to take the contents 
of a file and send it to STDOUT.   It has a small number of options as
to for form of the output, but otherwise, that is it.   It is not
intended or designed to care if the file is a text, binary, directory, etc
file.   Just to copy file's contents to stdout, period, done, end, get a life!

> 
> Ruben de Groot wrote (19.9.2003  13:34):
> >
> >So why don't you for example alias cat to cat -v in your system profile
> >and login scripts? This will display non-printing characters so they are
> >visible and don't mangle terminal settings.

Yah, do that.   It is a reasonable pervsion of cat's mission.

> So it's better for a newbie to get understandable jibrish from cat when run 
> on
> directories then an error message stating that they are trying to run cat on 
> a
> directory like ls says when they try to run ls on a file. But as I said 
> earlier
> who cares, right? Other OSs have only had this for "a couple" of year so why
> would we!!!

ls writes a formatted display of file information.  That is its purpose in
life.   It doesn't dump contents of files to stdout.   
Just because another OS takes the wrong road doesn't mean that FreeBSD
should also get lost.

> >
> >Why not? I regularly use constructs like this:
> >
> >cat somebackup.tgz | ssh someserver "cd /somedir; tar xzf -"
> >
> 
> Yes, but do you regularly pipe "cat /bin" to another program. If so, why?
> Because isn't cp ment to copy files and directories!

Different thing.
Yes, cat is very often used to pipe file contents to other programs.

> 
> >Because less != cat. It has a completely different functionality.
> 
> I'm aware of that! But as less doesn't show directory contents like ls doesn't
> show file contents I thought it would be a good example.

They are very different things from cat.   They both are intended
to created formatted displays.
> 
> >
> >> Dan Nelson wrote (18.9.2003  17:33):
> >> >
> >> >I find that hard to believe.  Do you also want to block catting of
> >> >executables, gzipped files, jpeg files, database files, and audio
> >> >files?  No OS does that by default.  Maybe you should teach them how to
> >> >reset their terminals when they cat binary data; ^Jreset^J should work,
> >> >assuming your TERM variable is set right.
> 
> No, I don't necessarily want to add all of that but the directory part would be
> a good start. And while we're on the subject of different file types why
> doesn't ls support coloring of different file types like in Linux. As it would
> make finding certain files easier by coloring them differently depending on
> their ending.
> 

Doesn't it?    How many file types do you want to make different colors?
Anyway, that seems to depend on shell.   I can get color differences.

////jerry



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200309221911.h8MJB8jE012561>