LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-27-2017, 04:48 PM   #1
fmd
LQ Newbie
 
Registered: Nov 2017
Posts: 2

Rep: Reputation: Disabled
Please advise on how to remove directories that only contain one or more specific file types


Greetings,

Could you please advise how to recursively remove directories if the directory only contains *.jpg, and/or *.jpeg ?

Itunes 'organized' my music at one point resulting in many directories that don't contain music, which I would like to remove.

thank you greatly--
Derek
 
Old 11-27-2017, 07:09 PM   #2
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 4,693

Rep: Reputation: 1576Reputation: 1576Reputation: 1576Reputation: 1576Reputation: 1576Reputation: 1576Reputation: 1576Reputation: 1576Reputation: 1576Reputation: 1576Reputation: 1576
Welcome to LQ!
I would write a little script to do this. This might give you some ideas.
Code:
#!/bin/bash

# Recursively prints a list of *.jpg and *.jpeg files
# with a count of the number of files in the containing directory

shopt -s globstar

for f in **/*.jp{,e}g; do
  count=$(ls -1 "${f%/*}" | wc -l)
  echo "$f $count"
done

shopt -u globstar
 
2 members found this post helpful.
Old 11-27-2017, 09:13 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 16,001

Rep: Reputation: 2219Reputation: 2219Reputation: 2219Reputation: 2219Reputation: 2219Reputation: 2219Reputation: 2219Reputation: 2219Reputation: 2219Reputation: 2219Reputation: 2219
Cute.
The wonderful thing about this business, is that there is always something to learn.
 
Old 12-02-2017, 11:09 AM   #4
fmd
LQ Newbie
 
Registered: Nov 2017
Posts: 2

Original Poster
Rep: Reputation: Disabled
thanks a lot allend--

Quote:
Originally Posted by allend View Post
Welcome to LQ!
I would write a little script to do this. This might give you some ideas.
Code:
#!/bin/bash

# Recursively prints a list of *.jpg and *.jpeg files
# with a count of the number of files in the containing directory

shopt -s globstar

for f in **/*.jp{,e}g; do
  count=$(ls -1 "${f%/*}" | wc -l)
  echo "$f $count"
done

shopt -u globstar
thanks a lot allend
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to Allow Specific File types on Samba Share ? keysys Linux - Server 1 12-28-2012 08:58 PM
[SOLVED] Hiding directories and file-types from grep? Shay Linux - General 1 08-19-2011 04:38 PM
Command For Finding Specific File Types? forkbeard Linux - Newbie 7 10-16-2009 01:02 AM
Keep specific file types, delete the rest ? jchambers Programming 5 11-26-2007 07:25 PM
How to remove certain types of file? heislyc Linux - General 5 02-17-2006 01:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration