LinuxQuestions.org
Visit the LQ Articles and Editorials section
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 10-26-2009, 12:56 AM   #1
pinga123
Member
 
Registered: Sep 2009
Posts: 676
Blog Entries: 2

Rep: Reputation: 36
How to list directories only


Hi guys how can i list only directories using ls
 
Old 10-26-2009, 01:14 AM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
use find
Code:
find . -type d
 
Old 10-27-2009, 12:14 AM   #3
pinga123
Member
 
Registered: Sep 2009
Posts: 676
Blog Entries: 2

Original Poster
Rep: Reputation: 36
How do i list only hidden files.
 
Old 10-27-2009, 12:19 AM   #4
bsat
Member
 
Registered: Feb 2009
Posts: 347

Rep: Reputation: 72
list only directories using ls

ls -l | grep ^d

list only hidden files

ls -a | grep ^"\."
 
Old 10-27-2009, 12:21 AM   #5
pinga123
Member
 
Registered: Sep 2009
Posts: 676
Blog Entries: 2

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by bsat View Post
list only directories using ls

ls -l | grep ^d


list only hidden files

ls -a | grep ^"\."
can you please tell me the use of ^
 
Old 10-27-2009, 12:23 AM   #6
pinga123
Member
 
Registered: Sep 2009
Posts: 676
Blog Entries: 2

Original Poster
Rep: Reputation: 36
How to find hidden files using find command.
 
Old 10-27-2009, 12:23 AM   #7
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
Code:
find . -type f -name ".*"
 
Old 10-27-2009, 12:26 AM   #8
pinga123
Member
 
Registered: Sep 2009
Posts: 676
Blog Entries: 2

Original Poster
Rep: Reputation: 36
can you please tell me the use of ^
 
Old 10-27-2009, 12:28 AM   #9
pinga123
Member
 
Registered: Sep 2009
Posts: 676
Blog Entries: 2

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by ghostdog74 View Post
Code:
find . -type f -name ".*"
Please find the output of both command i thing ls -a | grep ^"\." is more accurate as it has listed . and .. correctly where as find . -type f -name ".*" only displayed profile hidden file which i think is not the only hidden file .
I m a newbie in unix can you please correct me if i m wrong?
[root@test milind]# ls -a | grep ^"\."
.
..
.profile
[root@test milind]# find . -type f -name ".*"
./.profile
 
Old 10-27-2009, 12:50 AM   #10
etech3
Senior Member
 
Registered: Jul 2009
Location: Virginia
Distribution: Debian Stable Testing Sid Slackware CentOS
Posts: 1,055
Blog Entries: 2

Rep: Reputation: 44
Quote:
Originally Posted by pinga123 View Post
can you please tell me the use of ^
That is the control key on your keyboard
 
Old 10-27-2009, 01:00 AM   #11
snowtigger
Member
 
Registered: Mar 2005
Location: england
Distribution: slackware, win2k
Posts: 364

Rep: Reputation: 34
Regular expression metacharacters

^ = Start of line

so "ls -l | grep ^d" will grep each line of output from ls for lines that begin with d and only d. (it will ignore d in any other position of the line).

 
  


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
How can I list directories only in linux? abefroman Programming 15 01-04-2014 03:27 PM
How to just list directories using ls command shazam75 Linux - Newbie 10 01-26-2006 03:34 PM
list sub-directories only CowboyJ Linux - Newbie 1 12-05-2003 12:42 AM
Asking LS for a list of directories only gary knott Linux - Newbie 1 11-12-2003 06:49 PM
list of directories greg108 Linux - Newbie 5 08-08-2003 04:11 AM


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

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