Kompx.com or Compmiscellanea.com

Unzip multiple files. Linux

Operating systems : Linux

Unzip multiple zip files into one directory by Linux command line unzip. Contrary to possible expectations, "unzip *.zip" is not going to work, *.zip should be put into quotes:

unzip "*.zip"

There may be files with the same names in these archives. To avoid overwriting:

unzip -B "*.zip"

"Unzip -B" makes unzip to overwrite duplicates during extraction process, but saving a backup copy of each overwritten file. The names for these backup copy files are created by adding tilde ("~") at the end of the original names of the files. If a file extension is present, then "~" is added after it. If that is not enough, unique sequence number (up to 5 digits) is appended after the "~".

"Unzip -B" is not too practical. For example, since when the sequence number range for numbered backup files gets exhausted (99999, or 65535 for 16-bit systems), the backup file with the maximum sequence number is deleted and replaced by the new backup version without notice ( More on the subject ). The number of files in an archive may not be always known in advance or may be more than possible sequence number range, so "Unzip -B" is not a great choice. Renaming duplicate files by adding "~" at the end of their names, after the extension, is not too convenient either.

But another built-in option is even worse. If the "-B" modifier is not used, each time a file with same name as there already unpacked is being extracted, unzip asks "replace example.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename:". And each time "r" must be hit, then a new name has to be input. So some bash or another script solving the problem should probably be prepared and used instead.


Aliosque subditos et thema

 

HTTP to HTTPS redirect in .htaccess

 

Redirecting from HTTP to HTTPS, when the web server serving the pages is behind a load balancer or reverse proxy. Server configuration: Apache + nginx; SSL is enabled; SSL-certificate is purchased, approved and installed. That is, everything is up and running. So it is just the HTTP to HTTPS redirection that is left to get ready and start up. Directives for .htaccess file: RewriteEngine On RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] RewriteCond %{HTTP:X_FORWARDED_PROTO} !https [NC] RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L] HTTP to HTTPS redirect -- Enable runtime rewriting engine: RewriteEngine On -- If domain name has no www: RewriteCond %{HTTP_HOST} !^www\. [NC] -- Then replace it with domain with www: RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] -- If HTTPS is not present: RewriteCond %{HTTP:X_FORWARDED_PROTO} !https [NC] -- Then replace domain without HTTPS with domain with HTTPS: RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L] Notes 1. X_FORWARDED_PROTO may instead be called X-Forwarded-Proto or even else. The point is to obtain the information from a load balancer or reverse proxy on the original request it gets. Load balancers or reverse proxies may provide the web server with this info and a header named X_FORWARDED_PROTO or X-Forwarded-Proto or else may be sent, holding the protocol string. It is most often so, but not always. So it should probably be determined by practice how to get the protocol string in a particular case. 2. The other way is just to set the environment variable (if it is suitable for the given web server): SetEnvIf X_FORWARDED_PROTO https HTTPS=on Then directives for .htaccess file are to be like this: RewriteEngine On SetEnvIf X_FORWARDED_PROTO https HTTPS=on RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] RewriteCond %{HTTP:HTTPS} !on [NV] RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L] 3. Apache Module mod_rewrite docs: http://httpd.apache.org/docs/current/mod/mod_rewrite.html

Extract tar.bz2

 

Extracting tar.bz2 files in Linux, command line: tar jxvf file.tar.bz2 - j : filter the archive through bzip2 [ 1 ] - x : extract files from an archive - v : list the files processed - f : use archive file The command extracts the contents of a bzip2 compressed archive to the current directory. Tar creates an archive of one or several files. Then bzip2 is used to compress it. Or both processes are made at once by tar only, with corresponding options employed. The duality of nature - archived and then compressed - is reflected in the extension of the file ("tar.bz2") and requires two procedures to be performed while extracting: decompressing and unpacking. Hence both j (decompress it) and x (unpack it) in the command. [ 1 ] Sources for the option letters description: tar(1) - Linux man page and LinuxCommand.org