Tar linux скрытые файлы

Zip including hidden files

EDIT: The correct way is zip -r 1.zip .

The commands shown in my previous answer below are incorrect because they also include the parent directory.

zip yourfile.zip sourcedir/* .* 

It should include all hidden files also.

apparently. When i do zip 1.zip * .* (in a folder with subfolder a and a hidden file called ‘.hidden_file’) i get:

Or you can add more simple

Just to be sure it is not forgotten since this is a forum for developers and a good number of us use git.

An easy way to get only what you want in the zip is to use git archive -o filename.zip branch

If you want to zip all files (+hidden files) Kindly using: zip -r namefiles.zip . The «.» is all files in folder.

zip -r namefiles.zip "folder will zip" 

How is your answer different to the accepted answer, which states «The correct way is zip -r 1.zip . «?

The «.» is NOT all files in folder. It means the «current folder» itself, which would ultimately include all its contents.

On macOS 10.15.7 I had to separatelly add all dot leading files ( \.* ) and rest of the files ( * ):

if you don’t have rights to save zip file in current dir you can go to dir where you have rights and type

zip -r 1.zip /path/to/source/dir/. 

However when if in . /some_dir you type

then your files will be decompress into . /some_dir/path/to/source/dir/

Just doing zip -r 1.zip .* will include the parent folder as well so the trick is to exclude the parent folder using -x «../*»

If you’d like to save some subdirectory of the current directory recursively with hidden and regular files just type

$ zip -r backup_subdirectory.zip backup_subdirectory/. backup-subdirectory/* 
$ unzip backup_subdirectory.zip 

Or even simpler by using tar for creating an archive:

$ tar czvf backup_subdirectory.tar.gz backup_subdirectory/ 

And for extracting all files from the archive:

$ tar xzvf backup_subdirectory.tar.gz 

Источник

Читайте также:  Сделать бэкап postgresql linux

Will tar -cvzf packed.tar.gz mydir take hidden files into account?

I need to create a tarball of a given directory. However, I need to make sure hidden files are included too (such as those beginning with . ). Will the following command automatically take the hidden files into account?

tar -cvzf packed.tar.gz mydir 

NOTICE: In my case, I’ve realized(by experiment) that tar czvf something.tar.gz path contains them, but tar czvf something.tar.gz path/* doesn’t!

For those who would like to archive all items in the current directory, the following worked for me: $ tar czvf ../archive.tar.gz . Whereas if the trailing dot is replaced by a * then the (hidden, in some sense) dotfiles from the current directory are not included.

1 Answer 1

Files starting with . are not «hidden» in all contexts. They aren’t expanded by * , and ls doesn’t list them by default, but tar doesn’t care about the leading . . ( find doesn’t care either.)

(Of course, this is one of those things that’s easy to find out by experiment.)

Thanks. Yes experiment is sometimes a solution to find an answer, but in this case, I am not a unix expert and I know behaviors — in general — can be modified with configuration. What if two systems are not configured the same way? The belief I might build from one system might not be true for another.

@JVerstry: Good point. A suggestion, though; a question like «I tried this, and it worked; is it guaranteed?» would have been even better.

tar —help lists several different options, all beginning with —exclude that allow one to exclude various files based on name, pattern, etc. Agreed, experimentation is a great way to test and verify if something works as expected. Make backups regularly!

@RiccardoManfrin There was no * in the question. If you do tar cvzf data.tar.gz * , the * is expanded by the shell; tar never sees it. If you do tar cvzf data.tar.gz ‘*’ , tar will see the * and will interpret as a file literally named * . tar (at least GNU tar ) does have some support for wildcards, but as far as I know only for files in an archive. gnu.org/software/tar/manual/html_node/wildcards.html

Источник

Почему скрытые файлы не добавляются в архив?

webirus

sim3x

Войдите, чтобы написать ответ

Безопасен ли линукс для хранения файлов?

Существует ли дистрибутив линукс готовый к работе в домене из коробки?

Можно ли регулировать routing через bastion server в зависимости от группы пользователя?

Как скомпилировать код C в .ko?

Панель управления сервером с поддержкой ActiveDirectory/LDAP?

Куда телеграм сохраняет видео в линукс?

Как не загружать ОЗУ на 100%+?

Почему BASH скрипт по проверке самоподписанного SSl сертификата выдает неверную дату окончания и начала?

Как написать скрипт сбора tcpdump?

С каким интервалом времени установить команды на cron?

Минуточку внимания

  • Можно ли выключить автоматическую очистку Data usage/App history в Windows 10?
    • 3 подписчика
    • 1 ответ
    • 2 подписчика
    • 1 ответ
    • 2 подписчика
    • 1 ответ
    • 2 подписчика
    • 1 ответ
    • 4 подписчика
    • 1 ответ
    • 2 подписчика
    • 2 ответа
    • 3 подписчика
    • 4 ответа
    • 3 подписчика
    • 1 ответ
    • 2 подписчика
    • 3 ответа
    • 2 подписчика
    • 2 ответа

    Источник

    Create tar archive of a directory, except for hidden files?

    I’m wanting to create a tar archive of a specific directory (with its subdirectories of course). But when I do it, using the tar command, I get a list of files that were included, for example:

    As you can see, there are two versions of the same file. This goes for every file, and there are many. How do I exclude the temporary files, with the ._ prefix, from the tar archive?

    These aren’t temporary files, but represent OS X file system metadata (if I’m not mistaken, they include Finder labels, type and creator codes, extended attributes, etc.). These files don’t exist prior to creating the tar on OS X. Possible answers depend on whether you’re on OS X/HFS+ or another system.

    6 Answers 6

    You posted in a comment that you are working on a Mac OS X system. This is an important clue to the purpose of these ._* files.

    These ._* archive entries are chunks of AppleDouble data that contain the extra information associated with the corresponding file (the one without the ._ prefix). They are generated by the Mac OS X–specific copyfile(3) family of functions. The AppleDouble blobs store access control data (ACLs) and extended attributes (commonly, Finder flags and “resource forks”, but xattrs can be used to store any kind of data).

    The system-supplied Mac OS X archive tools ( bsdtar (also symlinked as tar ), gnutar , and pax ) will generate a ._* archive member for any file that has any extended information associated with it; in “unarchive” mode, they will also decode those archive members and apply the resulting extended information to the associated file. This creates a “full fidelity” archive for use on Mac OS X systems by preserving and later extracting all the information that the HFS+ filesystem can store.

    The corresponding archive tools on other systems do not know to give special handling to these ._* files, so they are unpacked as normal files. Since such files are fairly useless on other systems, they are often seen as “junk files”. Correspondingly, if a non–Mac OS X system generates an archive that includes normal files that start with ._ , the Mac OS X unarchiving tools will try to decode those files as extended information.

    There is, however an undocumented(?) way to make the system-supplied Mac OS X archivers behave like they do on other Unixy systems: the COPYFILE_DISABLE environment variable. Setting this variable (to any value, even the empty string), will prevent the archivers from generating ._* archive members to represent any extended information associated with the archived files. Its presence will also prevent the archivers from trying to interpret such archive members as extended information.

    COPYFILE_DISABLE=1 tar czf new.tar.gz … COPYFILE_DISABLE=1 tar xzf unixy.tar.gz … 

    You might set this variable in your shell’s initialization file if you want to work this way more often than not.

    # disable special creation/extraction of ._* files by tar, etc. on Mac OS X COPYFILE_DISABLE=1; export COPYFILE_DISABLE 

    Then, when you need to re-enable the feature (to preserve/restore the extended information), you can “unset” the variable for individual commands:

    (unset COPYFILE_DISABLE; tar czf new-osx.tar.gz …) 

    The archivers on Mac OS X 10.4 also do something similar, though they use a different environment variable: COPY_EXTENDED_ATTRIBUTES_DISABLE

    Источник

    archiving hidden directories with tar

    tar on a directory mydir will archive hidden files and hidden subdirectories, but tar from within mydir with a * wildcard will not. Is this a known inconsistency or bug? Edit: Additional information. tar from within mydir with a * wildcard will not «see» nor archive hidden files and hidden subdirectories in the immediate directory. However, in the non-hidden subdirectories of mydir hidden files and hidden subdirectories will be archived. In other words, deeper in the directory tree the hidden objects will be archived.

    7 Answers 7

    With wildcard it will not work. You have to specify . (current directory) if you mean full directory including hidden files. You can do

    But be careful of placing the new tar inside the same directory you are tarring. You can get into a nasty loop.

    Putting it somewhere else might mean using sudo which might cause additional work (which you might want to avoid) in dealing with the GUI-based scheduler or crontab.

    The answer is that the * wildcard is handled by the shell and it just does not expand to things that start with a dot. The other wildcard ? also does not expand to things that start with a dot. Thanks to Keith for pointing out it is the shell that does the expansion and so it has nothing to do with tar .

    If you use shopt -s dotglob then expansion will include things like .filename . Thanks to Andy.

    Use shopt -u dotglob to turn it off.

    Switching the dotglob option does not change ls itself. Rather it just changes expansion behaviour as exhibited in something like ls * .

    Edit: My recommendations are in a comment below.

    Источник

Оцените статью
Adblock
detector