LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 05-15-2016, 12:05 AM   #1
penquin.toes
LQ Newbie
 
Registered: May 2016
Posts: 4

Rep: Reputation: Disabled
New to linux and stuck in the tar


While in /home/user1, create a new tar file which contains the entire contents of your current directory. Name the new tar file: user1.tar Have the new tar file created in your current directory. When you create the tar file, create it so that the extraction path will be the current directory.

Performing tar -cvf user1.tar /home/user1 yielded results with the 1st immediate line stating tar: Removing leading '/' from memeber names followed by a massive amount of files. I am literally in my 2nd day of linux and not sure if I did this correctly with my command. The manual pages advised of multiple options but I attempted others like z and tvf and other options as well that failed giving errors: Cowardly refusing to create an empty archive

Last edited by penquin.toes; 05-15-2016 at 12:20 AM.
 
Old 05-15-2016, 12:13 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Not sure I am following your issue. Are you saying you have created a tar file and it is empty?
 
Old 05-15-2016, 12:23 AM   #3
penquin.toes
LQ Newbie
 
Registered: May 2016
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by grail View Post
Not sure I am following your issue. Are you saying you have created a tar file and it is empty?
Hello,

No. I am wondering if the command I performed is correct for the above instruction. A small brown box with the name I assigned showed up in the /home/user1 directory
 
Old 05-15-2016, 12:56 AM   #4
dunne
Member
 
Registered: May 2014
Distribution: OpenBSD
Posts: 67

Rep: Reputation: 36
To see what is in the tar file you created, type:

Code:
tar -tf user1.tar | less
This lists what is in user1.tar, and pipes that output into less so you can page through it.

Code:
man tar
Will tell you more about the tar command.
 
1 members found this post helpful.
Old 05-15-2016, 01:12 AM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,119

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Quote:
Originally Posted by penquin.toes View Post
... followed by a massive amount of files.
This is a result of using "-v"; not necessary IMHO.
As suggested "-t" is handy to see if you actually created anything useful.
 
1 members found this post helpful.
Old 05-15-2016, 01:37 AM   #6
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,292
Blog Entries: 3

Rep: Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718
Quote:
Originally Posted by penquin.toes View Post
While in /home/user1, create a new tar file which contains the entire contents of your current directory. Name the new tar file: user1.tar Have the new tar file created in your current directory. When you create the tar file, create it so that the extraction path will be the current directory.
In addition to what dunne wrote, you can take advantage of the advanced features of tar. You can use --exclude to not tar the existing tarball, for example.

Code:
tar cf user1.tar --exclude=user1.tar /home/user1/
tar tf user1.tar
Note that the --exclude has to come after the cf clause.

An even more advanced feature --transform allows you to use a sed-like pattern to find and replace parts of the file name and path.

Code:
tar -c --transform='s#home/user1/#./#' -f user1.tar --exclude=user1.tar /home/user1/;
tar -tf user1.tar
Mentioning sed, though, may be pushing you off the edge into the deep end on your second day because it drags regular expressions into the question. Regular expressions are definitely worth learning and the time invested will pay for itself in short order. The 30-second explanation is s#old#new# substitutes the string 'old' for the string new 'new'

By the way you can compress the tarball with the z, j, or J options.

Code:
tar zcf user1.tar.gz --exclude=user1.tar.gz /home/user1/
tar ztf user1.tar.gz
z is for gzip, it is common. j is for bzip2 and J for xz. All, and more, are in the detailed manual page, which hopefully gets less confusing over time.

Code:
man tar
The manual pages are quite useful references but do vary in quality from program to program. It's useful to pick through them for useful options and ignore the rest until next time.

Last edited by Turbocapitalist; 05-15-2016 at 01:38 AM.
 
1 members found this post helpful.
Old 05-15-2016, 01:45 AM   #7
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,292
Blog Entries: 3

Rep: Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718
An easier way than the --transform option is to just point tar at the current directory with a dot ( . )

Code:
cd /home/user1/
tar zcf user1.tar.gz --exclude=user1.tar.gz .
tar ztf user1.tar.gz
 
1 members found this post helpful.
Old 05-15-2016, 02:37 AM   #8
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,790

Rep: Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304
just a comment: you tried to put the result into tar, because user1.tar is inside /home/user1. That is obviously impossible. As a solution you can specify an exclusion or a much better way (at least for me) to avoid putting the final tar among the source files:
Code:
# for example:
tar -C /home/user1 -czvf /tmp/user1.tgz .
# or
tar -C /home/user1 -cf /some_dir/user1.tar .
 
2 members found this post helpful.
Old 05-16-2016, 08:48 PM   #9
Fred Caro
Senior Member
 
Registered: May 2007
Posts: 1,007

Rep: Reputation: 167Reputation: 167
-C means change directory but you might need to create one first, as c only creates the file.

hence:


tar -C /home/user1 -cf /some_dir/user1.tar .

Fred.
 
  


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
how can i decompress this tar.tar file? hmmm sounds new.. tar.tar.. help ;) kublador Linux - Software 14 10-25-2016 02:48 AM
Stuck on converting extentions tar.gz to .tgz networkingnub Linux - General 3 01-18-2010 09:17 PM
How to install tar.gz & tar.bz2 file on Linux min Krishnendu Linux Mint 2 07-16-2009 06:52 AM
BackUp & Restore with TAR (.tar / .tar.gz / .tar.bz2 / tar.Z) asgarcymed Linux - General 5 12-31-2006 02:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:35 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