Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
|
05-17-2017, 03:42 AM
|
#16
|
Member
Registered: Jun 2014
Location: Poland/Gdynia
Distribution: Mageia 9, SH4, Debian
Posts: 370
Original Poster
Rep:
|
Finally I found out most ASAP solution (ASAP -> As Simple As Possible).
Because name of directory I want to remove (and all its content) is a date of creation, because it is surveillance system. So using "date" command I can count number of days from 1970-01-01. If number of days is grater then 30 form today, just remove whole dir. The code below:
Code:
#!/bin/sh
#
ilosc_dni=30
#
katalog=/share/CACHEDEV2_DATA/kamery
FILES_Front_mp4=/share/CACHEDEV2_DATA/kamery/Kamery/Front/FI9900P_00626E660E5A/record
FILES_Front_jpg=/share/CACHEDEV2_DATA/kamery/Kamery/Front/FI9900P_00626E660E5A/snap
FILES_Bok_mp4=/share/CACHEDEV2_DATA/kamery/Kamery/Bok/FI9900P_00626E682B7A/record
FILES_Bok_jpg=/share/CACHEDEV2_DATA/kamery/Kamery/Bok/FI9900P_00626E682B7A/snap
#
#
x=`date +"%s"` ; actual=`echo $(( $x / 3600 / 24 ))`
for i in $FILES_Front_mp4 $FILES_Front_jpg $FILES_Bok_mp4 $FILES_Bok_jpg
do
for data in `find $i -maxdepth 1 -name '20*'|grep -o '.\{8\}$'`
do
x=`date -d $data +"%s"` ; curr=`echo $(( $x / 3600 / 24 ))`
dni=$((actual-curr))
[ $dni -gt $ilosc_dni ] && rm -rf $i/$data 2>/dev/null
done
done
Isnr it ASAP ?
|
|
|
05-17-2017, 03:52 AM
|
#17
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,745
|
no, it isn't ASAP, because:
Code:
curr=`echo $(( $x / 3600 / 24 ))`
# should be written as:
curr=$(( $x / 3600 / 24 ))
for example.
|
|
|
05-17-2017, 04:35 AM
|
#18
|
Member
Registered: Jun 2014
Location: Poland/Gdynia
Distribution: Mageia 9, SH4, Debian
Posts: 370
Original Poster
Rep:
|
OK, right small difference ;-)
|
|
|
05-17-2017, 08:42 AM
|
#19
|
LQ Guru
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342
|
I was going to suggest just having your script delete the entire directory then recreate it. that gets rid of any hidden files within it. But it looks to me you said something about only needing to get rid of a few files. You could as a work around. Use a different Logic.
Code:
1. find all files you want to keep.
2. create temp dir, move them into same said dir. if they are on the same partition. Depending on the over all size, that shouldn't take to long to do.
3. delete 'old' dir.
4. rename 'temp' dir to the same one you just deleted.
5. done.
the time required to do this should not be too much longer. as long as the directory in question being worked on is not receiving new data within it while in any part of that script running.
Last edited by BW-userx; 05-17-2017 at 08:43 AM.
|
|
|
All times are GMT -5. The time now is 06:44 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|