Archiving Commandline style

Hi guys

I’m currently doing an on online course and I’ve got an assignment to backup my home directory to /tmp

here’s he question

What would be a way to back-up all your files and subdirectories found in your login directory and put them into a tarball file out in /tmp called backup.tar ?

the solution according to the courseware is…

tar -cvf /tmp/backup.tar "

This doesn’t work all I get following that command is an > _ at the commmand prompt so clearly I’m not implementing it properly
I’ve no idea what the " at the end signify but if I remove them I get this output

graeme@Linux1 ~ $ sudo tar -cvf /tmp/backup.tar 
[sudo] password for graeme: 
tar: Cowardly refusing to create an empty archive
Try 'tar --help' or 'tar --usage' for more information.
graeme@Linux1 ~ $ 

I’ve tried other variations too numerous to mention but I can’t get anything to work, so can any of you commandline gurus give me a clue what I’m doing wrong and why the solution didn’t work

Many Thanks


You’re telling it where to create the tarball, but not what to put in it … try:

sudo tar cvf /tmp/backup.tar /home/graeme

or if you want to suppress the “Removing leading `/’ from member names” message

sudo tar cvf /tmp/backup.tar -C / home/graeme

personally I’d also do it as a gunzip, so

sudo tar cvfz /tmp/backup.tar.gz -C / home/graeme


Looking at it again, I think there was a typo in the coursework command…

I think what you were supposed to do was use the “*” wildcard to compress everything in the current directory … so

make sure your home directory is the current directory:

cd ~

then create the backup with

sudo tar cvf /tmp/backup.tar *

Ok thank you Mark I’m getting the hang of it now but I have a couple of questions

what does the -c and the space between / home mean ?

Many thanks



man tar

(man pages are your friend ;))

the “-C /” = change directory to /

then everything is done as a relative path from there … so there’s no need for the leading / in the path

there’s no need to do this, it just supresses the “Removing leading `/’ from member names” message you get without it.

think of it like this…

if you’re already in / there’s no need to have a full path such as
instead you can just specify a path relative to your current directory, such as
which removed the need for the leading / it was informing you it was removing.

Ok I understabd this

personally I'd also do it as a gunzip, so
sudo tar cvfz /tmp/backup.tar.gz -C / home/graeme

cvfz+ create, verbose, file, compress with gzip ?

But I don’t understand this

sudo tar cvf /tmp/backup.tar *

if the asterix is a wildcard telling it to compress all the files within the archive where’s the instruction to compress ie z for gzip or j for bz2

should it not be something like

sudo tar cvfz /tmp/backup.tar.gz *


Yeah … if you want a gz or bz2