News for hackers. Stuff that matters.

Cd command is broken

Everyone who knows `cd` kowns there's another command called `ls`. `ls` is always typed after `cd`. Like `cd project`, ls`.

Everyone wants to read child files as soon as he enters a directory, and `ls` is the command.

But why are `cd` and `ls` the same command. Enter a directory is an action, rather than 忒o actions. Suppose you want to open a site called <https://news.ycombinator.com> and you type in the url and hit Enter(like `cd hacker-news`). Then do you need to type in `open` to read?

Hope one day we may fix it.

( 10 comments | 2 points | on HN )
Re:Cd command is broken by nayefc on Tuesday March 26, 2013 @08:01AM (#5442607)
You can add an alias in bash to fix this. Or type dir && ls. Your assumption is wrong. We don't "type ls after cd". Maybe a lot of times, but definitely not most of the times. I memorize my directories from the first time I'm in that I barely need to type ls.
Re:Cd command is broken by jiyinyiyong on Wednesday March 27, 2013 @12:44AM (#5447844)
Still feeling strange that someone remembers all files and pathes. (Or maybe the habbits in China is a bit different. Even I use Bash everyday, I still want to read file list every time I enter a directory.)
Re:Cd command is broken by nayefc on Wednesday March 27, 2013 @05:43PM (#5452193)
I usually cd into the main directory I want to be in and then if I ever want to edit a file, simply typing emacs then tab for bash for auto-completion does the trick.

But again, just use a bash alias :) What's the problem with that?

Re:Cd command is broken by maerF0x0 on Tuesday March 26, 2013 @12:58AM (#5441485)
scripting is your friend:

$ function newcd(){ cd $1; ls;}

$ alias cd=newcd

$ cd ..

$ cd Desktop

EDIT: I had accidentally put a "$1" in the ls command, now removed.

Re:Cd command is broken by jiyinyiyong on Tuesday March 26, 2013 @11:27PM (#5447639)
That's my solution right now. There's a bug I don't kown if you can grt rid of it or not.

When I type `cd a\ dir`, it works, while `c a\ dir` fails. `$1` seems not to cover the whole parameter. Can you fix this?

Re:Cd command is broken by mmozeiko on Tuesday March 26, 2013 @01:06AM (#5441500)
Very often I don't want ls. I want cd X && make. Or cd X && svn up. Or something similar.
Re:Cd command is broken by jiyinyiyong on Tuesday March 26, 2013 @11:29PM (#5447644)
I think it doesn't metter if this command gives several lines more logs. It doesn't do anything else that may break the faollowing command.
Re:Cd command is broken by nayefc on Wednesday March 27, 2013 @05:44PM (#5452197)
Why does this sound like a marketing email/post to me?
Re:Cd command is broken by iamtherockstar on Tuesday March 26, 2013 @01:49AM (#5441598)
Huh? Since when do you always use 'ls' after 'cd' - I can think of many times that I don't need to do this, and it would annoy me if every time I called 'cd' it then printed out the directory listing as well.

The popular Unix mantra is "do one thing and do it well" - both these commands, while definitely connected, are each "one thing" and they both perform them very well.

Re:Cd command is broken by jiyinyiyong on Wednesday March 27, 2013 @07:31AM (#5448761)
The philosophy of Unix convinced me at my first glance. But then found there might be some problem in this case.

Just an example. People may say something offer three features, one plus one and plus one, just like Unix does. But if we are going to explain 99, it is faster to say 100 minus 1 rather than 90 plus 9.

`cd $1 && ls` is a larger command. It's also an easier one.