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. |
purpose built tool for this is find
Code:
find -name "*.html" Code:
find $PWD -name "*.html" it prints the full path many more options to find Code:
man find |
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? |
Code:
locate .html > all_html_files.txt If you recently added some more files you could run Code:
updatedb 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. |
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 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" with find whitespace implies AND, Code:
find $PWD -name "*.html" -a ! -name "Preview.html" you can use -o for OR It can get quite complicated, but once you get into the swing of things you are off.. |
Quote:
|
All times are GMT -5. The time now is 01:22 AM. |