Advertisement

"ls" doesn't show anything anymore.

Started by November 20, 2004 06:46 PM
6 comments, last by Russell 19 years, 10 months ago
I have a machine with Linux Slackware installed. Recently, I was playing with the command 'ls' and I was trying to use it with 'less'.. I did not remember the exact command ( wheter it was "less | ls" or "less > ls", "less < ls", "ls | less", etc.. ), so I tried a few things.. It didn't work.. but after one try, simply writing "ls" would not show anything anymore.. It just waits half a second when I write "ls" and then return to the prompt without displaying anything. I believe all my files are still intact since I can open applications like "vim" without a problem. Any idea what might have caused that exactly and how to fix it? Thanks a lot.
were you trying it as root? you could have overwriten ls by doing less > ls
To be considered a genius you just have to say what everybody knows in a way very few understand
Advertisement
Right, so I overwrote it.
Damn me, I won't work as a root so often anymore.
Any idea where could I get 'ls' again?
Would it be easy to find it on the Slackware cd?
Probably, yeah. In the meantime, you can use "echo *" as a replacement for ls.

EDIT: and of course, playing around with command syntax AS ROOT is really, really dumb. Use this as a learning experience.
To see a list of files without using "ls", use "echo *".

To see whether you screwed up your "ls" command, do "file /bin/ls". If it doesn't say something like "x86 ELF little-endian executable" but instead says something like "text file" then you screwed your /bin/ls.

Your search path may contain the current directory ("."). If you have a file called "ls" in the current directory, "ls" won't work in that directory, in that case. Try something like "cd /tmp; ls". Or try invoking it directly: "/bin/ls".

Oh, and if you have "." in the search path, take it out. It's an invitation for trouble. If you want to run a program in the current directory, specify it as "./program".

Perhaps you have an alias that does the wrong thing? "alias" will show what your aliases are. If "ls" is aliased to something, you can un-alias it by doing "alias ls=/bin/ls".

If you played around as root and screwed your ls, let that be a lession: NEVER TAKE THE NAME OF ROOT IN VAIN. You really should only use it when installing new software, or managing things that you know how to manage. For compiling software, testing things, or learning things, a regular user account is what you want.
enum Bool { True, False, FileNotFound };
Were you in /bin at the time? If not, ls is still there, just hidden by whatever file you created.

Otherwise, ls is probably in one of the basic system packages...
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Advertisement
Thanks for all the tips, the program 'ls' was overwritten when I did 'less > ls', I learned my lesson ;)
I found 'ls' on the slackware cd and I'm gonna retransfer it to my linux pc right away.
Thanks for all these constructive comments ;)
At least you didn't replace ls with rm...

This topic is closed to new replies.

Advertisement