Unix: How to find files with multiple filename extensions

As I mentioned in my How to find multiple filenames with Linux find tutorial, you can use find command syntax like this to find files with multiple filename extensions:

find iTunes \( -name "*.mp3" -o -name "*.m4a" \)

As that command shows, I ran this find command to find all of my music files under my iTunes directory, including .mp3 and .m4a filename extensions.

While I’m in the neighborhood, this is the full find command I use to backup all of my iTunes files that have changed or been added in the last 180 days:

find iTunes \( -name "*.mp3" -o -name "*.m4a" \) -type f -mtime -180 -print0 | xargs -0 tar rvf NewMusic.tar

There’s probably an easier way to do this, but that backup command works for me.

Mac backups - handling spaces in filenames with find, tar, and xargs alvin August 27, 2011 - 5:04pm

This morning I decided to take a few minutes to backup all the songs I've purchased over the last half-year. These are all on my Mac OS X system, under the Music folder in my home directory.

The problem with trying to do this with standard Unix tools is that all these subdirectories and filenames have spaces in their names. Just looking at the Music folder, it contains many directory names like this:

A "tar extract multiple" tip - How to extract multiple files from a tar archive alvin February 21, 2011 - 3:25pm

tar extract FAQ: Can you demonstrate how to extract (un-tar) multiple files from a tar archive, without extracting all files from the archive?

Sure, here are a couple of examples of how to extract multiple files from a tar archive (un-tar them), without extracting all the files in the archive.

First, if you just need to extract a couple of files from a tar archive, you can usually extract them like this, listing the filenames after the tar archive:

How to un-tar one file from a tar archive alvin February 20, 2011 - 8:14pm

tar extract FAQ: How do I extract one file (or multiple files) from a tar archive without extracting the entire archive (i.e., how do I un-tar files from a tar archive)?

Git export - How to export a Git project

Git export FAQ: How do I export a Git project, like I would do with a "cvs export" or "svn export"?

There is no "git export" command, so instead you use the "git archive" command. By default, "git archive" produces its output in a tar format, so all you have to do is pipe that output into gzip or bzip2 or other.

Git export example

Here's a simple Git export command I just ran. I moved into the root of my Git project directory, then ran this command to create a new file named "latest.tgz":

tar gzip example - How to work with files that are tar'd and gzip'd alvin May 19, 2009 - 6:40pm

tar gzip FAQ: How do I work with tar archives that have been created with tar and gzip?

When you work on Unix, Linux, and Mac OS X systems, you'll quickly find that tools like tar and gzip are your good friends, so learning how to work with them is very important. Here's a quick look at how to work with the most common tar/gzip scenarios.

Linux tar command man page alvin September 22, 2008 - 9:23am

The contents of this page come from the CentOS Linux tar man page, i.e., the man page for the Linux tar command (also known as the help page for the tar command).

Some Linux tar command examples alvin August 11, 2007 - 5:26pm

The Linux tar command is used to created and extract archives. An archive is one file that contains one or (usually) many other files. The name "tar" itself comes from the phrase "tape archive", but that's just an old name. I mostly just create archives and then send them over the wire these days.

Creating Unix/Linux tar archives

To create an archive of all files in your current directory, and all subdirectories, use this tar command:

Linux tar command examples

Unix/Linux tar command FAQ: Can you share some Linux tar command examples?

Sure. I'm a big believer in learning Unix/Linux commands by seeing examples, and I know from experience it will really help to see some Linux tar command examples. But first, a brief bit of background information.

tar gzip example - how to extract a tar archive that has been gzip'd alvin August 14, 2006 - 7:34am

tar gzip FAQ: Can you show how to extract (un-tar) a tar archive that has been created with tar and gzip?

Say you have a file (archive) named myfile.tar.gz, and you want to unzip it and unpack (un-tar) it in one command. This "tar extract" command should do the trick for you:

tar xzf myfile.tar.gz

That tar command can be read as "use tar and gzip (the 'z' option) to extract the contents of the file (archive) named myfile.tar.gz.