Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Linux: delete all files NOT being accessed

Posted on 2011-09-08
7
Medium Priority
?
279 Views
Last Modified: 2013-12-16
I want to delete all files here that are NOT currently being accessed or downloaded:
/home/userxyz/public_html/downloads/

If a file is in that directory and is NOT being downloaded or accessed, I want it to be deleted.
0
Comment
Question by:hankknight
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 38

Expert Comment

by:wesly_chen
ID: 36504381
as "root", type
find  /home/userxyz/public_html/downloads/   -type f   -atime +7
  to see how many files are not accessed within past 7 days.

If you are sure those files can be delete, then

find  /home/userxyz/public_html/downloads/   -type f   -atime +7  -exec /bin/rm -f {}\;
   to remove them

you can change  to "-atime +3" for not accessed for past 3 days.
0
 
LVL 16

Author Comment

by:hankknight
ID: 36504784
Is there a way to do this for files that are not CURRENTLY being accessed?

If we must set a time then files not accessed for 10 minutes.
0
 
LVL 38

Accepted Solution

by:
wesly_chen earned 500 total points
ID: 36504813
> not accessed for 10 minutes.
-amin +10

find  /home/userxyz/public_html/downloads/   -type f   -amin +10  -exec /bin/rm -f {}\;
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 38

Assisted Solution

by:Gerwin Jansen, EE MVE
Gerwin Jansen, EE MVE earned 500 total points
ID: 36505035
>> Is there a way to do this for files that are not CURRENTLY being accessed?

You'd have to be using lsof if you want to know for sure. But then you would have to compare a directory listing of ./downloads with lsof output and determine what can be deleted. This is a more difficult approach than using find with -amin +10 (access for 10 minutes).
0
 
LVL 40

Expert Comment

by:noci
ID: 36507150
be shut that the disks are mounted with the atime option though. (noatime is used a lot to speed up diskaccess by preventing updates of the atime stamp ....)
0
 
LVL 40

Assisted Solution

by:noci
noci earned 500 total points
ID: 36507152
be sure in stead of be shut... Sorry.
0
 
LVL 8

Assisted Solution

by:eager
eager earned 500 total points
ID: 36516510
Open files are not deleted until the last user closes the file, although the directory entry is removed immediately.  This may mean that you can delete all files in the directory and any that are currently being accessed will continue to be read. There may be interactions with a web server or other program which causes the file to be re-opened.

You can test this easily by creating a large file which takes a while to download or copy.  While this is being accessed, delete the file.  The transfer should complete without error.  
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Suggested Courses

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question