Linux zip with hidden files

How to zip all files including hidden files to zip file using linux command?

Question: I have linux hosting and wanted to zip everything in one single ZIP file but all time .htaccess file is excluded and other hidden files are not adding to zip file. Any other way to find files and file sizes.

How to zip all files including hidden files to zip file using linux command?

I have linux hosting and wanted to zip everything in one single ZIP file but all time .htaccess file is excluded and other hidden files are not adding to zip file.

The easiest way is to tell your shell to include hidden files in globs. With bash this is done with shopt -s dotglob .

I suppose, you try something like

but * doesn’t match filenames starting with a dot. But ? matches a dot, so ?* matches all file names, including those starting with a dot. Unfortunally it also matches .. , the parent directory, so do

This will match everything in the current directory.

One thing to note is if you are using a wildcard such as tar -cvpzf your_zip.tgz * it will not include hidden files. However, if you specify the directory such as tar -cvpzf your_zip.tgz /path/to/dir it will work. Or moreover, if you would like to run in your current directory:

tar -cvpfz your_zip.tgz --exclude=*.tgz . 

How to unzip all zipped files in a Linux directory?, As one can notice, there are few .zip files present in the above directory and we can unzip all these .zip files with the help of the command shown below. Command unzip “*.zip” Now once we run the following command, all the .zip files will be unzipped and their contents will be printed in the terminal. Output

How to find all .zip files and file size in linux

I have 2TB of data. I want to list entire .zip and .rar files and files size in the directory and I want to exclude 01_Personal Folder directory.

I tried below command but it didn’t work out.

find /home -type f ( -name ".zip" -o -name ".rar" ) ! -path "01_Personal Folder*" -print0 | xargs -0 -n1 du -b | sort -n -r > winrar.txt 

Any other way to find files and file sizes.

Recall that find has a predicate printf to create formatted output, including size. So you can combine the filtering and formatting together:

find /home -type f '(' -name "*.zip" -o -name "*.rar" ')' '!' -path "01_Personal Folder*" -printf '%P %k\n' 

Note: remember to quote all tokens which might have special meaning. This includes the file patterns (*.zip, . ), parentheses, exclamation point which might mean somthing to the shell.

Читайте также:  Linux mint usb from mac

Filtering on the name/folder with find eliminate searching and size calculation on unrelated files.

Example: to search for all .zip files in current directory and all sub-directories try this:

This will list all files ending with .zip regarding of case. If you only want the ones with lower-case change -iname to -name

The command grep searches for stings in files, not for files. You can use it with find to list all your .zip files like this

After you get the list of .zip files you can easily find the size of them.

You can use the below command: du -ah | grep -e «.zip» -e «.rar»

Explanation: du shows the disk usage, -h is for human-readable size. And grep will find the match for .zip and as for multiple words we’ll use -e.

Linux — How to unzip all files in directory using shell, you can use simple unzip command. Let me give you an example: go into the directory where you have the zip files. cd /home/rexter/test there are few zip files in this location. ls 1.zip 2.zip 3.zip now if you want to unzip them all just type: unzip ‘*.zip’ And its done! ##### As you want script for the same. Here it is …

Zip all files and subfolder in directory without parent directory

I have the following folder structure

folder | |--foo.txt | |--sub_folder | |--bar.txt 

I want to zip the content (files and sub folders) of folder without including the root folder in the zip.

But this includes the root folder. Also tried the following form

zip -j -r package.zip folder

But this will flatten all the directory structures and just include the files. How do I preserve the internal directory structure but ignore the parent folder?

zip stores paths relative to the current directory (when it is invoked), so you need to change that:

(cd folder; zip -r ../package.zip .) 

The above command will zip all files and sub folders under folder directory (It will ignore the parent directory for folder)

Zip — Zipping all files in a folder but excluding all, I would like to zip all files in a given folder but none of the directories: any idea on how to do it? e.g. directory X contains files F1 and F2 and directories D1 and D2. How can I zip directory X to only have F1 and F2 and not D1 and D2.

Zip everything in current directory

I’d like to compress and package everything, including files and folders in current directory, into a single ZIP file on Ubuntu.

What would be the most convenient command for this (and name of the tool needed to be installed if any)?

Edit: What if I need to exclude one folder or several files?

You can use the flags -0 (none) to -9 (best) to change compressionrate

Excluding files can be done via the -x flag. From the man-page:

-x files --exclude files Explicitly exclude the specified files, as in: zip -r foo foo -x \*.o which will include the contents of foo in foo.zip while excluding all the files that end in .o. The backslash avoids the shell filename substitution, so that the name matching is performed by zip at all directory levels. Also possible: zip -r foo foo -x@exclude.lst which will include the contents of foo in foo.zip while excluding all the files that match the patterns in the file exclude.lst. The long option forms of the above are zip -r foo foo --exclude \*.o and zip -r foo foo --exclude @exclude.lst Multiple patterns can be specified, as in: zip -r foo foo -x \*.o \*.c If there is no space between -x and the pattern, just one value is assumed (no list): zip -r foo foo -x\*.o See -i for more on include and exclude. 

