0

I want to find all html files and only show the file names, not the full file path, what I tried:

find /home/irakli/Desktop/irakli_linux -print | grep -i '.*[.]html'

Results:

/home/irakli/Desktop/irakli_linux/htmll/10.html
/home/irakli/Desktop/irakli_linux/htmll/11.html
/home/irakli/Desktop/irakli_linux/htmll/12.html
/home/irakli/Desktop/irakli_linux/htmll/13.html
/home/irakli/Desktop/irakli_linux/htmll/14.html
/home/irakli/Desktop/irakli_linux/htmll/15.html

I only want 1.html 2.html ...

Ravexina
  • 54,268
  • 25
  • 157
  • 179
Irakli
  • 103
  • 1
  • 1
  • 2
  • @Sergiy I doubt this is a duplicate of [How to Search for Files Recursively into Subdirectories](https://askubuntu.com/questions/307876/how-to-search-for-files-recursively-into-subdirectories). This one particularly asks how to print just the filename (without the path) while the other one asks for `find` in general. – PerlDuck Dec 30 '18 at 11:56
  • @PerlDuck Admittedly, the many top answers don't mention printing only filename without path, however IMHO it's a matter of reading the manual and adding proper flag to the command. I have, however, edited my own answer there to mention some of the flags `find` has, so hopefully that covers it. Alternatively, https://askubuntu.com/a/651321/295286 would probably be a more appropriate, and it pretty much same question in the title. Feel free to vote on reopening, though. – Sergiy Kolodyazhnyy Dec 30 '18 at 12:01
  • @SergiyKolodyazhnyy Congrats on `command-line` gold :) This seems more of a duplicate for printing basename only? – WinEunuuchs2Unix Dec 30 '18 at 14:46
  • @WinEunuuchs2Unix Hi, thanks. I've had `command-line` gold for about 2-3 years now. Check the list of duplicates to this post - there's two, [How do you output the filename in find command while using -exec?](https://askubuntu.com/questions/651315/how-do-you-output-the-filename-in-find-command-while-using-exec) addresses that issue. – Sergiy Kolodyazhnyy Dec 30 '18 at 22:53

1 Answers1

6

There is no need to use grep, find can do exactly what you seek.

Use:

find  -iname "*.html" -printf "%f\n"

It will look for all html files and only prints out their name.

If you want all names at the same line:

find  -iname "*.html" -printf "%f "
Ravexina
  • 54,268
  • 25
  • 157
  • 179