Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
Okay, this is not intended to start some big "Linux vs. Windows" debate. They both have their strengths and, without explicitly stating my opinion and preference, they both have appropriate functionality for their advocates. And I'm no n00b to either OS, although I have a LOT more to learn about Linux before it is my primary OS. And Linux will never (and I don't think it should) run Windows games like Windows. I do hope to find acceptable FPS as well as more of other games on Linux in the future. But I digress.
My concern and question is very specific:
- How do I get ls to list directories before other file types, as dir does in Windows?
That is all - I want to be able to sort the results list so that directories are at the top OR bottom of the list, rather than intermixed with the other file-types.
That's good info (thanks, sincerely) but it does not accomplish what I'm trying to do - which is get my listing of files that are not directories listed with the directories, yet sorted apart from the directories.
You're not the first person to ask about this. As far as I know, ls has no option to list directories first. and files afterward. You'll need to combine ls with other utilities or go a completely different route.
I think the closest so far has been PTrenholme's suggestion. I didn't have any luck getting dir or ls -u to do what you need on my system. But using sort gives some mixed results sometimes. The owner, group, filesize, and other fields will influence the sort and might put the listing out of alphabetical order. If what I assume is right, you want directories first (in alphabetical order) followed by files (in alphabetical order).
I can't think of any "clean" way to do it off-hand. However, here's a nasty way (which you could shove into an alias):
You can copy it directly to a command line and try it if you like. Be careful, because this behemoth of a command will break if you have any filenames that contain double quotes as a part of the filename. There's probably a way to work around that, but this works reasonably well.
Anyway, there may be a cleaner way to do it, but it'll likely require a shell/perl/python script. Once it's put in an alias, it won't matter how long it is
Last edited by Dark_Helmet; 11-16-2005 at 01:54 AM.
I did not, and never will, intend to start an argument. And I hope that this is not the case. I hope the exchange is all about educating users (like me) and not a bruised ego.
Don't get me wrong - I love an animated debate. As long as it's just that - debate. An exchange of facts, or opinions supported by facts. But there are enough angry people starting fires all over the web to have LQ get any smokier on my account.
In any event, this is obviously something that CAN be done - just not as simply and easily as dir. I thank everyone for their input and hope to hear from you in the future.
An argument? Nah, I don't think so. At least, I didn't take it as such. And I wasn't "picking a fight" either. From my perspective, I was just saying a plain sort is a good start. Things get developed by a process of refinement. That's how everything works.
Actually, I never even thought to try multiple -k options to sort. I tried to do "-k 1,9" and that got me nowhere. So then I went on to develop the other method.
There are virtually an infinite number of ways to do anything. And there's usually at least one that's "better." In my case, there's usually 100 better ways.
Distribution: Mandriva mostly, vector 5.1, tried many.Suse gone from HD because bad Novell/Zinblows agreement
In any event, this is obviously something that CAN be done - just not as simply and easily as dir
I think you need to see it from the flexibility view point.
ls is not dir,
old habits dies hard. I programmed an alias called dirr that always tell me the HD space left after a ls operation
ls is more flexible
ls can be made to behave like dir, this a programation / seting issue
But once it is implemented it is as simple as typing dir or dirr or whatever.
It is as easy as dir if implemented.
I think linux score very high on this
If you want a clone of dir behaviour, this is another story. You can create a patch,
a utility, whatever, and it may get into some distro, and it will be there for all.
I agree with what you may be saying: a utility cloning dir maybe a nice thing,
and may help to win over more people to linux. At the same time if you know
about dir then you know of CLI, then you know better than just clicking,
so maybe a clone is not that important. If it is important to you, well create
a sourceforge project. I will give you my "patch" for the HD space
I cannot remember the link but there is ftp repository in the uk with
all sort of short scripts to erase, move, shred
gvaught, did you notice how by default in linux the rename function does not work the same
AFAIK you cannot do mv file??name.jpg file??name.jpeg (have no pc here to test it)
(or one of this command with * and ? that can be done with dos is very different within linux)
Also there has been tutorial around about the advanced ls usage because the gnu ls
has not well known flags etc to do with date format (<> dates whether file is > or < 6 month old)
Originally posted by gvaught
In any event, this is obviously something that CAN be done - just not as simply and easily as dir. I thank everyone for their input and hope to hear from you in the future. [/B]
Well, ease is a relative thing. Would you say that implementing "ls" in Windows will be easier than "dir" in Linux, for instance?
Okay, okay. ls is *not* a dir. And Linux is not simply a Windows replacement.
Yes, I do understand that ls is more flexible and therefore, in my book, more powerful. I've read a lot of good ideology, which I happen to agree with, over the last few days. I have an entirely new perspective on what it is I could and should be doing as a Linux user. Not the least of which is build my own tools.
I appreciate all of the feedback and help - both programmatically and philosophically. As with most things in this world, just about the time I started feeling like I was beyond beginner or n00b, I find out that there are not enough hours in the day or years in my life to get beyond padwan.
At this point, I have to thank George Lucas for adding that word to our vocabulary. Whether you liked the movies or not, the concept is valid and it is expressed with two simple, little syllables.