I want a simple line of code that will compress files within a directory specified (parameter) and its subdirectories and also i want to remove files which are exactly 365 days old from the sysdate after this compression.
Please help.
Use \+ if you are passing files to utilities which can handle multiple files.
This is valid in both gzip and cp, and you should gain performance with small change.
Also, files with .gz extension gzip will not attempt to compress, but rather print on stderr that file(s) already have gz extension and it will skip it.
Keep in mind that if fileXYZ.gz exists on same location where same fileXYZ is being compressed, gzip will prompt you for overwrite halting your program awaiting user input.
You really don't want to come to a machine after N days/months to see N crons with N finds awaiting user input..
The part after the -type f should be in (esccaped) brackets, otherwise it would attempt to rm an old *.gz directory.
Or this version that also eliminates a redundant -name '*.gz'
Ok, this will delete all files if +365 days old, including uncompressed ones (where gzip has failed). Rather a feature than a mistake.
The efficient + instead of the \; should work as well.
Exact, if name of subdirectory is the name of file where to launch command then this file will delete.
So, We can just repeat -type f after -o connector: