Wikipedia:Reference desk/Archives/Computing/2011 April 23

Computing desk
< April 22 << Mar | April | May >> April 24 >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


April 23 edit

Bash - deleting recursively edit

  • OK, so I have a lot of folders on my Ubuntu machine that have files in them that I don't want. Namely, desktop.ini and thumbs.db (thanks Windows). However, I really really don't want to surf through every folder on my machine. What is the bash (i.e., terminal) command for deleting a file recursively? When I do rm thumbs.db -r, it simply responds with m: cannot remove `thumbs.db': No such file or directory. Magog the Ogre (talk) 05:52, 23 April 2011 (UTC)[reply]
find -name desktop.ini -exec rm {} \; (but I just woke up, so test it on a copy first) -- Finlay McWalterTalk 08:23, 23 April 2011 (UTC)[reply]
find needs a path to search. If you really want to delete every desktop.ini and thumbs.db on your entire system (or, at least, on every file system presently mounted read-write), try something like this:
sudo find / \( -iname 'desktop.ini' -o -iname 'thumbs.db' \) -delete
(With -iname meaning "case-insensitive name"; it will nuke any files named Desktop.ini or THUMBS.DB or any other case-variations as well. If you don't want that, use -name instead of -iname.) --Link (tcm) 08:57, 23 April 2011 (UTC)[reply]
Doesn't actually require a path, though I would definitely find the omission of one to almost certainly serve as a bad example. ¦ Reisio (talk) 15:26, 24 April 2011 (UTC)[reply]

Great! It worked beautifully. Now maybe you can help me with another problem I've had after unloading some archives: a folder within a folder. A lot of my directories are duplicated, so for example, I have /media/backup/pics/pics/IMG01.jpg or /media/backup/pics/Mypics/IMG01.jpg (you can see the first pics folder is unnecessary). Is there a way to move all the files to the parent directory and delete the subfolder when the only contents of the parent directory to begin with were just one folder (i.e., /media/backup/pics only content is the pics or Mypics directory). Magog the Ogre (talk) 18:47, 23 April 2011 (UTC)[reply]

I think that's most easily handled by a Python script:
import os
for r,d,f in os.walk("."):
  if not f and len(d)==1:
    e=os.path.join(os.path.dirname(r),"_empty")
    os.rename(r,e)
    os.rename(os.path.join(e,d[0]),r) # turn .../a/b/ into .../a/
    os.rmdir(e)
    del d[0]                    # don't recurse
Save that and run it (with python filename.py) in a directory containing all the "trivial" directories you want collapsed. As the comment says, it preserves the name of the containing directory rather than the contained directory; this is equivalent for most purposes to what you said ("move all the files to the parent directory and delete the subfolder"). Note that once it finds a shortening to do, it doesn't search the contents of that directory further (so if you had skinny/skinny2/directory/many-files, it would only delete skinny2/ from the path); you can always run it more than once. No warranty, of course, but since this only calls os.rmdir(), which can only remove empty directories, it should be pretty safe. --Tardis (talk) 17:58, 24 April 2011 (UTC)[reply]

Thank you; is there a way to maintain the name of the subdirectory? I don't know any python. Magog the Ogre (talk) 19:15, 24 April 2011 (UTC)[reply]

This will do that:
import os
for r,d,f in os.walk("."):
  if not f and len(d)==1:
    u=os.path.dirname(r)
    e=os.path.join(u,"_empty")
    os.rename(r,e)
    os.rename(os.path.join(e,d[0]),os.path.join(u,d[0])) # turn .../a/b/ into .../b/
    os.rmdir(e)
    del d[0]                    # don't recurse
Note that it will fail if you have, say, .../skinnyA/dir/files and .../skinnyB/dir/files since they can't both become .../dir. --Tardis (talk) 18:36, 25 April 2011 (UTC)[reply]

Wordprocessing - universal archiving standard? edit

I'm using Abiword (version 2.8.6) which by default saves documents as .abw. I'm beginning to worry that in future years, when I use some other wordprocessor with some other operating system, then I won't be able to open these old documents. Abiword can also save documents as .doc .rtf .latex .odt .sxw .docx among others.

What would be the best bet, apart from .txt, for long-term storage? Something that could be read in different operating systems by different wordprocessors. Thanks 92.24.182.118 (talk) 17:21, 23 April 2011 (UTC)[reply]

.rtf is Rich Text Format. .doc and .docx are Microsoft Word formats. .odt and .sxw are OpenOffice.org formats, with .sxw being an older, obsolete format, I think. .latex is presumably LaTeX.
.rtf is the most widely supported, and it is human-readable, so try that first. You may find that it doesn't preserve fancier features of the document, in which case I would try .doc or .docx, since MS Word's huge market share creates a strong incentive to support those formats well. .odt is an open format used by an open-source product, but so is .abw, so I'm not sure there's an advantage there. LaTeX will probably remain fairly stable for decades to come, so you will be able to print your documents, if you don't mind doing it with LaTeX. -- BenRG (talk) 18:02, 23 April 2011 (UTC)[reply]
It is difficult to guess (which is essentially what you're having to do) which formats will and won't be supported by future programs. I was caught out myself a while back, when I discovered that OpenOffice wouldn't (natively) open decade-old StarOffice documents. As you can't know, and as storage is cheap, I'd recommend a rather paranoid solution: store the .abw you actually use, and .doc, .odt, .rtf and maybe some others as well, and a PDF to boot (so at least, in the future, you can print a document, even if it's difficult to edit). If the appearance is important (e.g. if it's more than just essays or letters) I'd also archive off the TTF/OTF files for the fonts used in the documents. -- Finlay McWalterTalk 18:15, 23 April 2011 (UTC)[reply]
It's worth noting that .docx is an open standard and is essentially just XML (albeit zipped). The combination of huge market share with open and non-binary formatting, with the ability to support rather complicated documents, makes it seem to me like the best future-friendly choice. --Mr.98 (talk) 19:03, 23 April 2011 (UTC)[reply]
Office Open XML's status as an open standard is tenuous at best; it is largely a documentation of Microsoft's existing implementation (including bug-compatibility with ancient versions of Excel at least) that is unreasonably difficult for any other entity to support properly. It exists solely to let Microsoft say that Office uses open standards (as required by an increasing number of government bodies); we have an entire article on its standardization process and its irregularities. (In particular, many countries suddenly requested principal voting status just before the final polling, and then vanished once they had cast the vote they had been paid to makecared about.) --Tardis (talk) 17:28, 24 April 2011 (UTC)[reply]

Thanks. Reading the Abiword article more closely, it suggests .abw is XML. Do other editors exist to read XML? Thanks. 92.29.117.87 (talk) 20:45, 23 April 2011 (UTC)[reply]

Sure, tons. But being able to read XML doesn't mean you can do anything worthwhile with the document it encodes. XML is just a way of writing a complex document in a manner that's perhaps a bit easier for another program to parse than if it was an obscure binary format. But there's XML for pictures, XML for formulas, XML for molecules, XML for genes, XML for maps, etc. To really do anything useful with an XML document (like render a printed document) you have to understand what is encoded. To understand the Office Open XML (which is docx etc.; don't let the name make you think this is the format for the OpenOffice.org program) you need to read a specification that's 7,000 pages long (over and above the underlying XML specification). Hopefully (surely) Abiword's XML-based format isn't as insanely vast as that, but a word processor document is of necessity a complicated thing, requiring a detailed specification and an impressive feat of engineering to implement. -- Finlay McWalterTalk 21:15, 23 April 2011 (UTC)[reply]

None are going anywhere anytime soon, and if you use a plain text format, it will always be quite easy to make a converter even if all software on the planet disappears in a freak accident. I'd go with  , still, though. :p ¦ Reisio (talk) 19:25, 24 April 2011 (UTC)[reply]

Archiving Hotmail with Thunderbird edit

I installed Thunderbird only so that I could archive my thousands of Hotmail emails to my HD. But Thunderbird appears to save the archived emails to some file which only it can read. Is there any way of saving the emails in a more accessable way please? As it happens, I will need to show some old emails in court as evidence; I would prefer something that could print them as near to how they look in Hotmail as possible. As there are thousands of them, I could not do anything on an email by email basis. Thanks 92.24.182.118 (talk) 17:32, 23 April 2011 (UTC)[reply]

Thunderbird uses a variant of the mbox format, which many other programs can read. Bar some quoting rules, an mbox is just the text of all the emails, as they were received, concatenated one after the other. If you wanted them in individual files, I've used Fookes Software's "Aid4Mail" program (which isn't free) to turn such archives into folders full of .eml files (one file per email). Parsing an mbox file is not especially difficult, so I'm sure others here will have recommendations for other programs that can do the job too. But I share your pain about the printing issue. Some Googling suggests this extension can save folders as HTML (which maybe printable); I haven't used that extension myself. The obvious solution (simply select all the emails and say print) should work too. -- Finlay McWalterTalk 17:56, 23 April 2011 (UTC)[reply]

Cannot print in MS Word edit

  Resolved

Vista. Prints fine in Openoffice. Word boots me out when I CTRL P. Kittybrewster 18:12, 23 April 2011 (UTC)[reply]

CTRL P works fine for my Word running under Vista, but perhaps you have assigned the key to some other function? Dbfirs 18:46, 23 April 2011 (UTC)[reply]
1. Does it work if you go File > Print. 2. "Boots you out" how? Full crash or what? What's the message say? 3. Is it just one document in particular or all documents? --Mr.98 (talk) 18:56, 23 April 2011 (UTC)[reply]
No. File Print also boots me out. All documents. No message, no save, no hesitation, Word closes down altogether. Kittybrewster 19:12, 23 April 2011 (UTC)[reply]
Does the same thing happen if you use a different printer driver? Dbfirs 20:14, 23 April 2011 (UTC)[reply]
I think the way to check that would be through file print ... which boots me out. Kittybrewster 21:05, 23 April 2011 (UTC)[reply]
Go to Control Panel → Printers. Right-click a different printer icon and choose Set as Default. Then re-open Word and see if the Print box works. --Bavi H (talk) 04:05, 24 April 2011 (UTC)[reply]
Very helpful. Thank you. Kittybrewster 11:41, 24 April 2011 (UTC)[reply]

Making an animated GIF edit

I have a series of ASCII PPM files (24 bit color) which I would like to change into an animated GIF. How can I best (and most cheaply) accomplish this goal ? (No "tweening" is needed.) Right now I only have Gimp and MS Paint. I'm on Windows XP SP3. StuRat (talk) 22:01, 23 April 2011 (UTC)[reply]

Imagemagick: convert *.ppm foo.gif (more options listed here; -delay and -loop will be most useful for this operation) -- Finlay McWalterTalk 22:24, 23 April 2011 (UTC)[reply]
Thanks. I went to download it, but am confused by the "static" versus "dynamic" downloads offered here: [1]. What's the difference ? Does this refer to memory allocation within the program ? StuRat (talk) 00:32, 24 April 2011 (UTC)[reply]
From your perspective it doesn't matter. Use the "portable" one. 87.112.134.59 (talk) 01:25, 24 April 2011 (UTC)[reply]
That's 16 bits per pixel, or 48 bits total. I have limited memory and only need 24 bits total, so that seems like overkill. StuRat (talk) 01:59, 24 April 2011 (UTC)[reply]
Unless your pictures are of astronomical sizes, it will make little practical difference. I'm sure you're aware that if the colours in the images are drawn from nature (rather than being machine-generated from a very limited palette) the archaic nature of GIF's colour handling will do vile and sucktastic things to the colour rendition in the final GIF. 87.112.134.59 (talk) 02:04, 24 April 2011 (UTC)[reply]
They are computer generated images (from a program I wrote), and do use a limited palette. Being PPM ASCII, they are also huge, on the order of 5 MB each. StuRat (talk) 02:58, 24 April 2011 (UTC)[reply]
GIMP can create animated GIF images. It will use each layer as a frame. See this tutorial. --Andreas Rejbrand (talk) 23:08, 23 April 2011 (UTC)[reply]
Thanks. Does GIMP offer command line support for what I want ? StuRat (talk) 00:33, 24 April 2011 (UTC)[reply]
Yes, but it is not remotely near the simplicity of imagemagick. I had a job that imagemagick couldn't do and I spent two days writing scripts to get GIMP to do it from the command line. Basically, command line support is a limited feature of GIMP, but it is the primary feature of imagemagick. -- kainaw 02:17, 24 April 2011 (UTC)[reply]
Why couldn't imagemagick handle it ? StuRat (talk) 03:02, 24 April 2011 (UTC)[reply]
  Resolved

StuRat (talk) 18:24, 25 April 2011 (UTC)[reply]