LinuxQuestions.org
Help answer threads with 0 replies.
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 06-22-2010, 01:59 PM   #1
loftus49
Member
 
Registered: May 2010
Location: Phoenix
Distribution: Ubuntu, CentOS5, Fedora
Posts: 81

Rep: Reputation: 16
List all files by type


Dumb question I couldn't find the answer to.

How do I (in the command line) list all the .txt (or any common attribute) files in a directory?
 
Old 06-22-2010, 02:04 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,

ls -l *txt or ls *txt

Have a look at the man page (man ls) to see all the other options.

Hope this helps.
 
Old 06-22-2010, 02:05 PM   #3
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hi,

There are no dumb questions A couple of possible solutions:
Code:
ls /path | grep "*.txt"
find /path -type f -name '*.txt'
Have a look at the man pages for find, ls, grep.

Kind regards,

Eric
 
Old 06-22-2010, 02:13 PM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
@EricTRA: ls /path | grep "*.txt" ?? How does that work

ls /path | grep ".txt$" or shorter: ls /path/*.txt

BTW: Same "mistake" in the find command *.txt vs .txt
 
Old 06-22-2010, 02:20 PM   #5
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hi druuna,

Of course you're right My mistake, apparently wasn't thinking straight. Thanks for pointing it out. Mixed up commands just like my mind being mixed up for lack of sleep

Kind regards,

Eric
 
  


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
Kate: Append files to existing list and enable the Recent List AGazzaz Linux - Software 2 10-13-2009 09:27 PM
apt-get; E: Type 'GPG' is not known on line 20 in source list /etc/apt/sources.list tomorrow Linux - Newbie 9 05-21-2009 09:42 AM
Downloading a list of files from a remote server using a list ralcocer Programming 2 02-11-2009 02:02 PM
list<type> how can I make type be a pointer? exodist Programming 2 06-06-2005 09:40 AM
c++ list class, type of node? exodist Programming 2 05-20-2004 07:27 PM


All times are GMT -5. The time now is 06:48 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration