0

I need to find the size of all files in /etc with the .conf extension. I tried to do this with find /etc -type f -name "*.conf" -exec du -chB1 {} +, but find gave me .conf files that have two or three extensions. The question is how can I filter find output in order to get just the files with one extension, that being .conf ? Can this be achieved through find or do I need another command ?

4
  • What do you mean by two or three extensions, can you clarify on that
    – sla3k
    Nov 15, 2018 at 20:04
  • How do you define an extension? What if the file name is a.b.conf. Where a.b is file name and .conf is an extension?
    – Prvt_Yadav
    Nov 15, 2018 at 20:10
  • Well, for example I wanted to find file names like this one /etc/pam.conf, but instead the command above would give me something like this too /etc.dbus-1/system.d/org.freedesktop.bolt.conf
    – george
    Nov 15, 2018 at 20:11
  • What about a hidden .ltrace.conf file for instance? Nov 15, 2018 at 20:31

1 Answer 1

0

You could exclude the file names that contain more than one dot:

find /etc -type f  ! -name '*.*.*' -name '*.conf'

If you still want to print hidden .conf file names (if any, à la /etc/.pwd.lock) then

find /etc -type f ! -name '?*.*.*' -name '*.conf'
3
  • Suppose I am having a file with name a.b.conf. Where a.b is the name of the file and .conf is extension.
    – Prvt_Yadav
    Nov 15, 2018 at 20:09
  • @Debian_yadav - according to you, according to the next guy the file name is a and b is another extension... you know, like tar in tar.gz... Nov 15, 2018 at 20:26
  • One might prefer ! -name '?*.*.*' to allow files named like .socks.conf for instance, where .socks can't possibly be considered as an extension (it's rare to find such files in /etc except maybe in /etc/skel though). Nov 15, 2018 at 20:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .