0

I'm trying to archive specific files on diferent folders. I use this bash command:

tar cf file.tar /home/albertserres/Descargas/file

Inside the .tar file i have a folder named home inside another folder names albertserres, another folder called Descargas and inside there's my file.

Why this happens? I just need the file, not the entire folder hierachy

2
  • 1
    There's no compression going on here. You're just making an archive. And what do Python and TKInter have to do with it?
    – Barmar
    Apr 1 '15 at 21:27
  • Yes i know, but i don't want the folder hierachy inside, I just want the files on the root. I put python and tkinter by error, because the work is about it.
    – user2911701
    Apr 2 '15 at 0:35
2

Use the -C option to change to the directory before archiving the file.

tar cf file.tar -C /home/albertserres/Descargas file

In Python this should be:

saveFolder = "/home/albertserres/a.tar"
srcFolder = "/home/albertserres/Descargas"
srcFile = "test1"
subprocess.call(["tar", "rvf", saveFolder, "-C", srcFolder, srcFile])
4
  • It sends me error: rejected cause going to make empty folder (i translated it from spanish)
    – user2911701
    Apr 2 '15 at 0:34
  • I've tried it and it works for me. Make sure you have a space between the directory and file, not /.
    – Barmar
    Apr 2 '15 at 0:36
  • If i do it on a terminal it works with the space! The problem is that i'm using subprocess.call because i'm working on python. Here is the command: saveFolder = /home/albertseres/a.tar temporal =/home/albertserres/Descargas/ test1 subprocess.call(["tar","rvf",saveFolder,"-C",temporal]) It dosn't work. error: rejected cause going to make empty folder
    – user2911701
    Apr 2 '15 at 0:58
  • The directory and filename have to be separate arguments to subprocess.call. I'll update the answer.
    – Barmar
    Apr 2 '15 at 1:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy