Tar a file

I need help. I need to compress, (.tar) a file named file.text and append the date on its file name, from file.text, it should now be file_120724.tar.

The problem now with my below script is that it place the .tar file on the location where the script is located, not on the location of the original file likewise, it also compress the whole directory, not the file that I want to compress.

tar -zcvf file_$(date +%y%m%d).tar /direc/tory/ 

Thanks a lot.

tar -zcvf /location/of/file/dot/text/file_$(date ...).tar.gz /location/of/file/dot/text/file.text

thanks Scott for the prompt reply. I tried the below command and it gives me what I am looking for, however, I am not that certain if it's safe in the production servers:

tar -zcvf /location/of/the/file/file.text_$(date +%y%m%d).tar /*/*/*/file.text

thanks!

jasperux

If you know "/location/of/the/file", why do you need "/*/*/*", etc?

I really wanted to only compress the file.text, not including the directories where it reside, that's why I thought of using /*/*/*. Is there any way where I can only compress the file.text?

Thanks.

You can use the tar -C option, or cd to the directory first, if you like.

Scott, how can I possible do that in the script. I'm just new in the scripting world.

Thanks a lot!

cd /location/of/file/dot/text
tar -zcvf file_$(date ...).tar.gz file.text