Kristian Freeman Engineer at Simple, musician, and some dude in Portland.

Renaming files with mv

I have about a 50% chance of incorrectly formatting the filename for posts on this site. The posts follow a pretty simple structure: YYYY-MM-DD-post-title.md. Yet, I'm just as likely to introduce underscores instead of hyphens, or write the date as YYYY-MM-YY. No one told me that moving and renaming files would be such a large part of my day-to-day writing code; doing this so often, then (and generally misnaming things throughout the day) has required that I level up a bit in renaming files. Here's a quick tip on how to do this (more) efficiently, using the mv command in the terminal.

mv is move. That will probably become evident after using it at least once. The standard flow for using mv looks like this:

myfolder$ ls
bar baz foo

myfolder$ mv foo ..

myfolder$ cd .. && ls
foo myfolder

Here, we took a file from inside a folder (myfolder) and moved it up a directory, so that it would be parallel to myfolder in the directory structure. mv can also handle renaming files:

myfolder$ ls
bar baz foo

myfolder$ mv foo dude

myfolder$ ls
bar baz dude

These are pretty simple examples, but the real complexity and annoyance comes when you need to rename a file in a more variable way. Take, for instance, the file for this post: 2015-02-25-renaming-with-mv.md. When I originally saved it, I saved it as 2015-02-15-renaing-with-mv.md. So, we have an incorrect date (it is February 25th, not 15th) and a typo ("renaing" instead of "renaming"). There are two edits in the file that need to be done here. To do these, I'm going to introduce the bracket syntax, for representing multiple arguments to a command. For instance:

myfolder$ ls
2015-02-15-renaing-with-markdown.md

myfolder$ mv 2015-02-{15,25}-renaing-with-markdown.md

myfolder$ ls
2015-02-25-renaing-with-markdown.md

Here, the bracket syntax expands out to:

mv 2015-02-15-renaing-with-markdown.md 2015-02-25-renaing-with-markdown.md

Note that we didn't catch the typo here. As far as I know, there's no way to do multiple but separate renames in a single command; please let me know if I'm wrong :)

So we've used the bracket syntax to fix the date. As you can imagine, fixing the typo is quite similar:

myfolder$ ls
2015-02-25-renaing-with-markdown.md

myfolder$ mv 2015-02-25-{renaing,renaming}-with-markdown.md

myfolder$ ls
2015-02-25-renaming-with-markdown.md

While this post is ostensibly about using mv, it's really an introduction to Bash's bracket syntax. Here's a bonus look at ls with bracket syntax:

myfolder$ ls
folder1 folder2

myfolder$ ls {folder1,folder2}
folder1:
bar baz foo

folder2:
one two three

Super useful. When used correctly, this trick can save a lot of keystrokes.

Put.io tools

I wrote a couple Put.io tools over the weekend that I've been wanting for a long time, so I thought I'd document them here.

The first is an iOS app (GitHub link) for adding torrents to Put.io. The application registers itself as the handler for magnet links and, with the usage of a Put.io API key, it can add new torrents to your Put.io account without ever opening up the site. The previous flow looked like:

  1. Find a torrent
  2. Copy magnet link
  3. Open put.io (non-mobile site, though this is changing soon)
  4. Paste in text field
  5. Close text field with "Next"
  6. Confirm

The new flow:

  1. Find a torrent
  2. Select magnet link (opens app)
  3. Click upload button

It's a small thing but it really comes in handy when you're adding a bunch of files at once. There's a couple things I'd like to implement given a bit more time - this was a tool built in only a couple hours:

  • Group upload (multiple magnet links before upload)
  • Torrent progress

This was my first time writing a Swift app, and it went pretty well - I'm not a full-time iOS developer at all, but I know the environment enough that I managed to solve a pretty annoying problem of mine in an evening. Hooray!

I've thought about just turning it into a full Put.io app, with support for navigating through your files, but I rarely need that on mobile. If that is something you're looking for, there's a universal app that seems to do the job well for $2.99 (it's open source too!).

The other tool I made is a batch converter. From the README:

Problem: A put.io download finishes and it's entirely non-MP4 files (MKV, AVI, etc.)

Converting to MP4, according to put.io, takes half the length of the file. This is a limitation of ffmpeg or whatever put.io uses behind the scenes to convert their files.

Solution: We save time by starting these conversions automatically. Instead of opening files on your Roku or other MP4-handling device to find that you have to convert (and wait), we can load them all up into put.io's queue and be proactive. Woot!

This is a pretty simple Ruby script that makes use of httparty to interface with Put.io's API. This was another evening project (two evenings after the iOS app, actually) that solved an even bigger problem that I was having with my media.

Both of these tools are open source and available to use, customize, or do whatever with. They've already saved me an hour or so of manual clicking over the course of a couple days (seriously), so I'm considering them both a win. Programming is fun! 👍

November Update

Ah! I realized today that it's been about a month since I've written a blog post, so a quick update:

Things are all well in Kristian land. We've had a pretty busy couple months at Simple, and as we come into the holiday season, we're on the tail end of it. It's been really nice to be able to work on some larger features and projects and not be in firefighter mode. This has given me more of a chance to work on a couple Ember apps and even a couple little projects in the evenings (!!!). It's looking like it'll be a great end to the year - we'll have our remote employees in at the beginning of December for internal talks and presentations, as well as some dinners and drinks. As 2015 rolls around, I'll have been at Simple for six months, and in Portland for four. Time flies!

I've been taking up running with the goal of running my first 5K at the beginning of January. I've been running consistently (5/7 days of the week) for the last month and have been moving to just running every day if possible for the last two weeks. It's been pretty tough but I've noticed some nice changes - my pace has slowly improved. I spent the last couple days trying to figure out a goal in minutes for the 5K - I'm thinking around 30 minutes, but I'm more interested in being able to do it without stopping. I wasn't aware of the immense amount of 5Ks that happen on a regular basis; it'll be nice to start doing them regularly and track my results over time.

That's probably the most interesting thing to happen as of late. I've been pleasantly surprised by the amount of good video games to be released in the last month or so: I purchaed Shadow of Mordor and while there's some definite issues on PS3, it's still a great game. There's a really interesting hodgepodge of mechanics from various games that works really well together - primarily the Arkham and Assassin's Creed series. Just as recently as today, my copy of Persona Q arrived in the mail. I've only spent about thirty minutes in game, but it seems like it'll be a fun dungeon crawler to keep me busy in transit to and from work.

Finally, I'd be failing to write about a significant portion if I didn't update with a recent picture of my favorite pup, Shiro:

My first Go function

Because I'm learning Go and have a couple projects I'd like to transition from Ruby over to Go in the future, I thought it'd be fun to document my first actual (non-tutorial) function written in Go today - it returns a list of non-hidden files in a directory:

At some point this will probably look laughably bad to me, but that's how I feel about a lot of my early Ruby code. Here's to learning!

Understanding Apple Watch

I haven't written or spoken much about the Apple Watch online because I don't think we know enough about it yet to make concrete decisions. Regardless, the response online has been the classic new Apple product response - some find it useful, some find it useless. The best post I've read on it so far is from one of my new favorite sites, Stratechery. In the post, Ben Thompson suggests that the Apple Watch's purpose is to surpass the iPhone and other Apple products as your primary use device:

I believe that in the long run – i.e. not this version of the Apple Watch, but the one several iterations down the line – the Watch will have cellular capability and the ability to interface with any number of objects, including accessories that have larger screens and/or superior input methods, and will be the center of your computing existence.

This is a pretty big premise, and while it's not explicitly in the Apple Keynote, I think the signs are there. It becomes apparent when you look back to the word most-used during the keynote, and then in interviews with Cook and Ive in the months since then: personal. The iPhone is personal, yes, but it's still abstracted slightly; it sits in your pocket, or rests in your hand, temporarily. The Apple Watch is on you. There's a reason the classic watch is so popular, even though it has a single function that's baked in to almost every other device we use - it's personal.

It's always interesting to see the transition from someone to an iPhone (yes, it still happens!) - they don't think they need it, and then when they get it, it's like the whole world has been opened up to them. It's not an iPhone thing, really, but it is a smartphone thing. The Apple Watch will be similar, I think. We just haven't gotten our hands on it yet (or maybe it hasn't gotten on our hands).