Unix find command: How to move a group of files into the current directory alvin May 16, 2018 - 9:51pm

I just bought a bunch of MP3 music files from Amazon, and when I downloaded the zip file they provide onto my Mac, it was a bunch of files in a bunch of subdirectories; not really convenient to work with when you’re trying to import them into iTunes. So I used this Unix find command to move all of the music files from the subdirectories they were scattered in into the root directory that was created when I expanded the zip file:

cd Amazon-Music-Folder
find . -type f -exec mv {} . \;

If you ever need to either copy or move a bunch of files with a single command, I hope this example shows the correct find command syntax for your needs. (If you need to copy the files, use the cp command instead of the mv command.)

A Play Framework 2.6 startup script example (Scala) alvin April 4, 2018 - 4:46pm

Play Framework FAQ: Can you share an example of a Play Framework 2.6 startup script, i.e., a shell script that shows the commands and parameters you use to run a Play Framework application?

Sure. Assuming that you created a production mode version of your application with the sbt dist command, deployed that zip file to a production server, and have a Play Framework 2.6 application named “myapp,” you can put a command like this in a Unix/Linux shell script to start your Play application:

My vi/vim tutorial goes over 200,000 views

Way back when I lived in this low-income apartment complex in Wasilla, Alaska — technically I had no income at the time, and it’s ridiculously hard to find a place to live in Alaska in the summer — and spent as much time as I could meditating in the mountains, I created a vi/vim editor video tutorial and put it on YouTube. I just noticed that video has now exceeded 200,000 views. It feels a little weird to think that over 200K people have started to learn vi/vim from that video.

A funny thing about making that video is that the walls in that apartment complex were paper-thin. I could hear everything my neighbors did in their apartments (use your imagination and you won’t be wrong), and they could hear me, so I intentionally tried not to talk too loud in the video. I had to edit the video at several points to crop out some of my neighbors yelling at each other.

Format of the Linux crontab date and time fields alvin February 28, 2018 - 10:45am

I’ve written several things about the Linux cron command and crontab file format before, and as a quick note, here’s some information on the format of the crontab date and time fields.

Crontab date/time fields

First, from the crontab man page documentation:

How to use the Linux ‘scp’ command without a password to make remote backups alvin January 25, 2018 - 4:27pm

Summary: How to create a public and private key pair to use ssh and scp without using a password, which lets you automate a remote server backup process.

Over the last two years I've ended up creating a large collection of websites and web applications on a variety of Linux servers that are hosted with different companies like GoDaddy and A2 Hosting. I recently embarked on a mission to automate the backup processes for all these sites, and as a result of this effort, I thought I'd share what I've learned here.

Linux: How to get the basename from the full filename

As a quick note today, if you’re ever writing a Linux shell script and need to get the filename from a complete (canonical) directory/file path, you can use the Linux basename command like this:

$ basename /foo/bar/baz/foo.txt

How to show the largest files under a directory on Mac OS X (Unix)

Here’s an example that shows how to find the largest files under a directory on MacOS and Linux/Unix systems.

A du/sort command to show the largest files under a directory on Mac OS X

The Unix/Linux command that worked for me on my MacOS system is this:

$ du -a * | sort -r -n | head -10

du is the disk usage command, and the -a flag says, “Display an entry for each file in a file hierarchy.” Then I use the sort command to sort the du output numerically and in reverse. After that, head -10 shows only the first ten lines of output. In the Music folder on my Mac the command and output look like this:

sed on macOS: How to append multiple lines of text to an HTML or XML file alvin December 19, 2017 - 3:40pm

As a brief note about the Linux/Unix sed command, today I learned how to append multiple lines of text to an HTML (or XML) file on macOS. The short answer is that I created a sed commands file named changes.sed with these contents: