 |
26-08-2006, 08:17 AM
|
#1 (permalink)
|
|
I see right through you.
Join Date: Sep 2005
Location: Chennai
Posts: 597
|
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 --
|
|
|
|
Advertisements. Register and be a member of the community to get rid of them.
|
|
Advertisement
|
|
26-08-2006, 10:30 AM
|
#2 (permalink)
|
|
"The RaCaLaNGeL"©
Join Date: Dec 2005
Location: Goa/Pune
Posts: 389
|
Re: A question about ls.
i agree with syk,open a dedicated sub-forum for prog...
__________________
Without sorrows happiness would be boring!
|
|
|
26-08-2006, 12:00 PM
|
#3 (permalink)
|
|
Wise Old Owl
Join Date: Dec 2005
Location: Space-time continuum
Posts: 1,646
|
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.
|
|
|
26-08-2006, 12:28 PM
|
#4 (permalink)
|
|
I see right through you.
Join Date: Sep 2005
Location: Chennai
Posts: 597
|
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 --
|
|
|
26-08-2006, 04:01 PM
|
#5 (permalink)
|
|
String Phreak
Join Date: Mar 2005
Location: In ur Evil Mind!
Posts: 2,457
|
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.
|
|
|
26-08-2006, 04:49 PM
|
#6 (permalink)
|
|
I see right through you.
Join Date: Sep 2005
Location: Chennai
Posts: 597
|
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 --
|
|
|
26-08-2006, 05:32 PM
|
#7 (permalink)
|
|
String Phreak
Join Date: Mar 2005
Location: In ur Evil Mind!
Posts: 2,457
|
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.
|
|
|
26-08-2006, 05:36 PM
|
#8 (permalink)
|
|
I see right through you.
Join Date: Sep 2005
Location: Chennai
Posts: 597
|
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 --
|
|
|
26-08-2006, 05:59 PM
|
#9 (permalink)
|
|
String Phreak
Join Date: Mar 2005
Location: In ur Evil Mind!
Posts: 2,457
|
Re: A question about ls.
Yea it might...i dunno ! Anyways try bash !!
|
|
|
26-08-2006, 06:31 PM
|
#10 (permalink)
|
|
I see right through you.
Join Date: Sep 2005
Location: Chennai
Posts: 597
|
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.
|
|
|
26-08-2006, 09:31 PM
|
#11 (permalink)
|
|
String Phreak
Join Date: Mar 2005
Location: In ur Evil Mind!
Posts: 2,457
|
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
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.
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|