2

Using calibre from the command line, in debian testing, how can I insert a tag with the syntax being

    ebook-meta ebook_file --tags rhubarb

but for a range of files, but all by the same author so just need the tag of his/her name?

This is used for indexing and sorting out books on a Kindle.

Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227
boudiccas
  • 393
  • 1
  • 4
  • 12

2 Answers2

2

The easiest way, assuming all the relevant files are in the same directory, is:

for f in *; do ebook-meta "$f" --tags rhubarb

If the files can be in various sub directories, use find (this assumes that the only files in all sub directories are ebooks. Since this is likely not true, you should use something additional like -name "*.ebook" or whatever extension your ebooks have):

find . -type f -exec ebook-meta '{}' --tags rhubarb \;
Dubu
  • 3,654
  • 18
  • 27
terdon
  • 234,489
  • 66
  • 447
  • 667
  • @ChrisDown argh, thanks, forgot the quotes which were the whole point of the answer. – terdon Sep 01 '13 at 14:32
  • @~/kindle-backup/34-wilbur-smith-Kindle-Collection]$ [9570]>; for f in *; do ebook-meta "$f" --tags wilbur-smith > ^C @~/kindle-backup/34-wilbur-smith-Kindle-Collection]$ [9570]>; for f in *; do ebook-meta "$f" --tags wilbur-smith > ^C Doesn't work, but I cant see why. Any ideas please? – boudiccas Sep 01 '13 at 15:11
  • find . -type f exec ebook-meta '{}' --tags wilbur-smith \; find: paths must precede expression: exec Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression] – boudiccas Sep 01 '13 at 15:12
  • There was a '-' missing before 'exec'. – Dubu Sep 01 '13 at 17:14
  • @user205787 as Dubu pointed out, I had forgotten the `-` before `-exec`, try again with the modified answer. – terdon Sep 01 '13 at 17:20
0

You must have the ebooks of an author in a directory. cd to this directory an run:

for var in $(ls); do ebook-meta $var --tags rhubarb; done

if the filename has spaces, you must modify the IFS (Internal Field Separator):

oldIFS=$IFS
IFS='\n'
for var in $(ls); do ebook-meta $var --tags rhubarb; done
IFS=$oldIFS

Or the same in a single command:

oldIFS=$IFS && IFS='\n' && for var in $(ls); do ebook-meta $var --tags rhubarb; done && IFS=$oldIFS

mavillan
  • 3,067
  • 4
  • 22
  • 27
  • Thanks for this but its not working, this is part of the puitput - – boudiccas Sep 01 '13 at 06:27
  • Thanks for this but its not working, this is part of the output - the output is too long for here but its at http://paste.debian.net/33088/ . I think that theres some problem with the 'cli.py' module itself – boudiccas Sep 01 '13 at 06:36
  • 4
    [NEVER parse `ls`](http://mywiki.wooledge.org/ParsingLs), and twice never when working with file names that are likely to have spaces. – terdon Sep 01 '13 at 14:13