Linux Terminal : Output a List of All Directory Contents Files and Subdirectories to a Text File

I just discovered this, and am using it to make a list of my music collection.

Credit for making the output goes to Noufal on this page. Credit for how to list directories recursively is actually from the gnome-terminal ls manual (code input to view it: man ls)

Anyway, here’s what you plug into the terminal:

cd the-address-of-the-top-folder-you-want-to-list
ls -R > list.txt

You can name "list.txt" whatever you want (i.e., popmusicbest.txt or something.) This method works for insanely large music collections and scans folders recursively, so if you have all of your Three Dog Night albums and Guess Who albums dumped into artist folders, it will still list all of your mp3/whatever-file-format-you-use.

You can use this for anything, but the main use to me is figuring out which music to buy. (You know, to avoid buying the same song on Amazon or something twice…)

How to Sync Your Calibre Library Between Computers on Ubuntu Linux with Dropbox

It’s easier than it sounds, I promise. I’ve tried to keep this simple & step-by-step for non-techies. And everything I use here is free.

Calibre and Ebooks…

If you like ebooks, you’re probably already familiar with the multi-platform ebook management software Calibre. It’s been called "the iTunes for ebooks" and can catalogue, tag, convert and sync ebooks to various readers such as Nook and Kindle.

Calibre stores all the books you add to it in a folder, which is sub-sorted into other folders based on author, and then based on title + a number- i.e., Calibre Library/Charles Dickens/A Tale of Two Cities (58). All of Calibre’s "important" data is located in the Calibre Library folder and its subfolders- which makes syncing Calibre between computers a breeze if you know what you’re doing.

If you want to sync between Ubuntu Linux and Windows or between two Windows installations, see the paragraph on Windows towards the end, under the heading "Syncing Between Windows and Linux/Windows". Be sure to read the rest of the tutorial first, though!

Syncing Your Calibre Library On Ubuntu Linux : The Setup

1. First of all, you need to sign up for Dropbox. It’s free, private and keeps your files synced between computers. The storage space starts at 2GB and can be increased by links and contests- or by buying more space. Install the Dropbox Linux Sync Daemon. Restart the computer if required. After it runs the first time, you should now have a folder titled Dropbox in your home folder and (most likely) an icon in the system tray showing you Dropbox’s status (syncing, done syncing, paused).

2. Download Calibre Ebook Software and install it. It’s possible to do this via the command-line in Ubuntu Linux, should you so choose; to install via the command-line, enter this code in the gnome-terminal:
sudo apt-get update
sudo apt-get install calibre
).

3. ALTERNATE, EASIER METHOD USING THE START WIZARD:
lafattaturchina helpfully pointed out in the comments that "in Calibre 0.9.12, you can choose where to place the library by going in Preferences > Start Wizard". lafattaturchina has successfully used this method with the somewhat-similar-to-Dropbox Ubuntu One service, and it’s working thus far. If you can get this method to work, I recommend using it instead of the steps 3-6 below; then to sync with another computer, you could use steps 7-8 below the heading Adding a Second (or Third) Computer, BUT using the Start Wizard to select the downloaded library folder in your Dropbox folder when you’re setting up Calibre on the second comp. I HAVEN’T TRIED THIS, but it seems like it should work. Please comment below if you’ve tried it successfully.

3. Run Calibre for the first time and add some books to it. (If you don’t have any ebooks, Project Gutenberg has loads of free ones, including most of the classics.) This should create a folder full of them in your home folder called Calibre Library. Close Calibre.

4. MOVE the entire Calibre Library folder into your newly-formed Dropbox folder. It should start uploading the books/data to back them up. (DON’T start Calibre again yet, or it will just try to make another folder there to replace the moved one.)

5. Now we’re going to create a symbolic link to trick Calibre into thinking that its library is still in the home folder. It will still access/update your books just like before, but Dropbox will sync them and any updates to them (i.e., converted formats or new tags/author info). Open the gnome-terminal and enter the following short code to make sure it’s looking at the home folder:
cd ~
Now enter the following code to make a symbolic link pointing to your Calibre library; since the link will have the same name as the old folder, Calibre will treat the folder it points to as if it’s the original Calibre Library:
ln -s Dropbox/Calibre\ Library/ Calibre\ Library
The ln stands for "link" and the -s means that it’s symbolic. When making symbolic links, you enter the "real" location first, and then the "fake" location you want to point to the real one.

6. Open Calibre and add some more books (to make sure it works). The books and any edits to them should be added to the Calibre Library folder in your Dropbox folder and automatically updated. If you just want to back up your Calibre Library, rather than syncing it, then you’re done here.

Adding a Second (or Third) Computer

7. Now you’ll want to configure your other computer(s) (which I’ll call "comp #2" from now on) to receive the updated Calibre Library from Dropbox. Turn on your other computer and install Dropbox, then download to comp #2 whatever’s in your Dropbox folder- including the Calibre Library folder. Download it all and then pause Dropbox’s syncing. (You don’t *have* to do this, but it’s just easier to tweak things when Drobox isn’t stalking your file changes…)

8. Download and install Calibre onto comp #2. Run Calibre one time, to make the Calibre Library folder inside your home folder, and then close Calibre. NOW DELETE THE Calibre Library FOLDER YOU JUST MADE.

8. Open the gnome-terminal and again make sure it’s looking at the home folder (it usually opens there by default, but if it’s already open or customized… It never hurts to make sure.)
cd ~
and now make a symbolic link from where the folder you just deleted used to be to the Calibre folder inside your Dropbox folder:
ln -s Dropbox/Calibre\ Library/ Calibre\ Library

9. Open Calibre. It should show all the books you added on your other computer, along with any custom things you did (such as, say, tagging anything by Mark Twain as "over-rated".) You can now add/remove/change books on either computer, and it will show up on the other one(s). You can repeat steps 7-9 for as many computers as you want to sync.

ONE POINT: You SHOULD NOT have two Calibres running on two different computers at the same time. This will lead to file conflicts as Dropbox tries to figure out which version the files changed should be kept. It won’t permanently break anything or ruin your computer, but it can be annoying- especially if you just finished tagging a lot of books and it over-writes all your tags. Dropbox will usually try to save the alternate versions of files in their respective folders as ItsOldFilename.conflict or something, but it’s easier just to avoid this.

This method is confirmed to work and I use it myself- it’s not one of those "you have to download 28 dependencies you’ve never heard of and it might crash your gui and it won’t work half the time!" sort of linux tutorials you sometimes see online. I’m currently using this tutorial’s method to keep my Calibre library synced between two Ubuntu 11.04-running laptops.

Syncing Between Windows and Linux/Windows

I run Calibre primarily on my favorite OS- a somewhat recent version of Ubuntu Linux. This tutorial is for Ubuntu Linux, but it could be tweaked for other linux flavors. There’s also a way to make this work between a Linux install and Windows, although you have to use the portable version of Calibre on the Windows comp. I’ve never tried it, but you could do it this way: install Dropbox on Windows FIRST, and then install the portable version of Calibre INSIDE the Dropbox folder. Add whatever books you want to Calibre, close it and then sync it to Linux. Then point the symbolic link to in your home folder to /home/YourUsernameHere/Dropbox/CalibrePortable-or-whatever-the-portable-versions-folder-is-called/Calibre\ Library or wherever the library got dumped (you might have to browse for it.) Between two Windows computers, it would be much easier: just skip the whole symbolic links deal and run the portable Calibre from within the Dropbox folders every time.

If you have any questions/comments/concerns, feel free to comment. I’ll try to reply when I can.

Helpful Links: