LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 12-12-2013, 05:24 AM   #1
riahc3
Member
 
Registered: Dec 2002
Posts: 223

Rep: Reputation: 1
tar all files and folders in the current directory


I want to make a tar file with everything inside the directory. This includes files, folders, and hidden "." files and folders.

Ive tried two commands

(lets say current directory Im in is /hello)

tar -zcvf something.tar.gz .

This does it but inside the archive, it adds a "." to the front of all files/folders

Next I tried:

tar -zcvf something.tar.gz *

This does it better but doesnt copy .htaccess and files that are hidden it seems

How can I do it?
 
Old 12-12-2013, 05:40 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
It is best to not stand in the directory you want to tar. Assuming you want to tar the user directory in /home/user:
Code:
cd /home
tar zcf something.tar.gz user/
If you do not have write permissions in /home you can do:
Code:
cd /home
tar zcf /path/to/something.tar.gz user/
 
Old 12-12-2013, 05:50 AM   #3
riahc3
Member
 
Registered: Dec 2002
Posts: 223

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by druuna View Post
It is best to not stand in the directory you want to tar.
I know. I just perfer to do it this way (personal preference)
 
Old 12-12-2013, 05:52 AM   #4
riahc3
Member
 
Registered: Dec 2002
Posts: 223

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by druuna View Post
It is best to not stand in the directory you want to tar. Assuming you want to tar the user directory in /home/user:
Code:
cd /home
tar zcf something.tar.gz user/
If you do not have write permissions in /home you can do:
Code:
cd /home
tar zcf /path/to/something.tar.gz user/
Tried that

cd /home
tar -zcvf filename.tar.gz user/

And it make a tar but inside there was only "filename.tar 2"

What went wrong?
 
Old 12-12-2013, 06:13 AM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Quote:
Originally Posted by riahc3 View Post
I know. I just perfer to do it this way (personal preference)
You might want to reconsider you personal preference. If you do it your way then:
- the tar file itself ends up in the tar file
- untarring might overwrite files that do not want/need to be overwritten.

Anyway:
Quote:
Originally Posted by riahc3 View Post
cd /home
tar -zcvf filename.tar.gz user/

And it make a tar but inside there was only "filename.tar 2"

What went wrong?
Did something go wrong? Without knowing what is inside the directory you tarred I cannot give you any pointers.

Here's a real life example:
Code:
$ pwd
/home/druuna/Schuur/Tmp
$ ls
New  Temp  Test
 $ ls -la Test/
total 20
drwxr-x--- 2 druuna druuna  4096 dec 12 13:10 .
drwxr-x--- 5 druuna druuna 16384 dec 12 13:04 ..
-rw-r----- 1 druuna druuna     0 dec 12 13:05 .dot.file
-rw-r----- 1 druuna druuna     0 dec 12 13:05 normal.file

$ tar zcf /home/druuna/test.tar.gz Test/
$ tar tf /home/druuna/test.tar.gz 
Test/
Test/.dot.file
Test/normal.file
 
Old 12-12-2013, 06:34 AM   #6
riahc3
Member
 
Registered: Dec 2002
Posts: 223

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by druuna View Post
You might want to reconsider you personal preference. If you do it your way then:
- the tar file itself ends up in the tar file
- untarring might overwrite files that do not want/need to be overwritten.
Don't mind and I can exclude the tar file itself.

Quote:
Originally Posted by druuna View Post
Anywayid something go wrong? Without knowing what is inside the directory you tarred I cannot give you any pointers.

Here's a real life example:
Code:
$ pwd
/home/druuna/Schuur/Tmp
$ ls
New  Temp  Test
 $ ls -la Test/
total 20
drwxr-x--- 2 druuna druuna  4096 dec 12 13:10 .
drwxr-x--- 5 druuna druuna 16384 dec 12 13:04 ..
-rw-r----- 1 druuna druuna     0 dec 12 13:05 .dot.file
-rw-r----- 1 druuna druuna     0 dec 12 13:05 normal.file

$ tar zcf /home/druuna/test.tar.gz Test/
$ tar tf /home/druuna/test.tar.gz 
Test/
Test/.dot.file
Test/normal.file
There are files and folders inside of the directory. But all I got is:

http://img189.imageshack.us/img189/7990/dg7s.png

Last edited by riahc3; 12-12-2013 at 06:54 AM.
 
Old 12-12-2013, 06:46 AM   #7
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Yopu post doesn't tell us too much.
- Post the exact command you used and from which location.
- Also post the content of the dir you try to tar (if big: +/- 10 lines).
- Post the output (again: first 10 lines if big) of the following command: tar tf name.of.tar.gz
 
Old 12-12-2013, 07:29 AM   #8
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
If you really don't want to include top directory:
Code:
# assuming you are standing in the dir you want to tar:
$ tar czf some.name.tar.gz -C `pwd` .
 
Old 12-12-2013, 08:21 AM   #9
riahc3
Member
 
Registered: Dec 2002
Posts: 223

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by druuna View Post
Yopu post doesn't tell us too much.
- Post the exact command you used and from which location.
- Also post the content of the dir you try to tar (if big: +/- 10 lines).
- Post the output (again: first 10 lines if big) of the following command: tar tf name.of.tar.gz

1: Im in /home/user and Im trying to tar /home/user/public_html
I used:
tar -zcvf try.ta.gz public_html/
2:
user@alpha [~]# ls -al public_html/
total 680
drwxr-xr-x 28 user nobody 4096 Dec 12 12:36 ./
drwx--x--x 20 user user 4096 Dec 12 13:29 ../
-rw-r--r-- 1 user user 4898 Feb 12 2013 .htaccess
-rw-r--r-- 1 user user 4600 Apr 3 2012 .htaccess.sample
drwxr-xr-x 3 user user 4096 Nov 30 2012 .idea/
-rw-r--r-- 1 user user 10679 Apr 3 2012 LICENSE.html
-rw-r--r-- 1 user user 10410 Apr 3 2012 LICENSE.txt
-rw-r--r-- 1 user user 10421 Apr 3 2012 LICENSE_AFL.txt
-rw-r--r-- 1 user user 436921 Apr 3 2012 RELEASE_NOTES.txt
drwxr-xr-x 6 user user 4096 Nov 30 2012 app/
drwxr-xr-x 5 user user 4096 Nov 30 2012 awstats-7.0/
drwxr-xr-x 2 user user 4096 Oct 31 2012 cgi-bin/
drwxr-xr-x 2 user user 4096 Apr 9 2013 correo/
-rw-r--r-- 1 user user 1606 Apr 3 2012 cron.php
-rw-r--r-- 1 user user 642 Apr 3 2012 cron.sh
drwxr-xr-x 2 user user 4096 Nov 30 2012 dataBaseScript/
drwxr-xr-x 3 user user 4096 Aug 22 08:51 dev/
3:
(Last lines)
public_html/var/minifycache/minify_e5e26b022e209a3a6c7f5fd549624af2
public_html/var/minifycache/minify_be3ccb4ca8cedaef4a7311da2da6fe79.gz
public_html/var/minifycache/minify_cb8b071c6a5b8329ba7b2a860b05e348.gz
public_html/var/minifycache/minify_46531ab44a2eab68d009f42339a46027
public_html/var/minifycache/minify_18d81ac9b5dc0d83eb7e3fd40d0a4945.gz
public_html/var/minifycache/minify_54d7427a3af286b5392aece87c89e0fd
public_html/var/minifycache/minify_5c4da8fa3d19816bd3c480a49fc3883d.gz
public_html/var/.htaccess
public_html/includes/
public_html/includes/config.php
public_html/includes/.htaccess
public_html/LICENSE.txt

I open the file and all I see inside is "try.ta"
 
Old 12-12-2013, 08:34 AM   #10
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Quote:
Originally Posted by riahc3 View Post
3:
(Last lines)
public_html/var/minifycache/minify_e5e26b022e209a3a6c7f5fd549624af2
public_html/var/minifycache/minify_be3ccb4ca8cedaef4a7311da2da6fe79.gz
public_html/var/minifycache/minify_cb8b071c6a5b8329ba7b2a860b05e348.gz
public_html/var/minifycache/minify_46531ab44a2eab68d009f42339a46027
public_html/var/minifycache/minify_18d81ac9b5dc0d83eb7e3fd40d0a4945.gz
public_html/var/minifycache/minify_54d7427a3af286b5392aece87c89e0fd
public_html/var/minifycache/minify_5c4da8fa3d19816bd3c480a49fc3883d.gz
public_html/var/.htaccess
public_html/includes/
public_html/includes/config.php
public_html/includes/.htaccess
public_html/LICENSE.txt
Assuming the above is the output of tar tf try.ta.gz: It seems to be working perfectly.

Quote:
I open the file and all I see inside is "try.ta"
Explain a bit more what you are trying to do:
- The tar tf ... command seems to be showing everything, tar xf ... would extract everything.

You are using tar, right?
 
Old 12-12-2013, 09:03 AM   #11
riahc3
Member
 
Registered: Dec 2002
Posts: 223

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by druuna View Post
Assuming the above is the output of tar tf try.ta.gz: It seems to be working perfectly.

Explain a bit more what you are trying to do:
- The tar tf ... command seems to be showing everything, tar xf ... would extract everything.

You are using tar, right?
??? What ???

The command tar compresses/archives the file into one
 
Old 12-12-2013, 09:38 AM   #12
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Quote:
Originally Posted by riahc3
I open the file and all I see inside is "try.ta"
The content of the tar file is correct, as shown, in post #9, by the tar tf try.ta.gz command.

How are you trying to open the tar file? Which command? Which options? Are you using the tar command or some other command?

Provide info, I'm not a psychic.
 
Old 12-12-2013, 09:48 AM   #13
Madhu Desai
Member
 
Registered: Mar 2013
Distribution: Rocky, Fedora, Ubuntu
Posts: 541

Rep: Reputation: 153Reputation: 153
Quote:
Originally Posted by riahc3 View Post
I know. I just perfer to do it this way (personal preference)
Then save tar file somewhere else.
Code:
tar -czvf ../try.tar.gz .
Quote:
Originally Posted by riahc3 View Post
I open the file and all I see inside is "try.ta"
How did you open 'try.ta.gz'? In the screenshot you provided, the compressed file name has space inbetween (MS Win style). While compressing with tar did you give name with space inbetween and no quotes around it?
 
Old 12-12-2013, 10:07 AM   #14
riahc3
Member
 
Registered: Dec 2002
Posts: 223

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by druuna View Post
The content of the tar file is correct, as shown, in post #9, by the tar tf try.ta.gz command.

How are you trying to open the tar file? Which command? Which options? Are you using the tar command or some other command?

Provide info, I'm not a psychic.
Im sorry, I was just confused because I felt I was being insulted without reason.

I open the tar file with WinRAR and thats what I see as its contents.

Im sorry for not giving enough information.
 
Old 12-12-2013, 10:09 AM   #15
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Quote:
Originally Posted by riahc3 View Post
I open the tar file with WinRAR and thats what I see as its contents.
WinRAR is a windows specific program. I'm not able to help you with that (maybe some other member can).
 
  


Reply



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
move all files in current directory into a subdirectory in the current directory jakykong Linux - Newbie 8 07-16-2013 11:46 PM
tar files not the folders takayama Linux - Desktop 5 05-13-2011 01:01 AM
find and unzip selected sub folders in tar.gz files samanp Linux - Server 1 11-05-2010 09:16 AM
extracting .tar.gz files in current directory... mitesh.ever Linux - Newbie 4 12-09-2008 06:03 AM
tar multiple folders and files at once sinister1 Linux - General 4 12-10-2007 02:49 AM

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

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