Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 11-18-2014, 08:11 PM   #1
Registered: Jan 2012
Posts: 56

Rep: Reputation: Disabled
tar files without absolute path

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, 08:56 PM   #2
Senior Member
Registered: Aug 2009
Distribution: CentOS
Posts: 3,401

Rep: Reputation: 1489Reputation: 1489Reputation: 1489Reputation: 1489Reputation: 1489Reputation: 1489Reputation: 1489Reputation: 1489Reputation: 1489Reputation: 1489
You can insert "-C dirpath" in the argument list to cause tar to change directory before processing the arguments that follow:
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, 10:02 PM   #3
Senior Member
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,688

Rep: Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259
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.


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 03:27 PM
[SOLVED] tar absolute and relative path mmhs Linux - Newbie 13 08-09-2012 08:09 PM
Samba veto-files option on an absolute path? fmillion Linux - Server 0 11-12-2011 02:19 AM
bash: how to tar without absolute path? xushi Programming 1 05-20-2007 09:13 AM
tar saves absolute path warshke Linux - Software 2 03-27-2006 07:43 AM

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

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