Skip to main content
added 19 characters in body
Source Link
dma1324
  • 107
  • 4

You can use a bash script to do it (not the best way):

#!/bin/bash # Don't screw us up with spaces! IFS=$'\n'; set -f DIRS=$(find . -type d -name "rules") for i in $DIRS; do set +f rm $i/*.pdf done set +f 

This iterates through the directories you find in your find command and removes the pdf's under each directory.

The line IFS=$'\n' is to cope with spaces in file names, and set -f is to cope with wildcard characters. Of course, this is assuming you don't have newlines in any of your filenames. If you do, the solution will become a lot more complicated.

You can use a bash script to do it:

#!/bin/bash # Don't screw us up with spaces! IFS=$'\n'; set -f DIRS=$(find . -type d -name "rules") for i in $DIRS; do set +f rm $i/*.pdf done set +f 

This iterates through the directories you find in your find command and removes the pdf's under each directory.

The line IFS=$'\n' is to cope with spaces in file names, and set -f is to cope with wildcard characters. Of course, this is assuming you don't have newlines in any of your filenames. If you do, the solution will become a lot more complicated.

You can use a bash script to do it (not the best way):

#!/bin/bash # Don't screw us up with spaces! IFS=$'\n'; set -f DIRS=$(find . -type d -name "rules") for i in $DIRS; do set +f rm $i/*.pdf done set +f 

This iterates through the directories you find in your find command and removes the pdf's under each directory.

The line IFS=$'\n' is to cope with spaces in file names, and set -f is to cope with wildcard characters. Of course, this is assuming you don't have newlines in any of your filenames. If you do, the solution will become a lot more complicated.

deleted 53 characters in body
Source Link
Gilles 'SO- stop being evil'
  • 865.9k
  • 205
  • 1.8k
  • 2.3k

You can use a bash script to do it:

#!/bin/bash cd $(dirname $0) # Don't screw us up with spaces! IFS=$'\n'IFS=$'\n'; set -f DIRS=$(find . -type d -name "rules") for i in $DIRS; do set +f rm $i/*.pdf done set +f 

This iterates through the directories you find in your find command and removes the pdf's under each directory.

EDIT: This would fail upon encountering a directory with whitespace in its name. To fix that, add the The line IFS=$'\n' is to the beginning of thecope with spaces in file names, as shown aboveand set -f is to cope with wildcard characters.

Of Of course, this is assuming you don't have newlines in any of your filenames. If you do, the solution will become a lot more complicated.

You can use a bash script to do it:

#!/bin/bash cd $(dirname $0) # Don't screw us up with spaces! IFS=$'\n' DIRS=$(find . -type d -name "rules") for i in $DIRS; do rm $i/*.pdf done 

This iterates through the directories you find in your find command and removes the pdf's under each directory.

EDIT: This would fail upon encountering a directory with whitespace in its name. To fix that, add the line IFS=$'\n' to the beginning of the file, as shown above.

Of course, this is assuming you don't have newlines in any of your filenames. If you do, the solution will become a lot more complicated.

You can use a bash script to do it:

#!/bin/bash # Don't screw us up with spaces! IFS=$'\n'; set -f DIRS=$(find . -type d -name "rules") for i in $DIRS; do set +f rm $i/*.pdf done set +f 

This iterates through the directories you find in your find command and removes the pdf's under each directory.

The line IFS=$'\n' is to cope with spaces in file names, and set -f is to cope with wildcard characters. Of course, this is assuming you don't have newlines in any of your filenames. If you do, the solution will become a lot more complicated.

added 16 characters in body
Source Link
dma1324
  • 107
  • 4

You can use a bash script to do it:

#!/bin/bash cd $(dirname $0) # Don't screw us up with spaces! IFS=$'\n' DIRS=$(find . -type d -name "rules") for i in $DIRS; do rm $i/*.pdf done 

This iterates through the directories you find in your find command and removes the pdf's under each directory.

EDIT: This would fail upon encountering a directory with whitespace in its name. To fix that, add the line IFS=$'\n' to the beginning of the file, as shown above.

Of course, this is assuming you don't have newlines in any of your filenames. If you do, the solution will become a lot more complicated.

You can use a bash script to do it:

#!/bin/bash cd $(dirname $0) # Don't screw us up with spaces! IFS=$'\n' DIRS=$(find . -type d -name "rules") for i in $DIRS; do rm $i/*.pdf done 

This iterates through the directories you find in your find command and removes the pdf's under each directory.

EDIT: This would fail upon encountering a directory with whitespace in its name. To fix that, add the line IFS=$'\n' to the beginning of the file.

Of course, this is assuming you don't have newlines in any of your filenames. If you do, the solution will become a lot more complicated.

You can use a bash script to do it:

#!/bin/bash cd $(dirname $0) # Don't screw us up with spaces! IFS=$'\n' DIRS=$(find . -type d -name "rules") for i in $DIRS; do rm $i/*.pdf done 

This iterates through the directories you find in your find command and removes the pdf's under each directory.

EDIT: This would fail upon encountering a directory with whitespace in its name. To fix that, add the line IFS=$'\n' to the beginning of the file, as shown above.

Of course, this is assuming you don't have newlines in any of your filenames. If you do, the solution will become a lot more complicated.

Fix for whitespace characters
Source Link
dma1324
  • 107
  • 4
Loading
Source Link
dma1324
  • 107
  • 4
Loading