I guess many people who come via Google to this question mean «archive and compress» when they write «zip». An alternative to the zip format is tar:

tar -czf copy.tar.gz whatever/ 

where the compressed archive file will be copy.tar.gz and the contents will be everything in the folder whatever.

 -c, --create create a new archive -z, --gzip, --gunzip --ungzip -f, --file ARCHIVE use archive file or device ARCHIVE 

Zip and Unzip Commands in Linux, Unzip password-protected zip files. To unzip a password-protected zip file without prompting, use -P option, followed by the password for the file: $ unzip -P < password >zip_file. For instance, we have a zip file, test. zip , that is protected by the password “ tin ”. To extract this file, the command would be:

Читайте также:  Windows 10 встроенный linux

Источник

Zipping all files/dirs in a directory except hidden ones?

How can I make a zip of all the files and subdirectories in the directory mydir , except all those files/dirs that begin with a .* ? The command:

mydir/foo mydir/bar mydir/.hello 

7 Answers 7

@Joe Internet, @Dariusz: normal shell patterns won’t work properly because zip matches against the full path+filename internally (as the zip manual explains. 😉 )

Claeys — My example workerd for me, but to be fair, I used Ch Shell (includes zip) under Win7. I CDed into my test directory, and used ‘zip -r test.zip ./ -x .*.*’ (minus the single quotes). If I use ‘zip -r mydir.zip mydir -x «/.«‘ (minus the single quotes), it doesn’t exclude the hidden file in my test directory. I guess it’s down to differences in the shells used to test with.

Shorter, and takes advantage of the features of globbing:

(. files are not included in the * wildcard)

Note that the directory ‘mydir/’ may not be included in the paths of the files in the resultant zip file, so this will change the output slightly. You may have to change your extraction process as a result.

Interesting thing I just found: It will add a top-level hidden folder, but none of its contents (hidden or visible)

The following approach works for this type of directory tree:

$ tree . . ├── adir1 │ ├── afile1 │ ├── afile2 │ ├── afile3 │ └── afile4.txt ├── adir2 │ ├── afile1 │ ├── afile2 │ ├── afile3 │ └── afile4.txt ├── adir3 │ ├── afile1 │ ├── afile2 │ ├── afile3 │ └── afile4.txt ├── afile1 ├── afile2 ├── afile3 ├── foo.test 

This was the solution that worked for this scenario (which I believe is the more general case).

 $ find . -type f -not -path '*/\.*' -exec zip -r test.zip <> + 

Example

$ find . -type f -not -path '*/\.*' -exec zip -r test.zip <> + updating: adir1/afile1 (stored 0%) updating: adir1/afile1.zip (stored 0%) updating: adir1/afile2 (stored 0%) updating: adir1/afile3 (stored 0%) updating: adir1/afile4.txt (stored 0%) updating: adir2/afile1 (stored 0%) updating: adir2/afile2 (stored 0%) updating: adir2/afile3 (stored 0%) updating: adir2/afile4.txt (stored 0%) updating: adir3/afile1 (stored 0%) updating: adir3/afile2 (stored 0%) updating: adir3/afile3 (stored 0%) updating: adir3/afile4.txt (stored 0%) updating: afile1 (stored 0%) updating: afile2 (stored 0%) updating: afile3 (stored 0%) updating: foo.test (deflated 87%) 

Источник

Читайте также:  Dd wrt linux commands

How to zip all files including hidden files to zip file using linux command? [closed]

I have linux hosting and wanted to zip everything in one single zip file but all time .htaccess file is excluded and other hidden files are not adding to zip file.

3 Answers 3

The easiest way is to tell your shell to include hidden files in globs. With bash this is done with shopt -s dotglob .

I suppose, you try something like

but * doesn’t match filenames starting with a dot. But ? matches a dot, so ?* matches all file names, including those starting with a dot. Unfortunally it also matches .. , the parent directory, so do

This will match everything in the current directory.

Wildcard expansion is done by the shell, the zip version is irrelevant. What is your shell and what files are missing in the archive?

I am sorry. I already stated the version, but forgot to mention bash. It is the version of bash I am using. Thank you.

One thing to note is if you are using a wildcard such as tar -cvpzf your_zip.tgz * it will not include hidden files. However, if you specify the directory such as tar -cvpzf your_zip.tgz /path/to/dir it will work. Or moreover, if you would like to run in your current directory:

tar -cvpfz your_zip.tgz --exclude=*.tgz . 

They did say «zip» several times in the title, question, and tags, so a ‘tar’ answer a little off-target. Your idea is almost there, too — when given a wildcard source, tar would actually include hidden files of subdirectories, just not (by default) of the current directory.

Hot Network Questions

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.13.43531

Linux is a registered trademark of Linus Torvalds. UNIX is a registered trademark of The Open Group.
This site is not affiliated with Linus Torvalds or The Open Group in any way.

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

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