Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to remove all the files in the current folder that are created after the specific time?!

Posted on 2006-04-20
11
Medium Priority
?
203 Views
Last Modified: 2010-04-21
I want to remove all the files in the current folder that are created after the 17:00h (for example)!

P.S.:I don't need a script for this to schedule it, just for a one time execution.

I supose that i need to use the rm and find commands, but.. how?!
0
Comment
Question by:oky-doky
  • 6
  • 5
11 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 16497537
assuming you have a file with timestamp 17:00, then do

find . -type f -newer ./file-of-17:00 -exec rm {} \;

(use ls instead of rm for testing)
0
 

Author Comment

by:oky-doky
ID: 16497837
Nice, but.. isn't working!

For an example (on the concrete example), i have the next:
-rw-r--r--      1      user      is06      16      Apr      20      14:13      dat1.txt
-rw-r--r--      1      user      is06      0      Apr      20      14:14      dat1.txt

...and i want to remove all the files that are created after the 14:00, then i'll need to write:
find . -type f -newer ./file-of-14:00 -exec rm {} \;
or
find . -type f -newer ./file-of-14:00 -exec ls {} \;

The results are:
find: ./file-of-14:00: No such file or directory

Something needs to be changed...
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 16498997
> .. ../file-of-14:00
> find: ./file-of-14:00: No such file or directory
you have to use a real existing filename
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:oky-doky
ID: 16499614
I don't understand this "real existing filename".
Why can't i find that two files dat1.txt & dat2.txt - which are created AFTER the 14:00?!
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 16499723
> Why can't i find that two files dat1.txt & dat2.txt - which are created AFTER the 14:00?!
cause you need a file which was created BEFORE 14:00
find itself can only use timestamps older than 24 hours, see man find

> I don't understand this "real existing filename".
if you have a file named timestamp, where you see with:
  ls -l timestamp

somthing like:

-rw-r--r--     1     user     is06     16     Apr     20     14:00     timestamp

then your find looks like:

  find . -type f -newer ./timestamp -exec ls {} \;
0
 

Author Comment

by:oky-doky
ID: 16499999
OK! That is correct, full working!

Now i understand what you all the time are trying to "show" me!

Conclusion: this is a method of removing (if rm is used) the files which are newer than the specified file (timestamp).

Now i have the different "idea" (question): is it possible to remove all the files without specifieng that "timestamp" file which is actually created at 14:00? Can it be done with some other command, maybe?
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 750 total points
ID: 16500122
> .. is it possible to remove all the files without specifieng that "timestamp" file
not with find

> Can it be done with some other command, maybe?
hmm, I'm not aware of a single command doing that.
I'd use
  touch `date +%m%d`1400 timestamp
  find . -type f -newer ./timestamp -exec ls {} \;
(some systems allow this kind of touch command as user root only)
0
 

Author Comment

by:oky-doky
ID: 16501613
Thanks, ahoffmann!

Only what left tricky (for me!) is this touch command which is creating a file named "timestamp" and should set it to 14:00 (date of creation), but that just isn't working - file is created and set on the current system time.

Easier whould be (which is working well):
      touch -d1400 timestamp

THANKS again!!! You're the legend!

[btw.. that was my first question asked on experts-exchange.com - which cost me some points, but points spent on that in comparison to knowledge what i have now.. :]!

Greetings from Croatia [HRVATSKA]:)!
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 16501745
glad to have helped you
dobro dan ;-)
0
 

Author Comment

by:oky-doky
ID: 16501858
Very nice (try:)..

It's a night [21:48h] but that's not so important..

dobar dan:)!!
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 16502099
hehe, that's (beside pievo) what remains from last holidays
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses

580 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