LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-23-2004, 05:48 AM   #1
guarriman
Member
 
Registered: Nov 2004
Posts: 101

Rep: Reputation: 15
/bin/tar: Removing leading `/' from member names


Hi.

I wrote a script:
/bin/tar -zcf /home/user/backup_www.tar.gz /var/www/html

It works, but I get this warning message:
/bin/tar: Removing leading `/' from member names

I removed the first '/' from '/home/user...' but it does not work.

Any suggestion? Thank you very much.
 
Old 12-23-2004, 06:13 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984
what do you want suggestions about? tar archives don't contain absolute paths, only relative ones. this is correct behaviour, as the alternative is really nasty and illogical. this is the same way that other compression programs like winzip work. when you untar somethign you provide an destination directory, which implicity is '/' in your case... but it should be explicit for logical operation.
 
Old 02-01-2007, 11:36 PM   #3
pk2001
LQ Newbie
 
Registered: Feb 2007
Location: Singapore
Distribution: Debian Sarge/Etch
Posts: 19

Rep: Reputation: 0
Quote:
Originally Posted by guarriman
Hi.

I wrote a script:
/bin/tar -zcf /home/user/backup_www.tar.gz /var/www/html

It works, but I get this warning message:
/bin/tar: Removing leading `/' from member names

I removed the first '/' from '/home/user...' but it does not work.

Any suggestion? Thank you very much.

The "P" option should help you there. See man tar
 
Old 07-04-2008, 01:42 PM   #4
stargazer.shah
LQ Newbie
 
Registered: Jul 2008
Posts: 1

Rep: Reputation: 0
Quote:
Originally Posted by pk2001 View Post
The "P" option should help you there. See man tar
Also take the '-' out
/bin/tar zcfP ...
 
Old 07-04-2008, 02:48 PM   #5
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Quote:
Originally Posted by stargazer.shah View Post
Also take the '-' out
/bin/tar zcfP ...
The name of the archive file MUST follow the f. Therefore that is the wrong place for the P parameter. And I believe that the c must be the first parameter. Not positive about that.
Code:
tar czPf archive.tgz /home
Also, the - isn't doing any harm. Who cares if he is using BSD or GNU parameter style?

@guarriman: acid_kewpie makes a good point. The file paths in a tar archive are stored as relative paths for a good reason. It gives you more flexibility about where to restore files. You may want to restore files into a temporary location. The relative path makes this possible. If the file paths in the tar archive were absolute then you would have to chroot into a temporary directory in order to restore the files anywhere but their original location.

Last edited by stress_junkie; 07-04-2008 at 03:15 PM.
 
Old 07-04-2008, 03:35 PM   #6
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
...and there are system harmful or grave security implications when extracting with absolute pathnames or relative symbolic links that contain "..". Use cautiously.
 
Old 08-01-2008, 08:00 AM   #7
timsoft
Member
 
Registered: Oct 2004
Location: scotland
Distribution: slackware 15.0 64bit, 14.2 64 and 32bit and arm, ubuntu and rasbian
Posts: 495

Rep: Reputation: 144Reputation: 144
Smile solution

A solution to your backup without changing the nature of the tar file you create, and avoiding the stripping message would be

/bin/tar -czf /home/user/backup_www.tar.gz -C / var/www/html

this way you avoid the security hazards of the -P option and avoid the warning message about stripping /
note the "-C /" before the dir to be backed up and the removed leading /
this tells tar to change to the root ( / ) directory first, and then of course your path minus the leading /
is still the same place, even if it is relative.

It means you can restore your files easily elsewhere, as per stress_junkie's comment.

Last edited by timsoft; 08-01-2008 at 08:02 AM.
 
Old 08-02-2008, 12:45 PM   #8
smoked kipper
Member
 
Registered: May 2008
Location: UK
Distribution: Slackware,Slamd64
Posts: 81

Rep: Reputation: 15
Quote:
Originally Posted by stress_junkie View Post
The name of the archive file MUST follow the f. Therefore that is the wrong place for the P parameter. And I believe that the c must be the first parameter. Not positive about that.
This is not quite correct. When you use the "new" syntax (i.e. with a leading -) then the filename must immediately follow the f as is usual for unix commands, but with tar's "traditional" syntax, the first "word" is a list of command/option letters and any following arguments must be in the same order as the letters (for options that take arguments, of course). This means that, e.g.

Code:
tar fcz filename ...
is correct, even though it is irrational and prone to error.

It is preferable to use the "new" syntax, using a - for all options.

Code:
tar -zcf filename...
The c does not have to be first, it can be anywhere (with either syntax), though there may be some versions of tar the require the command to be first?

Last edited by smoked kipper; 08-02-2008 at 12:47 PM.
 
Old 08-02-2008, 01:06 PM   #9
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
Quote:
Originally Posted by smoked kipper View Post
The c does not have to be first, it can be anywhere (with either syntax), though there may be some versions of tar the require the command to be first?
Indeed, this used to be the case, and I'm no longer sure what the rules are for various tars. It was always a stupid requirement, and the command options without the dash was one of those dumb exceptions to an almost universally consistent Unix command line syntax.
 
Old 01-04-2009, 01:05 AM   #10
statistic
LQ Newbie
 
Registered: Jan 2009
Location: Guelph ON
Distribution: Ubuntu
Posts: 7

Rep: Reputation: 0
Hey, sorry to revive a dead thread.

Quote:
Originally Posted by stress_junkie View Post
Also, the - isn't doing any harm. Who cares if he is using BSD or GNU parameter style?
Just to let you guys know that the '-' actually seems to do harm.

Code:
statistic@SewagePlant:~$ tar -zcfP test.tar /home/statistic/webmail_auth
tar: test.tar: Cannot stat: No such file or directory
tar: Removing leading `/' from member names
tar: Error exit delayed from previous error
Then I try
Code:
statistic@SewagePlant:~$ tar zcfP test.tar /home/statistic/webmail_auth
and now it seems to work.

Before the obvious question rolls in, I'm running Ubuntu 8.04. So just to let you guys know, that sometimes, for some reason, the '-' does matter.
 
Old 01-04-2009, 12:21 PM   #11
grndrush
LQ Newbie
 
Registered: Jan 2004
Location: Hamilton, Ontario, Canada
Distribution: Arch
Posts: 17

Rep: Reputation: 0
Quote:
Originally Posted by smoked kipper View Post

{snip}

Code:
tar -zcf filename...
The c does not have to be first, it can be anywhere (with either syntax), though there may be some versions of tar the require the command to be first?
I'm running Arch Linux, which uses the GNU version of tar; the function parameter ('c' in this case) does have to come first with this distro. I always (a) use the '-' (it's self-documenting), (b) put the function code (c,x,t,etc) first, and (c) put the "f" option LAST. Seems to me a good habit to pick up.

==> statistic:
It's not the '-' that's giving you errors - it's the option order! "tar czPf ..." and "tar -czPf ..." both work here...

Last edited by grndrush; 01-04-2009 at 12:26 PM. Reason: typo
 
Old 01-05-2009, 07:59 PM   #12
statistic
LQ Newbie
 
Registered: Jan 2009
Location: Guelph ON
Distribution: Ubuntu
Posts: 7

Rep: Reputation: 0
==> grndrush:

Ok neat, so it seems that the order of the parameters is important only WITH the dash on my system (Ubuntu), but order is not important without the dash.

That seems odd, I wonder if it is because when you include the dash, it shifts to GNU mode and enforces the correct ordering of parameters, whereas without the dash it does not enforce any other GNU standards. It's not really important, but please correct me if I'm wrong, I would like to understand.
 
Old 01-05-2009, 09:57 PM   #13
grndrush
LQ Newbie
 
Registered: Jan 2004
Location: Hamilton, Ontario, Canada
Distribution: Arch
Posts: 17

Rep: Reputation: 0
Statistic -

*I* do not know (I'd like to understand tar better, also!), but your line of thinking is in line with mine, completely. Makes sense. I did a few googles on the topic yesterday, and one of the links had a comment to the effect that the famous optional "-" in tar was an abberation (not their term; I can't remember now the term they used) and completely inconsistent with the way the REST of Linux works. I agree completely and have felt that way since my first Linux install.

Of course, tar is a REALLY old, and critical, tool, and backwards compatibility is highly important - changing the command line in real-time is easy, but who KNOWS how many thousands of Linux scripts there are, world-wide, which have a tar command in them. Nothing's perfect - and Linux is MUCH more "consistent", overall, than ANYTHING ever released by M$.

Last edited by grndrush; 01-05-2009 at 09:59 PM. Reason: typo
 
Old 01-05-2009, 11:44 PM   #14
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
I believe that tar may have been written before the "dash" convention was introduced. The "-f" option needs an argument, so the line containing the "fP" options was wrong. That command will create an archive named "P" and add the file test.tar and the directory /home/statistic/webmail_auth to the archive. Obviously not what you wanted to do.

If you have two options that take arguments, then you need to use the dash. For example, it is common to start with the -C option to change the base directory where tar should extract the files.
The -f option is required. Since you can't group all of the options together, dashes are needed.
As far as I am concerned, alway use the dash.

Last edited by jschiwal; 01-05-2009 at 11:48 PM.
 
Old 01-06-2009, 12:09 PM   #15
grndrush
LQ Newbie
 
Registered: Jan 2004
Location: Hamilton, Ontario, Canada
Distribution: Arch
Posts: 17

Rep: Reputation: 0
jschiwal -

Actually, I thought the exact same thing, and tried it on my system. To my astonishment, it DIDN'T do as you (and I) expected. Again, I run Arch - YMMV w/other distros.

Ah, technology!
 
  


Reply

Tags
message, tar


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
"tar: Removing leading `/'..." - message Lotharster Linux - Newbie 4 12-02-2005 08:41 AM
Strip leading dot in filepaths (in tar archive) EcceVery Debian 2 04-13-2005 07:47 PM
LQ member progress status from member to senior member............. emailssent LQ Suggestions & Feedback 3 10-11-2004 01:31 PM
script #!/bin/bash, problem with space in file names existent Linux - General 3 06-17-2004 08:13 AM
.bin...tar.gz?? piras Linux - Software 2 07-30-2003 08:00 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration