This requirement is way over my head....hopefully someone can give me a hand.
I need a script where I can specify a particular path, i.e, nytimes/fiction and have the script delete all file extensions of a specified type
Something like
scriptname /nytimes/fiction mobi
or if I wanted to deleted the epup files
scriptname /nytimes/ epup
The variables are the directory path and the file extension
Thanks in advance for any help.
Thom
Script Request
-
- Posts: 229
- Joined: Wed 25 Aug 2010, 15:38
- Location: ISM Dhanbad, Jharkhand, India
Code: Select all
#!/bin/sh
dirname="$1"
extension="$2"
find "$dirname" -name "*.$extension" -print |
while read file; do
rm "$file"
done
Ah....my error
The directory structure is
nytimes/fiction/variable authorname/extension
it would need to look in all many authornames and perform the rm
The directory structure is
nytimes/fiction/variable authorname/extension
it would need to look in all many authornames and perform the rm
akash_rawal wrote:Does this work?Code: Select all
#!/bin/sh dirname="$1" extension="$2" find "$dirname" -name "*.$extension" -print | while read file; do rm "$file" done
That's what find is for. It will look in all subdirectories, recursively.tlchost wrote:Ah....my error
The directory structure is
nytimes/fiction/variable authorname/extension
it would need to look in all many authornames and perform the rm
akash_rawal wrote:Does this work?Code: Select all
#!/bin/sh dirname="$1" extension="$2" find "$dirname" -name "*.$extension" -print | while read file; do rm "$file" done
I presume that the files are (for example) *.mobi, not <author>/mobi (which a pedantic reading of your post would suggest)?
Pedantic wins:Ibidem wrote: I presume that the files are (for example) *.mobi, not <author>/mobi (which a pedantic reading of your post would suggest)?
Examples:
/nytimes/fiction/authorname1/*.mobi
/nytimes/fiction/authorname2/*.mobi
So one might think of it as
/nytimes/fiction/authorname/*.extension
/nytimes/nonfiction/authorname/*.extension
where fiction/nonfiction are variables
authorname is a variable
extension is a variable
Thanks,
Thom
-
- Posts: 229
- Joined: Wed 25 Aug 2010, 15:38
- Location: ISM Dhanbad, Jharkhand, India
Means you want to delete files at depth 2?tlchost wrote:Pedantic wins:Ibidem wrote: I presume that the files are (for example) *.mobi, not <author>/mobi (which a pedantic reading of your post would suggest)?
Examples:
/nytimes/fiction/authorname1/*.mobi
/nytimes/fiction/authorname2/*.mobi
So one might think of it as
/nytimes/fiction/authorname/*.extension
/nytimes/nonfiction/authorname/*.extension
where fiction/nonfiction are variables
authorname is a variable
extension is a variable
Thanks,
Thom
In your example you want to delete files named as "/nytimes/fiction/*/*.extension" and not "/nytimes/fiction/*.extension" or "/nytimes/fiction/*/*/*.extension"?
Then this might work:
Code: Select all
#!/bin/sh
dirname="$1"
extension="$2"
find "$dirname" -mindepth 2 -maxdepth 2 -name "*.$extension" -print |
while read file; do
rm "$file"
done
Check whether listing is correct:
If correct,
will finish it.
Code: Select all
find /nytimes/fiction -path '*/authorname/*.mobi'
Code: Select all
find /nytimes/fiction -path '*/authorname/*.mobi' -delete
Fatdog64 forum links: [url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Latest version[/url] | [url=https://cutt.ly/ke8sn5H]Contributed packages[/url] | [url=https://cutt.ly/se8scrb]ISO builder[/url]
Thanks
It seems that the directories created with the ebooks are all differnent in structure..so there may not be a universal script.
Thanks for all the responses.
I ended up with a kludgy solution..
looked at the directory nytimes, noted the subdirectories and based on that:
rm /mnt/home/nytimes/Books/Fiction/*/*.mobi
and
rm /mnt/home/nytimes/Books/Non-fiction/*/*.mobi
Since all the sub-directories can have different names...it's beyond me on how to do it, unless I did
rm /mnt/home/nytimes/*/*/*.mobi
Thanks for all the responses.
I ended up with a kludgy solution..
looked at the directory nytimes, noted the subdirectories and based on that:
rm /mnt/home/nytimes/Books/Fiction/*/*.mobi
and
rm /mnt/home/nytimes/Books/Non-fiction/*/*.mobi
Since all the sub-directories can have different names...it's beyond me on how to do it, unless I did
rm /mnt/home/nytimes/*/*/*.mobi