LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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!

Notices

Reply
 
Search this Thread
Old 01-15-2007, 04:24 PM   #1
Lufbery
Senior Member
 
Registered: Aug 2006
Location: Harrisburg, PA
Distribution: Slackware 64 14.0
Posts: 1,142
Blog Entries: 29

Rep: Reputation: 119Reputation: 119
Listing directories first with 'ls' command


Hi all,

I've been working with Linux now for half a year or so. I generally find its command line interface superior to DOS except for one command, the 'ls' command.

I'd like the equivalent of the dir command: 'dir /o:g' which lists directories first.

I've looked at the info and man pages, and I'm not sure how to get 'ls' to do that. If anyone knows please tell me.

Thanks in advance,
 
Old 01-15-2007, 04:51 PM   #2
merchtemeagle
Member
 
Registered: Oct 2004
Location: Belgium
Distribution: Slackware 13.37
Posts: 512

Rep: Reputation: 31
Take a look at http://kim.biyn.com/Linux/How_to_sor..._like_DOS_does
 
Old 01-15-2007, 05:12 PM   #3
Brian1
Guru
 
Registered: Jan 2003
Location: Seymour, Indiana
Distribution: Distribution: RHEL 5 with Pieces of this and that. Kernel 2.6.23.1, KDE 3.5.8 and KDE 4.0 beta, Plu
Posts: 5,700

Rep: Reputation: 61
If you like that command line you can make an alias so you don't have to remember it. Edit your home directory file .bashrc and add a line like this.
alias dir="ls -l | sort -k 1.1,1.2 -k 8.1 -f | less"

Brian
 
Old 01-15-2007, 08:45 PM   #4
Lufbery
Senior Member
 
Registered: Aug 2006
Location: Harrisburg, PA
Distribution: Slackware 64 14.0
Posts: 1,142
Blog Entries: 29

Original Poster
Rep: Reputation: 119Reputation: 119
Great stuff! Thank you.

Regards,
 
Old 01-15-2007, 09:30 PM   #5
Lufbery
Senior Member
 
Registered: Aug 2006
Location: Harrisburg, PA
Distribution: Slackware 64 14.0
Posts: 1,142
Blog Entries: 29

Original Poster
Rep: Reputation: 119Reputation: 119
Okay, that worked, except that the directories are listed after the other files. I guess I'll have to dig into the sort command a bit more.

EDIT: fixed it. I added the -r option to the sort command.

The alias looks like this now:

alias dir='ls -l | sort -k 1.1,1.2 -k 8.1 -r'

I found that there's generally no need to pipe to the less command by default; I can allways type 'dir | less' and get the same result.

Regards,

-Drew

Last edited by Lufbery; 01-15-2007 at 09:47 PM.
 
Old 01-16-2007, 08:10 AM   #6
ecuas
Member
 
Registered: Dec 2006
Location: India
Distribution: openSUSE 10.2/ Gentoo 2006.1
Posts: 50

Rep: Reputation: 15
I hope theres no prob if i post a query of mine.
How can I use the command line to list all files of a particular extension recursively?
What I am trying to do is go to a particular directory and then search all the directories inside this directory for certain filetypes.

I tried ls -R *.mp3 or ls -R *.mp3 ./ but it doesnt work.
If I do ls|grep -R --include==*.mp3 ./ it returns a whole lot of garbage...I know grep searches even for the contents of the file, but just gave it a try.

Im still new to the command line.
 
Old 01-16-2007, 08:22 AM   #7
merchtemeagle
Member
 
Registered: Oct 2004
Location: Belgium
Distribution: Slackware 13.37
Posts: 512

Rep: Reputation: 31
Code:
find . -name "*.mp3"

Last edited by merchtemeagle; 01-16-2007 at 08:23 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
can 'ls' command be recursive? Hailey's_Comet Linux - Newbie 3 10-01-2006 12:29 AM
Listing all directories only anjanesh Linux - Newbie 5 06-20-2006 03:23 AM
Using 'ls' to get full path listing for mp3gain sygin Linux - Software 4 09-06-2005 08:55 AM
How to I flag 'ls' to list only the current sub-directories? davee Linux - Newbie 5 01-18-2005 09:49 AM
'ls' command... sramelyk Slackware 7 10-01-2003 12:45 PM


All times are GMT -5. The time now is 02:03 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration