Skip to main content

seqcp

I have been working on PhatSort this week for a number of reasons. I have been too busy to work on a large project, but PhatSort is small enough for me to keep in my head and make progress in small time intervals. It was also a good project to try out HMock with, which I will likely write about in a separate blog entry. The primary reason, however, is that I have finally gotten around to writing a utility that I have wanted for a long time. The seqcp utility sequentially copies files and directories in sorted order.

My wife has a (rather large) stereo system that can play music from a wide variety of sources. One source is an SD card slot, which I find convenient for storing seasonal music. (Seasons play a large role in Japanese culture.) I periodically clear the SD card and copy music for the coming season. The stereo plays the media in the order that the files are stored on the FAT filesystem, so a program like PhatSort is very convenient for making sure that the tracks play in the correct order. The fixed order of directories also allows me to print an index of the music, making it easy to find the music that you want on the stereo.

Until now, the easiest way for me to prepare the SD card was to copy the music (using cp -r) and then fix the order using phatsort. The seqcp utility copies files and directories in sorted order, so I will now be able to use this utility instead. I am next scheduled to re-write the SD card after Christmas, to prepare New Year music.

While the seasonal music was my motivation for finally actually writing the utility, I will use it more often when copying podcast files to my MP3 player. For example, one podcast that I listen to provides bonus content for paying members, so I generally copy two files at once and want the bonus content to follow the primary content. I have been doing this as follows:

$ mkdir /mnt/stickB/podcasts/NameOfPodcast
$ cp NOP-042.mp3 /mnt/stickB/podcasts/NameOfPodcast ; sync
$ cp NOP-042b.mp3 /mnt/stickB/podcasts/NameOfPodcast ; sync

With seqcp, I will now be able to do the following:

$ mkdir /mnt/stickB/podcasts/NameOfPodcast
$ seqcp NOP-* /mnt/stickB/podcasts/NameOfPodcast

The seqcp utility has the same options as phatsort and is passed arguments like the cp command: one or more source files/directories followed by a destination directory. Directories are copied recursively.

Usage: seqcp [-c|--case] [-f|--first TYPE] [-n|--no-sync] [-o|--order ORDER]
             [-r|--reverse] [-s|--script] [-v|--verbose] SOURCE ... DESTINATION
  sequentially copy files and directories

Available options:
  -h,--help                show this help text
  --version                show version and exit
  -c,--case                case-insensitive sort
  -f,--first TYPE          sort certain directory entries first
  -n,--no-sync             do not sync after each command
  -o,--order ORDER         desired order (default: name)
  -r,--reverse             reverse sort
  -s,--script              output script instead of executing
  -v,--verbose             display progress
  SOURCE ... DESTINATION   source directories/files and destination directory

TYPE choices:
  dirs   sort directories before files
  files  sort files before directories

ORDER choices:
  name    sort by filename
  time    sort by modification time
  random  random order

Exit codes:
  0  no error
  1  execution error
  2  command line error

The seqcp utility is included in the PhatSort 0.5.0.0 release.

Author

Travis Cardwell

Published

Tags