zipping the files in unix having extension after - unix

I have a logs file at directory cd /opt/app/logs named as
coa.log.1
uoa.log.2
erete-rere.log.1
now my concern is that i am looking for unix command which will zip the files having extension log.1 or log.2 or having log. extension anything
request you to please advise the unix comand to zip these files
Folks please advise for this

You can compress in a lot of formats in unix. The most commom is the tar.gz extension. If you are looking fot .zip specifically, there is a zip command: zip <zipname> <files>
To pass the file list you may use the * wirldcard, indicating any name. For example: *.log.*, as sugested by glen, will match every file that contains .log. in its name.
You probably want something like this:
zip backup_logs.zip /opt/app/logs/*.log.*
This will zip all files in the folder that matched what you asked and create a zip file in your current directory.

Related

Unzip specific files in a ARR file within a Tar.gz

i'am currently trying to unzip some specific files within a ARR file. This ARR file is within a tar.gz file.
Is it possible to unzip these files without a intermediate step/One liner. Its important that the first tar.gz will not be unpacked.
Thanks!
you can try something like:
gzip -dc input_file.tar.gz|tar xf - path/to/file/you/want/to/extract
This decompress and untar the archive in memory and have advantage of run faster.

WinSCP script to synchronize directories, but exclude several subdirectories

I need to write a script that synchronizes local files with a remote machine.
My file structure is:
ProjectFolder/
.git/
input/
output/
classes/
main.py
readme.md
I need to synchronize everything, but:
completely ignore .git folder
ignore files in input and output folders, but copy the folder
So far my code is:
open sftp://me:password#server -hostkey="XXXXXXXX"
option batch abort
option confirm off
synchronize remote "C:\Users\MYNAME\Documents\MY FOLDER\Python Projects\ProjectFolder" "/home/MYNAME/py_proj/ProjectFolder" -filemask="|C:\Users\MYNAME\Documents\MY FOLDER\Python Projects\ProjectFolder\.git"
close
exit
First question: it doesn't seems to work.
Second question, how to add mask for input and output folder if I have spaces in file paths?
Thanks to all in advance.
Masks for directories have to end with a slash.
To exclude files in a specific folder, use something like */folder/*
-filemask="|.git\;*/input/*;*/output/*"

zip files of a certain date to zip file with batch

I'm trying to do a batch file to run every day. The batch needs to zip all the files with the current system date.
I have the following for now and it's working but is zipping all the files.
#echo off
"c:\Program Files\7-Zip\7z.exe" a -tzip "C:\test\location_zip\zip_file_%date:~6,4%-%date:~3,2%-%date:~0,2%" "C:\test\*.*"
pause
Can someone please help me to zip only the files created with system date instead all?
Many thanks,
I do not have a 7-zip solution. But with WinRAR this can be very easily achieved:
"%ProgramFiles%\WinRAR\WinRar.exe" a -ac -afzip -agYYYY-MM-DD -ao -cfg- -ed -ep1 -inul -m5 -r -tn24h "C:\test\location_zip\zip_file_" "C:\test\*.*"
a ... add files to archive.
-ac ... clear archive attribute after compression.
-afzip ... create a ZIP archive instead of a RAR archive.
-agYYYY-MM-DD ... append current date to archive file name in format YYYY-MM-DD.
-ao ... add only files with archive attribute set.
-cfg- ... ignore configuration file and RAR environment variable.
-ed ... do not add empty directories.
-ep1 ... exclude base directory from names, i.e. C:\test\
-inul ... disable all error messages.
-m5 ... use best compression method.
-r ... recurse subdirectories.
-tn24h ... add only files with a last modification date within last 24 hours (newer than 24 hours).
A single license of WinRAR is very cheap and includes unlimited upgrades. The few dollars/euros for a WinRAR license are invested well taking into account the time needed to code a batch file for archiving purposes with free 7-zip because of missing features which WinRAR has since more than 10 years. (I bought my WinRAR license in 1999 and have never needed any other compression tool.)

unzip all files and save all contents in a single folder - unix

I have a single directory containing multiple zip files that contain .jpg files.
I need to unzip all files and save all contents (.jpgs files) into a single folder.
Any suggestions on a unix command that does that?
Please note that some of the contents (jpgs) might exist with same name in multiple zipped files, I need to keep all jpgs.
thanks
unzip '*.zip' -o -B
as by default these utilities are not installed
see http://www.cyberciti.biz/tips/how-can-i-zipping-and-unzipping-files-under-linux.html regarding installation
read about -B flag to realize its limitations.

Creating Zip of directory in Unix m/c

on Unix m/c i have folder in which there are few more folders..
I wants to make zip file of parent folder. and i should able to unzip this zip file in windows m/c..
Can you please advice..
thanks in advance..
given that the program 'zip' is available, the following should work:
zip -r archive_name.zip folder
From midnight commander highlight the directory that you want to zip, then press F2 to get to the user menu, then # to perform an operation on it. You can now enter zip -r archive.zip followed by return, where archive.zip is that name of the zip file that you want to create.
zip -r parent-directory parent-directory
If you have zip installed on your Unix host.
It will create parent-directory.zip file and it can be unzipped on Windows using native unzip Windows program.

Resources