LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 08-07-2013, 04:30 PM   #1
Ferodactyl
LQ Newbie
 
Registered: Aug 2013
Posts: 4

Rep: Reputation: Disabled
How to get file path for specific type of file on my server?


I need to find the file path to all the .html files stored in my directory so that I can easily create links to them for a site map.

How can I do this?

I have tried ls -R | grep \.html$

It does pull out all the html files in my directory but doesn't show the path to them so I can't create the link.

The files are in many different sub-folders.

Thanks for anyone's input. Please let me know if you need more details or if I should rephrase my question - I am totally new to Linux so am not sure if I am explaining my needs correctly.
 
Old 08-07-2013, 04:35 PM   #2
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
purpose built tool for this is find

Code:
find -name "*.html"
^^ very basic, will find files which end .html, relative to current directory

Code:
find $PWD -name "*.html"
the same, but since we give full path to current directory ( with $PWD env var. )
it prints the full path


many more options to find

Code:
man find
for details
 
Old 08-07-2013, 04:54 PM   #3
Ferodactyl
LQ Newbie
 
Registered: Aug 2013
Posts: 4

Original Poster
Rep: Reputation: Disabled
This is really amazing. Thank you!

Just one more question. Is there anything I can add to that command in order to stop it from displaying certain files? I have some files called Preview.html that I don't need to display, so could I do something to show all .html files except Preview.html?
 
Old 08-07-2013, 04:58 PM   #4
dt64
Member
 
Registered: Sep 2012
Distribution: RHEL5/6, CentOS5/6
Posts: 216

Rep: Reputation: 38
Code:
locate .html > all_html_files.txt
would give you a file including all your html files.

If you recently added some more files you could run
Code:
updatedb
before running the above. updatedb usually runs once a day automatically.

This way of doing it might be quicker on file systems with loads of files (especially if you don't have to run the updatedb bit) but would find any html files on your system. You might need to grep out your relevant path/subdirs.
 
Old 08-07-2013, 05:02 PM   #5
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
more than a few

probably the simplest is to pipe the output of find through grep

Code:
find $PWD -name "*.html" | grep -v Preview.html
grep is normally used to show matching lines ( or patterns )
But here we use the -v flag, which inverts it

man grep


you can also get find to do this
Code:
find $PWD -name "*.html" ! -name "Preview.html"
here the ! is NOT , so we are looking for files ending .html AND NOT named Preview.html

with find whitespace implies AND,
Code:
find $PWD -name "*.html" -a ! -name "Preview.html"
is the same, but you won't see it all that often
you can use -o for OR
It can get quite complicated, but once you get into the swing of things you are off..

Last edited by Firerat; 08-07-2013 at 05:04 PM.
 
Old 08-08-2013, 09:21 AM   #6
Ferodactyl
LQ Newbie
 
Registered: Aug 2013
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Firerat View Post
more than a few

probably the simplest is to pipe the output of find through grep

Code:
find $PWD -name "*.html" | grep -v Preview.html
grep is normally used to show matching lines ( or patterns )
But here we use the -v flag, which inverts it

man grep


you can also get find to do this
Code:
find $PWD -name "*.html" ! -name "Preview.html"
here the ! is NOT , so we are looking for files ending .html AND NOT named Preview.html

with find whitespace implies AND,
Code:
find $PWD -name "*.html" -a ! -name "Preview.html"
is the same, but you won't see it all that often
you can use -o for OR
It can get quite complicated, but once you get into the swing of things you are off..
Thank you!
 
  


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
[SOLVED] Search for specific type of file recursively koshy Linux - Newbie 4 03-02-2013 04:15 AM
[SOLVED] Getting full path while using the input type is file in HTML vijaysince89 Linux - Desktop 5 11-29-2010 09:33 PM
[SOLVED] how to make grep to search a pattern in only specific file type mq15 Linux - Newbie 7 03-07-2010 10:41 AM
Get file icon from extension, file type, or mime-type Guitarist88 Programming 3 04-21-2008 11:58 AM
automount specific user's file on an NFS server cememet Linux - Networking 4 05-16-2007 09:45 PM


All times are GMT -5. The time now is 04:27 PM.

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