LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-04-2014, 02:27 PM   #16
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142

Quote:
Originally Posted by Andy_Crowd View Post
listing only directories:
for f in *;do if [[ -d $f ]]; then echo $f;fi; done;
Code:
ls -d */
is much easier to remember and faster to type

Quote:
Originally Posted by Andy_Crowd View Post
listing only files:
for f in *;do if [[ -d $f ]]; then echo "" > /dev/null ;else echo $f ;fi; done;
That is grossly inefficient. Why would you test if it's a directory, and if so echo a newline to /dev/null and otherwise print the name? Why not just test if it's not a directory with [[ ! -d $f ]], or just directly test it's a file with [[ -f $f ]]?
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 10-27-2015, 11:00 AM   #17
wsteinbr
LQ Newbie
 
Registered: Oct 2015
Posts: 2

Rep: Reputation: Disabled
Smile The Easiest way to see Directories

Five keystrokes:

cd<space><Tab><Tab>

If any reply to this and it doesn't have a / at the end, then you have no directories to view.
This lists files and directories. So, if you see that there are many replies, then it would be better to use ls -d */

Last edited by wsteinbr; 10-27-2015 at 11:19 AM.
 
Old 10-27-2015, 11:40 AM   #18
wsteinbr
LQ Newbie
 
Registered: Oct 2015
Posts: 2

Rep: Reputation: Disabled
Another way to see Directories

Another way is:

ls * | grep :

If you want directories and to show files in each directory:

ls *

This most likely is not as good as: ls -d */

Last edited by wsteinbr; 10-27-2015 at 11:46 AM.
 
  


Reply



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 recursively list only directories? Vosper Linux - General 3 07-16-2005 03:57 AM
list sub-directories only CowboyJ Linux - Newbie 1 12-04-2003 11:42 PM
Asking LS for a list of directories only gary knott Linux - Newbie 1 11-12-2003 05:49 PM
list of directories greg108 Linux - Newbie 5 08-08-2003 03:11 AM
Does anyone know how to list directories vertically ? lostboy Linux - General 2 04-07-2003 08:45 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:31 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration