0

I am using this command

tar -zcf acc.tar.gz /home/uname/public_html/project/js

it is creating the zip file fine, but zip file contains all the folders in home->uname->public_html->projects/js..

i want only js folder in the zip..

msturdy
  • 10,479
  • 11
  • 41
  • 52
Arsalan
  • 461
  • 3
  • 12

1 Answers1

2

Try the following to get only the contents of the js folder, and no sub-directory content:

tar -czf acc.tar.gz --no-recursion /home/uname/public_html/project/js/*

Try the following to change to the directory to avoid archiving the absolute path:

tar -czf acc.tar.gz -C /home/uname/public_html/project ./js

From the man tar page:

--no-recursion
    don't recurse into directories
-C, --directory DIR
    change to directory DIR
Lars
  • 108
  • 11
  • Thnx 4 ur response, but i want every thing in the js folder i just want my zip to contain only the js folder with all its content.. – Arsalan Jun 17 '14 at 11:00
  • Right now my zip file contains hhome->uname->public_html->projects/js->js files folders, i want the zip to contain js->js files folders – Arsalan Jun 17 '14 at 11:02
  • I get what you're seeking now. I'll change the answer from: `tar -czf acc.tar.gz --no-recursion /home/uname/public_html/project/js/*` to: `tar -czf -C /home/uname/public_html/project ./js`. Also see: http://stackoverflow.com/questions/3153683/how-do-i-exclude-absolute-paths-for-tar – Lars Jun 17 '14 at 11:16
  • Awesome.. Ase Lars... Thnx a million.. :) – Arsalan Jun 17 '14 at 11:35