LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   List all files by type (https://www.linuxquestions.org/questions/linux-newbie-8/list-all-files-by-type-815715/)

loftus49 06-22-2010 12:59 PM

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?

druuna 06-22-2010 01:04 PM

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.

EricTRA 06-22-2010 01:05 PM

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

druuna 06-22-2010 01:13 PM

@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

EricTRA 06-22-2010 01:20 PM

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 :o

Kind regards,

Eric


All times are GMT -5. The time now is 08:36 PM.