How do I tar a directory without retaining the directory structure?

前端 未结 9 1291
[愿得一人]
[愿得一人] 2020-12-23 16:01

I\'m working on a backup script and want to tar up a file directory:

tar czf ~/backup.tgz /home/username/drupal/sites/default/files

This ta

相关标签:
9条回答
  • 2020-12-23 16:13
    cd /home/username/drupal/sites/default/files
    tar czf ~/backup.tgz *
    
    0 讨论(0)
  • 2020-12-23 16:14

    For me -C or --directory did not work, I use this

    cd source/directory/or/file
    tar -cvzf destination/packaged-app.tgz *.jar
    # this will put your current directory to what it previously was
    cd -
    
    0 讨论(0)
  • 2020-12-23 16:16

    Use the --directory option:

     tar czf ~/backup.tgz --directory=/home/username/drupal/sites/default files 
    
    0 讨论(0)
  • 2020-12-23 16:17

    Create a tar archive

    tar czf  $sourcedir/$backup_dir.tar --directory=$sourcedir WEB-INF en
    

    Un-tar files on a local machine

    tar -xvf $deploydir/med365/$backup_dir.tar -C $deploydir/med365/
    

    Upload to a server

    scp -r -i $privatekey $sourcedir/$backup_dir.tar $server:$deploydir/med365/
    echo "File uploaded.. deployment folders"
    

    Un-tar on server

    ssh -i $privatekey $server tar -xvf $deploydir/med365/$backup_dir.tar -C $deploydir/med365/
    
    0 讨论(0)
  • 2020-12-23 16:18

    Kindly use the below command to generate tar file without directory structure

    tar -C <directoryPath> -cvzf <Path of the tar.gz file> filename1 filename2... filename N
    

    eg:

    tar -C /home/project/files -cvzf /home/project/files/test.tar.gz text1.txt text2.txt
    
    0 讨论(0)
  • 2020-12-23 16:23

    This worked for me:

    gzip -dc "<your_file>.tgz" | tar x -C <location>
    
    0 讨论(0)
提交回复
热议问题