Forum     

Go Back   Digit Technology Discussion Forum > Software > Open Source
Register FAQ Calendar Mark Forums Read

Open Source A place where you can talk to like-minded people about the fastest growing software movement today! Discuss anything and everything about Open Source software and Operating Systems.


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 26-08-2006, 08:17 AM   #1 (permalink)
I see right through you.
 
Sykora's Avatar
 
Join Date: Sep 2005
Location: Chennai
Posts: 597
Question A question about ls.


Is there any way to make the ls command display directories first, then the files? I tried the ls -X switch, and while this puts the directories first, it groups the rest of the fiels by extension, something I don't really want. I want the firectories to be in alphabetical order, followed by the rest of the files, also in alphabetical order Is there a way, by aliases or shell scripts? I'm a bit rusty on shell scripting so I thought I'd ask for help.

--

As a sidenote, I think the digit forums should open a new sub-forum for programming related questions.
__________________
I didn't make the world, I only try to live in it.
http://lucentbeing.com
-- Sykora --
Sykora is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 26-08-2006, 10:30 AM   #2 (permalink)
"The RaCaLaNGeL"©
 
romeo_8693's Avatar
 
Join Date: Dec 2005
Location: Goa/Pune
Posts: 389
Default Re: A question about ls.

i agree with syk,open a dedicated sub-forum for prog...
__________________
Without sorrows happiness would be boring!
romeo_8693 is offline  
Old 26-08-2006, 12:00 PM   #3 (permalink)
Wise Old Owl
 
JGuru's Avatar
 
Join Date: Dec 2005
Location: Space-time continuum
Posts: 1,646
Default Re: A question about ls.

To list only directories, try this command:

$ ls -d */

To pause after a page listing, try this
$ ls -d */ |more

To move to the next page, press the 'TAB' key.

Last edited by JGuru; 26-08-2006 at 12:06 PM.
JGuru is offline  
Old 26-08-2006, 12:28 PM   #4 (permalink)
I see right through you.
 
Sykora's Avatar
 
Join Date: Sep 2005
Location: Chennai
Posts: 597
Default Re: A question about ls.

It seems I haven't made myself clear enough. I want to modify the ls command to list directories first, files later, all in alphabetic order, if possible, ignoring the dot in dotfiles when sorting them. ls -d */ is what I need for directories, but the problem comes in listing only files afterwards.
__________________
I didn't make the world, I only try to live in it.
http://lucentbeing.com
-- Sykora --
Sykora is offline  
Old 26-08-2006, 04:01 PM   #5 (permalink)
String Phreak
 
mediator's Avatar
 
Join Date: Mar 2005
Location: In ur Evil Mind!
Posts: 2,457
Wink Re: A question about ls.

Ahhhhhh............Shellscripting!!!!!!! YAY!
Why do u wanna modify ls?? Ur answer is a shellscript!!
Ok here's what u shud dooo!!

1. ********Save the following as "ls.sh"******************************************* ***************

echo -e "\033[40m"
echo -e "\033[32m"
echo -e "\033[1m"
echo "************FILEZ*************"
while [ $1 ]
do
if [ -f $1 ]; then
echo $1
fi
shift
done

echo -e "\033[33m"
echo "***********Directories********"
ls -d */

echo -e "\033[0m"
echo -e "\033[30m"

************************END OF "ls.sh"******************************************* ***********

2. command "chmod +x ls.sh"
3. Copy the file to any PATH idirectory ......or make a directory "bin" in ur home folder and add it to ur path and then copy "ls.sh" in "bin"!
4. Run as "ls.sh `ls`"

But first test as " sh entire_path/ls.sh `ls` "

Ur problem solved !!.... old buddy O pal!!

Last edited by mediator; 26-08-2006 at 04:07 PM.
mediator is offline  
Old 26-08-2006, 04:49 PM   #6 (permalink)
I see right through you.
 
Sykora's Avatar
 
Join Date: Sep 2005
Location: Chennai
Posts: 597
Default Re: A question about ls.

Can you explain exactly what you've written? I don't understand it, and it's not working. In a folder with only some files and no folders, it returns errors saying "no matches found; */". I'm also trying to make it accept the ls options ie long, all, nobackup, etc.
__________________
I didn't make the world, I only try to live in it.
http://lucentbeing.com
-- Sykora --
Sykora is offline  
Old 26-08-2006, 05:32 PM   #7 (permalink)
String Phreak
 
mediator's Avatar
 
Join Date: Mar 2005
Location: In ur Evil Mind!
Posts: 2,457
Red face Re: A question about ls.

Quote:
Originally Posted by Sykora
Can you explain exactly what you've written? I don't understand it, and it's not working. In a folder with only some files and no folders, it returns errors saying "no matches found; */". I'm also trying to make it accept the ls options ie long, all, nobackup, etc.
Hey man....take it easy! dat was soooo ruuude!! I think u still remember our fight in the fight club!! That was restricted to the fight club only. Anyways.....whateva I have written can be undesrtood even by a newbie.
I help everyperson in this forum irrespective of his name or whateva. Neways I gave u the PERFECT solution. Its upto u to use it.
And about "no matches found"......I dunno what u r saying........I have various kinda of shell scripts I made in last 2 yrs. And this one I gave to a dozen of mah noobie friends. All said "PERFECT".
Neways.....wat can i say.......dont use it then!! And if works lemme know.

Last edited by mediator; 26-08-2006 at 05:35 PM.
mediator is offline  
Old 26-08-2006, 05:36 PM   #8 (permalink)
I see right through you.
 
Sykora's Avatar
 
Join Date: Sep 2005
Location: Chennai
Posts: 597
Default Re: A question about ls.

I use zsh. Could that make a difference?
__________________
I didn't make the world, I only try to live in it.
http://lucentbeing.com
-- Sykora --
Sykora is offline  
Old 26-08-2006, 05:59 PM   #9 (permalink)
String Phreak
 
mediator's Avatar
 
Join Date: Mar 2005
Location: In ur Evil Mind!
Posts: 2,457
Default Re: A question about ls.

Yea it might...i dunno ! Anyways try bash !!
mediator is offline  
Old 26-08-2006, 06:31 PM   #10 (permalink)
I see right through you.
 
Sykora's Avatar
 
Join Date: Sep 2005
Location: Chennai
Posts: 597
Default Re: A question about ls.

I figured it out myself, thanks anyway, mediator, for your help.

For those who want to know, my solution was this :

Code:
alias ls='ls -hl --color=always | grep --color=never ^d; ls -hl --color=always | grep --color=never ^-'
symlinks and other filetypes can be added as necessary.

I'm still waiting for an answer from the mods about a programming subforum...
__________________
I didn't make the world, I only try to live in it.
http://lucentbeing.com
-- Sykora --

Last edited by Sykora; 26-08-2006 at 06:36 PM.
Sykora is offline  
Old 26-08-2006, 09:31 PM   #11 (permalink)
String Phreak
 
mediator's Avatar
 
Join Date: Mar 2005
Location: In ur Evil Mind!
Posts: 2,457
Talking Re: A question about ls.

Ya ur solutions is better.......but is too lengthy. U can make shellscript of it too for simpler use. Also u r using aliasing here.....so u have to put that alias in path or u have to first write that whole code to initialize the shell everytime u open it. Its one and the same thing like I posted mah solution in either case u have to put it in path.

Neways.....Allow me to make ur solution shorter without disturbing the existing ls

Code:
ls -hl | sort
What say?
But if ur satisfied with ur solution then put it in a shellscript!!

Last edited by mediator; 26-08-2006 at 09:48 PM.
mediator is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by Charan
- by Charan

Advertisement




All times are GMT +5.5. The time now is 05:11 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2