Linux cron job remove .zip files from folder every 12 hours - linux

I'm looking for help to make a cron job that every 12 hours will delete all .zip files from a subfolder in my hostgator hosting account.
http://prntscr.com/7rr22d
After some google research I tried this command but nothing seems to happen
find /home/username/domain.com -type f -name "*.zip" |xargs rm
What should I put in the "Command:" field ?

Maybe try:
find /home/username/domain.com -name "*.zip" -exec rm -rf {} \;

Related

Task Scheduler Script copy NEW files only - Synology

Similar to this question I want to make a task scheduler script to copy NEW files (last 24h) to a new folder.
I try to use this code:
find /volume1/start/ -mtime -1 -type f -exec cp -r {} /volume1/target/ \;
but it delivers a 1kb filename.pdf#SynoEAStream file instead of the file itself.
How can I fix that?
Ok actually it seems to work as supposed I actually just had the wrong file modification date in the files where it didn't work. The script additionally copies some "useless" #SynoEAStream files whicht I now avoid by only looking for pdf-files which ist what I wanted.
find /volume1/TestScan/start/ -mtime -1 -type f -iname '*.pdf' -exec rsync -r {} /volume1/TestScan/ziel/ \;
Maybe its helpful for someone

Cron Job email find: missing argument to `-exec'

I'm setting up a webserver with Plesk on Ubuntu 18.04 and I would like to use a part of the space I've available to store security footage. I succeeded in automatically uploading the photos and videos to the correct folder, but the problem is that they are not automatically removed, so that the server is full of security images. I upload the footages to a folder on the server that is also available from the internet (secured). I did some research on the internet to a cron job that automatically deleted the files older than 7 days where I found this:
find /var/www/vhosts/path to files/* -mtime +7 -exec rm -f {} \;
I also found that you can name a file to, for example: delete-files and which can be executed with crontab -e. (Yes, I made it executable;-)
I added this cron to run every hour and stated that I received notifications from the cron. Now, however, I get the following output: find: missing argument to `-exec '
Is there anything else that I need to share? Like logs?
change find /var/www/vhosts/path to files/* -mtime +7 -exec rm -f {} \;
to
find /var/www/vhosts/path to files/ -mtime +7 -exec rm -f {} \;
the * is unnecessary in the path
Can you try this as well?
find /var/www/vhosts/path to files/ -mtime +7 | xargs rm -f

Linux find command and copy and rename them same time

Will you be able to help me to write a script, I just want to find log files over 2GB and copy them to archive folder in same directory.I just write a find command it is not working, appreciate if someone could help me.
ex - main log folders - /vsapp/logs/
- app1,app2,app3
there are lot of logs in the app1, app2 and app3 folders.
so i want to find the logs in the logs folder which is over 2GB, and copy them to archive folder with the different name with today's date.
ex - abcd.log -----copy to -----> abcd.log-08-22-2016
My command at the moment which is not working
find $i/* -type f -size +2G -exec cp '{}' $i/$arc/{}-$date
You can do:
find /src -type f -name '*.log' -size +2G -exec cp {} /dest/{}-$(date -I) \;
Additions/Modifications i made:
-name '*.log' searches only for log files, as we are only interested in those. You can look for files with any names too if unsure, just omit -name '*.log in that case
$(date -I) is command substitution the output will be today's date in format YYYY-mm-dd, you can also define a custom format, check man date
End the -exec action of find with \;

How can I exclude a directory but not its content using the find command?

I use the following command in a scheduled Cron task to delete all files older than 30 days in a folder called Downloads:
find /home/orschiro/Downloads -path ./Archiveror -prune -path ./Fairphone -prune -o -type f -mtime +30 -exec rm {} \; && notify-send "Searching for old files..."
Thereby, I want to exclude:
the folder Archiveror with all its content which it does
and the folder Fairphone but keep its content checked if older than 30 days
How do can I tell the find command to not delete the folder Fairphone but its content if older than 30 days?

In linux shell, How to cp/rm files by time?

In linux shell, When I run
ls -al -t
that show the time of files.
How to cp/rm files by time? just like copy all the files that created today or yesterday. Thanks a lot.
Depending on what you actually want to do, find provides -[acm]time options for finding files by accessed, created or modified dates, along with -newer and -min. You can combine them with -exec to copy, delete, or whatever you want to do. For example:
find -maxdepth 1 -mtime +1 -type f -exec cp '{}' backup \;
Will copy all the regular files in the current directory more than 1 day old to the directory backup (assuming the directory backup exists).
Simple Example
find /path/to/folder/ -mtime 1 -exec rm {} \; // Deletes all Files modified yesterday
For more examples google for bash find time or take a look here

Resources