Advanced

Taming the tar command: Tips for managing backups in Linux

Posted by enable_sysadmin on · 7 comments
Enable SysAdmin; By Gabby Taylor
Mail this story
Print this story

Put tar to work creating and managing your backups smartly. Learn how tar can create, extract, append, split, verify integrity, and much more.

Full Story

  Nav
» Read more about: Story Type: Tutorial; Groups: Linux

» Get new stories by e-mail: nightly or as they are published

« Return to the newswire homepage

  Related stories
» More like this

Comments (7)

How to handle files with names in their blanks correctly with GNU tar?

Lots of music files and directories are that way. For example, on my server my mp3 directory has a sub-directory David Garrett/.

The command "cp -r mp3 /foo/" works correctly -- I get, among other things /foo/mp3/David Garrett/

But when I tar the mp3 directory and then un-tar it under /foo, I get names with quotes in them, e.g., /foo/mp3/'David Garret'/. "scp" does the same thing -- the command "scp -r mp3 someone@somehost/foo/" creates somehost/foo/'David Garret'/ -- again with quotes.

How do I fix this (mis-)behavior?
Who's crazy idea was it anyway to start using the space character for both an element separator AND a name component? That bad decision has cost humanity lifetimes of wasted effort (not just for Linux users)

Personally whenever I get a file with spaces I immediately replace spaces with underscores. I find that to be a time saving step in the long run.
> I get names with quotes

It seems that bash adds the quotes in stdout only, they are not stored in the file names. A GUI file manager does not show any quotes in the file names. tar -tf foo.tar neither.

>lifetimes of wasted effort...replace spaces with underscores

Yep, right or wrong, I agree, and do same.

Seen elsewhere, posted by someone who's not me:

    for file in *; do mv "$file" `echo $file | tr ' ' '_'` ; done
...but I happily snarfed it to disk and called it ".space2bar" (dotted name so it doesn't show up in an Apache index of the subdir where I use it).
Another possibility, in Bash:

$ for file in * ; do mv "$file" ${file/ /_} ; done
Should also work in ksh. IIRC, ksh had it first.
>for file in * ; do mv "$file" ${file/ /_} ; done

This would replace the first space only.

for file in * ; do mv "$file" ${file// /_} ; done

replaces all spaces;

Woops, yup, you're right.

"Many eyes", indeed.

Post a comment

A free account is needed to post. Write your comment here first: your text is kept in this browser while you sign up or log in, and is waiting for you when you come back.

Your message:
|||||
10
Markdown: **bold**, *italic*, [text](https://link), - lists, > quotes, $x^2$ for math. Formatting help

Sign up and post (it is free)  or  Log in and post