The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,814 other followers

Linux command shows a list of all subdirectories that contain a least one .xml file – Thomas Mueller

Posted by jpluimers on 2019/09/09

Via [WayBack] So I don’t forget: The following Linux command shows a list of all subdirectories that contain a least one .xml file… – Thomas Mueller (dummzeuch) – Google+:

[WayBack]Find all subdirectories containing xml files on Linux command line

find . -type f -name '*.xml' | sed -r 's|/[^/]+$||' | sort | uniq

The sed bit is explained in [WayBack] Get list of subdirectories which contain a file matching a string:

The sed command consists of a single substitute. It looks for matches to the regular expression /[^/]+$ and replaces anything matching that with nothing. The dollar sign means the end of the line. [^/]+' means one or more characters that are not slashes. Thus, /[^/]+$ means all characters from the final slash to the end of the line. In other words, this matches the file name at the end of the full path. Thus, the sed command removes the file name, leaving unchanged the name of directory that the file was in.

–jeroen

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

 
%d bloggers like this: