The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
regex to remove commentaries and blanks yomaya Shell Programming and Scripting 7 06-18-2009 08:22 AM
regex to remove text before&&after comma chars yomaya Shell Programming and Scripting 3 06-08-2009 06:44 AM
How to deleting some files under subdirectory AdziE Shell Programming and Scripting 4 08-20-2008 09:05 AM
Count files in every subdirectory yorryk Shell Programming and Scripting 3 08-12-2008 06:22 PM
subdirectory password sskb UNIX for Dummies Questions & Answers 1 09-24-2001 06:17 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 4 Weeks Ago
janel10 janel10 is offline
Registered User
  
 

Join Date: Nov 2009
Location: Florida
Posts: 4
Regex to remove subdirectory

I need to remove subdirectories that are empty and I've not done this before. First I am going through the files to remove old records. Then if the directory is empty I want to delete it. There are files in /direcotry/images/fs* - 0-9 and a-z The fs* directories need to stay, but any directories under the fs* directories that are empty need to be removed. Did I explain this ok?
So far I have this:

Code:
DIRECTORY=/directory/images
DATESTAMP="`date '+%m%d%y_%H:%M'`"
LOG_DIR=${TRAFFIC_IMAGE_HOME}/log
LOG=${LOG_DIR}/tiffsRemoved.${DATESTAMP}.txt
# this works fine -- 
for file in $( find $DIRECTORY -type f -name '*.tif' -mtime +15 )
do
  echo $file
  rm -rf $file
done | sort >> "$LOG"

# I can't figure out how to do this- 

for dir in $( find $DIRECTORY -type d -empty )
do
  echo $dir
  grep [0-9] $dir
#  rm -rf $file
done | sort > "$LOG"


Last edited by pludi; 4 Weeks Ago at 05:24 PM.. Reason: code tags, please...
  #2 (permalink)  
Old 4 Weeks Ago
Scrutinizer Scrutinizer is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 745
Assuming there are only subdirectories in $DIRECTORY that start with "fs", this should work:

Code:
find $DIRECTORY/fs*/* -type d -printf "'%p'\n"|sort -r |xargs rmdir 2>&-

  #3 (permalink)  
Old 4 Weeks Ago
janel10 janel10 is offline
Registered User
  
 

Join Date: Nov 2009
Location: Florida
Posts: 4
There are directories under, so this doesn't work. The directories look like this:
/directory/images/fsa/09005573FRA
/directory/images/fsa/09004364EVA

It is these 0900.... directories that need to be removed.
There a literally hundreds of these subdirectories that I need to remove. I guess my question wasn't clear enough. Can you still help me?
  #4 (permalink)  
Old 4 Weeks Ago
Scrutinizer Scrutinizer is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 745
Actually I think that should work. You seem to confirm that there are only subdirectories called fs* (e.g. fsa) in $DIRECTORY (/directory/images). These subdirectories must not be removed but the subdirectories inside these subdirectories do have to be removed if they are empty (i.e. contain no files or further subdirectories).

S.
  #5 (permalink)  
Old 4 Weeks Ago
janel10 janel10 is offline
Registered User
  
 

Join Date: Nov 2009
Location: Florida
Posts: 4
After review, I believe you are right. Thanks,
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:32 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0