'cat' eq 'ls'

Ovid on 2007-08-01T09:33:37

I'm so sick and tired of typing "cat $some_dir" or "ls $some_file" that I'm thinking of writing bash functions that will switch the two around, as needed. The cat $some_dir is particularly bad as it really screws up my terminal settings by spewing junk across the screen.


You want "less"

markjugg on 2007-08-01T12:57:39

On Linux, "less" can handle both:

less dir/

less file.txt

However, on the FreeBSD machines I use, "less" can't handle directories, so I don't depend on it for that.

Re:You want "less"

chibiryuu on 2007-08-01T14:01:04

less dir/ only works for me when $ENV{LESSOPEN} is set to an appropriate script, regardless of Linux or BSD.

Wha?

Aristotle on 2007-08-01T16:57:38

cat spews junk? All I get is

$ cat .
cat: .: Is a directory

Btw, blindly typing reset + Enter on a screwed terminal will often fix it.

Re:Wha?

Ovid on 2007-08-01T18:03:43

The reset command breaks my backspace key, though. I could probably source my .bashrc as I think I have something in there to fix it, but I can't recall.

Re:Wha?

chibiryuu on 2007-08-01T18:16:38

Linux typically generates errno=EISDIR on open(".", O_WRONLY) and read(dirfd, …).  IIRC, the latter varies by filesystem on BSD.

mmm

jhi on 2007-08-02T02:31:10

I don't know about swapping but my (z)shell alias 'm' handles directories (ls -sF | less) and files (less), and for certain types of files it does Magic (TM), e.g. for .tar.bz2 it pipes bzip2 -d foo.tar.bz2 | tar tvf - to less (I don't do tar jtvf because I don't have gtar everywhere). Kinda like open(1) in Mac OS X.