![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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... |
|
||||
|
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? |
|
||||
|
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. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|