Find where a kind of file is stored

find . -name '*.desktop' | sed s/[^/]*\.desktop$// | uniq -c | sort -g
In this case searches for where .desktop files are stored. The resulted is a sorted list of the top directories containing such files.
Sample Output
      1 ./usr/share/wayland-sessions/
      2 ./usr/share/gdm/greeter/autostart/
      3 ./usr/share/desktop-base/
      4 ./usr/lib/gnome-settings-daemon-3.0/gtk-modules/
      4 ./usr/share/xsessions/
      7 ./usr/share/gnome/applications/
      8 ./usr/lib/libreoffice/share/xdg/
     22 ./etc/xdg/autostart/
     45 ./usr/share/mimelnk/application/
    161 ./usr/share/applications/

By: T4b
2016-09-16 12:22:38

1 Alternatives + Submit Alt

  • May require the locate package. Locate is awesome, it creates a small file database which is updated once a day or so, or you can do a force update with 'updatedb'. Then you just type in 'locate' with the name of the file or folder that you want and off it goes. Show Sample Output

    locate *.desktop
    Vallamost · 2016-09-21 23:47:39 0

What Others Think

It's always best to quote your sed scripts, especially if they contain '$' Also, you can simplify it, to: ... | sed 's/[^/]\+$//' | ... Search for any non-slash chars at the end of the line.
flatcap · 271 weeks ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: