LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-18-2014, 09:11 PM   #1
anandg111
Member
 
Registered: Jan 2012
Posts: 56

Rep: Reputation: Disabled
tar files without absolute path


Hi,
I want to tar files without absolute path.
For exaple i have some files users home directory and some files in users desktop dir. I want to tar them all together without entire directory structure is it possible ?
 
Old 11-18-2014, 09:56 PM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 3,131

Rep: Reputation: 1347Reputation: 1347Reputation: 1347Reputation: 1347Reputation: 1347Reputation: 1347Reputation: 1347Reputation: 1347Reputation: 1347Reputation: 1347
You can insert "-C dirpath" in the argument list to cause tar to change directory before processing the arguments that follow:
Code:
tar -cf stuff.tar -C /home/user file1 file2 -C Desktop file3 file4
The archive will contain just "file1", "file2", "file3", and "file4" without any other path components.
 
Old 11-18-2014, 11:02 PM   #3
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,654

Rep: Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255
You can also use "--strip-components=n" which will remove the leading n elements (use 1 if all you are removing is the /)

Tar normally removes the leading / anyway - it will tell you that.
 
  


Reply


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] tar with or without absolute path steinz Linux - Server 3 01-29-2013 04:27 PM
[SOLVED] tar absolute and relative path mmhs Linux - Newbie 13 08-09-2012 09:09 PM
Samba veto-files option on an absolute path? fmillion Linux - Server 0 11-12-2011 03:19 AM
bash: how to tar without absolute path? xushi Programming 1 05-20-2007 10:13 AM
tar saves absolute path warshke Linux - Software 2 03-27-2006 08:43 AM


All times are GMT -5. The time now is 08:54 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration