LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 05-17-2017, 03:42 AM   #16
mackowiakp
Member
 
Registered: Jun 2014
Location: Poland/Gdynia
Distribution: Mageia 7, SH4, Debian
Posts: 316

Original Poster
Rep: Reputation: 8
Talking


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 ?
 
Old 05-17-2017, 03:52 AM   #17
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,622

Rep: Reputation: 5610Reputation: 5610Reputation: 5610Reputation: 5610Reputation: 5610Reputation: 5610Reputation: 5610Reputation: 5610Reputation: 5610Reputation: 5610Reputation: 5610
no, it isn't ASAP, because:
Code:
curr=`echo $(( $x / 3600 / 24 ))`
# should be written as:
curr=$(( $x / 3600 / 24 ))
for example.
 
Old 05-17-2017, 04:35 AM   #18
mackowiakp
Member
 
Registered: Jun 2014
Location: Poland/Gdynia
Distribution: Mageia 7, SH4, Debian
Posts: 316

Original Poster
Rep: Reputation: 8
OK, right small difference ;-)
 
Old 05-17-2017, 08:42 AM   #19
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952

Rep: Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting a non empty folder without having to change directories poadeosun1 Linux - Newbie 2 02-04-2015 08:32 PM
Deleting empty line at end of text file in BASH human2.0 Linux - General 8 04-01-2009 02:44 AM
Deleting empty/blank line with per script knockout_artist Programming 2 10-31-2008 01:25 PM
ProFTPD - deleting non-empty directories? orange400 Linux - Software 1 05-28-2004 03:36 AM
deleting non-empty directory sadiboyz Linux - Newbie 2 04-21-2003 09:29 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration