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 12-17-2007, 08:21 AM   #1
LQ Newbie
Registered: Dec 2007
Posts: 11

Rep: Reputation: 0
bash - tar command

i have a final question ...

i have a list of directories inside a string.
i want to tar these directories. i wrote this code;

directories="/home/cumhur/code/scripts /home/cumhur/Desktop/vim71/src"

for i in $directories
	tar -cvzf "$destination$date-$i.tar" "$i"
what is wrong in the code ?
it gives me this result;

tar: /home/cumhur/Desktop/compressed-/home/cumhur/code/scripts.tar: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: Removing leading `/' from member names
/home/cumhur/code/scripts/untitled folder/
/home/cumhur/code/scripts/untitled folder/deneme
/home/cumhur/code/scripts/untitled folder/program2.c
/home/cumhur/code/scripts/untitled folder/
edit: these directories exist.

Last edited by klavuzkarga; 12-17-2007 at 08:23 AM.
Old 12-17-2007, 08:34 AM   #2
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
You are simply trying to do something like
tar -cvzf "/home/cumhur/Desktop/compressedMon Dec 17 15:28:00 CET 2007-/home/cumhur/code/scripts" "/home/cumhur/code/scripts"
which is obviously wrong. You can first extract the name of the directory from its absolute path and eventually format the date to avoid blank spaces inside the file name. For example
directories="/home/cumhur/code/scripts /home/cumhur/Desktop/vim71/src"

for i in $directories
        dir=$(basename $i)
	tar -cvzf "${destination}/$(date +%Y-%m-%d)-${dir}.tar" "$i"
Also, when you are testing scripts you can put an echo in front of some commands: in this way the commands are not executed but will be echoed after the shell has done all the variable expansions (and you will immediately know if the results are what you expected or not).

Last edited by colucix; 12-17-2007 at 08:38 AM.
Old 12-17-2007, 08:49 AM   #3
Registered: Mar 2007
Distribution: centos
Posts: 126

Rep: Reputation: 15
i think the dir should me more detail define,
you can try this dir=`ls -R youdir`;And i'm unable to describle it


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
BackUp & Restore with TAR (.tar / .tar.gz / .tar.bz2 / tar.Z) asgarcymed Linux - General 5 12-31-2006 02:53 AM
need some help with muli-volume tar (ubuntu, bash, gnu tar) MattCarp Linux - General 4 06-05-2006 08:15 AM
bash syntax when envoking tar command in python script tangle Programming 4 02-04-2006 03:22 PM
bash/tar bokini Programming 2 07-30-2005 04:50 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:13 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
Open Source Consulting | Domain Registration