The -C option is needed so tar knows where the files with relative names are located. The best way is to combine it with tar's -T option, like this: find /my/dir/ -printf "%P\n" -type f -o -type l -o -type d | tar -czf mydir.tgz -no-recursion -C /my/dir/ -T -īasically what it does is list all files ( -type f), links ( -type l) and subdirectories ( -type d) under your directory, make all filenames relative using -printf "%P\n", and then pass that to the tar command (it takes filenames from STDIN using -T -). ) to add a file list to the command (like in magnus' answer), but that potentially causes a "file list too long" error. It becomes increasingly difficult to tame the command. You can move all the files out of that directory by using the -transform configuration option, but that doesn't get rid of the. in the archive: tar -czf mydir.tgz -C /my/dir. The below unfortunately includes a parent directory. With some conditions (archive only files, dirs and symlinks): find /my/dir/ -printf "%P\n" -type f -o -type l -o -type d | tar -czf mydir.tgz -no-recursion -C /my/dir/ -T. file1!) find /my/dir/ -printf "%P\n" | tar -czf mydir.tgz -no-recursion -C /my/dir/ -T.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |