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 ?

  • What do you mean by two or three extensions, can you clarify on that – sla3k Nov 15 '18 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_Yadv Nov 15 '18 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 '18 at 20:11
  • What about a hidden .ltrace.conf file for instance? – Stéphane Chazelas Nov 15 '18 at 20:31

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'
  • 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_Yadv Nov 15 '18 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... – don_crissti Nov 15 '18 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). – Stéphane Chazelas Nov 15 '18 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.