Unable to create tar file of files from specific folder . Getting wrong path after extraction

user3559780

Here I want to create tar file of bin folder only . My main.c code has location i.e. /home/amit/practice/datafill/main.c. datafill directory contains folders like bin, conf, config, data,lib.

There is one link system("cd <path>") in a C program But it doesn't solve my problem . with the use of combining 2 commands with && operator it is creating bin.tar from bin folder only ,but when it is extracted, it is containing full path link /home/amit/practice/datafill/bin/ which is wrong .Suppose there is one file abc.txt inside bin folder . So after extraction ,abc.txt should have path as bin/abc.txt only, not /home/amit/practice/datafill/bin/abc.txt

#include<stdio.h>
#include<unistd.h>
int main(void)
{
char Cmd[256];
/*Go to specific directory && create tar file*/
sprintf(Cmd,"cd /home/amit/practice/datafill/bin/ && sudo tar -cvf bin.tar *");
system(Cmd);
return 0;
}
Joshua

Your code creates the tar file in the bin directory, but it appears you checked an older attempt in the current directory.

This code is strange and unnatural. I would normally do something like this:

 `cd /home/amit/practice/datafill/bin/ && sudo tar -cvf - *`

which causes the tarball is written to the program's standard output. If you want to generate it to a specific path, this would be more reasonable

 `sudo sh -c '(cd /home/amit/practice/datafill/bin/ && tar -cvf - *) > bin.tar'`

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Create tar gz on linux with specific list of files from sed output

From Dev

extract files to a relative path from a tar file that was creating with -P flag

From Dev

compress specific folder(directory) from folder with tar

From Dev

Remove Specific File From Tar Archival Process After the Process Starts

From Dev

Php create folder on specific path

From Dev

How to delete image file from specific folder path?

From Dev

Extract specific folder from a tar.gz

From Dev

Can't create files in a specific folder from the given list

From Dev

How to retrieve the path of files from a folder into a text file with a python script?

From Dev

How to copy all files to a folder from path in a txt file?

From Dev

Batch file that copies files from an external device into a specific folder

From Dev

Unable to create folder from batch file run by C#

From Dev

create tar file from stdin

From Dev

VB.Net: Getting File Path from Data Files In Project

From Dev

How to tar several files without containing their whole path in tar file

From Dev

VBS - Getting program files folder path?

From Dev

Unable to untar file after tar error

From Dev

bash to create sub directories in folder from specific file extension

From Dev

cd in pipe after getting folder path

From Dev

Getting `write too long` error when trying to create tar.gz file from file and directories

From Dev

Create folder directory from path?

From Dev

RecusriveDirectoryIterator - Getting files within folder with specific params

From Dev

Count specific files from folder

From Dev

create a .tar file of all latest files in the directories

From Dev

Extract a specific folder to specific directory from a tar.gz

From Dev

download googlesheet and create folder in specific path to save

From Dev

Unable to add folder to PATH in .profile file

From Dev

Undo tar file extraction mess

From Dev

Python: Extracting specific files with pattern from tar.gz without extracting the complete file

Related Related

  1. 1

    Create tar gz on linux with specific list of files from sed output

  2. 2

    extract files to a relative path from a tar file that was creating with -P flag

  3. 3

    compress specific folder(directory) from folder with tar

  4. 4

    Remove Specific File From Tar Archival Process After the Process Starts

  5. 5

    Php create folder on specific path

  6. 6

    How to delete image file from specific folder path?

  7. 7

    Extract specific folder from a tar.gz

  8. 8

    Can't create files in a specific folder from the given list

  9. 9

    How to retrieve the path of files from a folder into a text file with a python script?

  10. 10

    How to copy all files to a folder from path in a txt file?

  11. 11

    Batch file that copies files from an external device into a specific folder

  12. 12

    Unable to create folder from batch file run by C#

  13. 13

    create tar file from stdin

  14. 14

    VB.Net: Getting File Path from Data Files In Project

  15. 15

    How to tar several files without containing their whole path in tar file

  16. 16

    VBS - Getting program files folder path?

  17. 17

    Unable to untar file after tar error

  18. 18

    bash to create sub directories in folder from specific file extension

  19. 19

    cd in pipe after getting folder path

  20. 20

    Getting `write too long` error when trying to create tar.gz file from file and directories

  21. 21

    Create folder directory from path?

  22. 22

    RecusriveDirectoryIterator - Getting files within folder with specific params

  23. 23

    Count specific files from folder

  24. 24

    create a .tar file of all latest files in the directories

  25. 25

    Extract a specific folder to specific directory from a tar.gz

  26. 26

    download googlesheet and create folder in specific path to save

  27. 27

    Unable to add folder to PATH in .profile file

  28. 28

    Undo tar file extraction mess

  29. 29

    Python: Extracting specific files with pattern from tar.gz without extracting the complete file

HotTag

Archive