Tar command fails


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Tar command fails
# 1  
Old 12-06-2015
Tar command fails

I am on Oracle Linux:

Code:
tar -cpzf export.tar.gz /dir/dir1/dir2/*

bash: /bin/tar: Argument list too long

I tried the workaround

from the folder /dir/dir1/dir2:

Code:
find . -name '*' -print | tar -cpzf export.tar.gz --files-from –

My issue is that the command inludes the newly created tar file as part of the tar.

How can I ensure if the tar only includes the files in the sub directory dir2 and not the tarfile itself?

Thanks much!

Last edited by Don Cragun; 12-07-2015 at 03:08 AM.. Reason: Add CODE and ICODE tags.
# 2  
Old 12-06-2015
Try creating the archive outside of the directory where find is working on.
Code:
find . -print | tar cpzf ../export.tar.gz -T -

This User Gave Thanks to Aia For This Post:
# 3  
Old 12-06-2015
Quote:
Originally Posted by Aia
Try creating the archive outside of the directory where find is working on.
Code:
find . -print | tar cpzf ../export.tar.gz -T -

Thanks This worked!!
# 4  
Old 12-06-2015
You could also just use:
Code:
find . ! -name export.tar.gz | tar -cpzf export.tar.gz --files-from -

# 5  
Old 12-07-2015
Quote:
Originally Posted by sumang24
Thanks This worked!!
I spoke too soon

I am not sure if I did something wrong, I see 2 files with the same name in the tar file created in the uppper level of subdirectory.
# 6  
Old 12-07-2015
File names can have the same name, but not the same path (location where they leave)

Example of two files with the same name
Code:
$ tree
.
├── dir1
│   └── sumang24.file
└── dir2
    └── sumang24.file

Creating a tar.gz file outside the directory sumang24
Code:
$ tar cpvzf ../sumang24.tar.gz *
dir1/
dir1/sumang24.file
dir2/
dir2/sumang24.file

Now, checking the content of sumang24.tar.gz
Code:
$ tar tf sumang24.tar.gz
dir1/
dir1/sumang24.file
dir2/
dir2/sumang24.file

For further understanding, you might need to post some more information.
Please, post the following:
  • The result of pwd before issuing the command
  • The output entries shown by the command tar tf export.tar.gz for only those two files you say they are the same.
  • The exact command that you used to tar and gzip.
  • And any clear explanation of what you expected but it was not so.
This User Gave Thanks to Aia For This Post:
# 7  
Old 12-07-2015
Did you remove the export.tar.gz created by your first run before running again using ../export.tar.gz as the output file?

Did you try using the find pipeline I suggested in post #4 in this thread?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Cybersecurity

Use command 2 incase command 1 fails

I try to fire grep command on remote servers using ssh like below: sshpass -p mypassword ssh -t user1@mach2 "grep -e word1 -e word2 /var/out.txt" The issue is that i wish to run the same grep command which searches for multiple strings in a file on remote servers with different Operating... (6 Replies)
Discussion started by: mohtashims
6 Replies

2. Shell Programming and Scripting

Script to check one command and if it fails moves to other command

Input is list of Server's, script is basically to remove old_rootvg, So it should check first command "alt_rootvg_op -X old_rootvg" if it passes move to next server and starts check and if it fails moves to other command "exportvg old_rootvg" for only that particular server. I came up with below,... (6 Replies)
Discussion started by: aix_admin_007
6 Replies

3. Shell Programming and Scripting

SH script, variable built command fails, but works at command line

I am working with a sh script on a solaris 9 zone (sol 10 host) that grabs information to build the configuration command line. the variables Build64, SSLopt, CONFIGopt, and CC are populated in the script. the script includes CC=`which gcc` CONFIGopt=' --prefix=/ --exec-prefix=/usr... (8 Replies)
Discussion started by: oly_r
8 Replies

4. Shell Programming and Scripting

tar command to explore multiple layers of tar and tar.gz files

Hi all, I have a tar file and inside that tar file is a folder with additional tar.gz files. What I want to do is look inside the first tar file and then find the second tar file I'm looking for, look inside that tar.gz file to find a certain directory. I'm encountering issues by trying to... (1 Reply)
Discussion started by: bashnewbee
1 Replies

5. Shell Programming and Scripting

Need help! command working ok when executed in command line, but fails when run inside a script!

Hi everyone, when executing this command in unix: echo "WM7 Fatal Alerts:", $(cat query1.txt) > a.csvIt works fine, but running this command in a shell script gives an error saying that there's a syntax error. here is content of my script: tdbsrvr$ vi hc.sh "hc.sh" 22 lines, 509... (4 Replies)
Discussion started by: 4dirk1
4 Replies

6. AIX

Find command fails in crontab

Hi , I imported find command I have on my hp-ux server to clean up the /tmp of my new IBM AIX servers. Though, the commands always fails in the cron but if I past it at the prompt, it works find. I tried with at jobs and regular 'find' . Could anyone tell me what I am doing wrong? Many... (4 Replies)
Discussion started by: cforget2810
4 Replies

7. Shell Programming and Scripting

tar command dont tar to original directory

HI, if I have a tarfile called pmapdata.tar that contains tar -tvf pmapdata.tar -rw-r--r-- 0/0 21 Oct 15 11:00 2009 /var/tmp/pmapdata/pmap4628.txt -rw-r--r-- 0/0 21 Oct 14 20:00 2009 /var/tmp/pmapdata/pmap23752.txt -rw-r--r-- 0/0 1625 Oct 13 20:00 2009... (1 Reply)
Discussion started by: borderblaster
1 Replies

8. Shell Programming and Scripting

unzip command fails in ssh

I'm trying to run a set of commands on a remote machine using ssh in a shell script. One of the commands is unzip. But when the execution reaches this command, the script fails with an error that unzip is not found. Below is the code and the error snippet. sourceDir=$1 ; filename=$3 ; destDir=$2... (4 Replies)
Discussion started by: farahzaiba
4 Replies

9. AIX

AIX: chpath command fails

Hi Guys, i'm having trouble changing the path-priority. Now both priorities are 1 as you can see in the lspath-output. Any ideas why the chpath command fails? # chpath -l hdisk3 -p fscsi1 -a priority=10 Method error (/etc/methods/chgdisk): 0514-080 Invalid routine argument... (4 Replies)
Discussion started by: raba
4 Replies

10. UNIX for Advanced & Expert Users

at command fails

hi, all the user on my machine can't launch at job anymore. they all got the message "error in message send" each time they launch something using the at command. i tried to empty the job queue but the error message is still there. What can I do ? Thanks (1 Reply)
Discussion started by: a329743
1 Replies
Login or Register to Ask a Question