Solved

delete file

Posted on 2013-05-25
8
277 Views
Last Modified: 2013-06-04
[oracle@term1 admin]$ ls -lart
total 40
-rw-r--r--  1 oracle oinstall  187 May  9  2007 shrept.lst
drwxr-xr-x  2 oracle oinstall 4096 Feb  2 13:47 samples
drwxr-xr-x 11 oracle oinstall 4096 Feb  2 13:57 ..
-rw-r--r--  1 oracle oinstall  223 Feb  2 14:04 sqlnet.ora
-rw-r-----  1 oracle oinstall  738 Feb  8 00:43 tnsnames.ora~
-rw-r--r--  1 oracle oinstall  382 Mar 13 20:45 listener.ora~
-rw-r-----  1 oracle oinstall 1036 Mar 13 23:03 tnsnames.ora
-rw-r--r--  1 oracle oinstall  382 May 19 21:45 listener.ora
drwxr-xr-x  4 oracle oinstall 4096 May 25 09:06 .
drwxr-xr-x  2 oracle oinstall 4096 May 25 09:06 admin
[oracle@term1 admin]$ cd 7~

Is there any command just to delete that all files created on May 25
rm -rf  is applicable to admin but one of the file is hidden
0
Comment
Question by:walkerdba
8 Comments
 
LVL 29

Expert Comment

by:Randy Downs
ID: 39196793
Try piping your ls into rm \.*

http://www.linuxforums.org/forum/red-hat-fedora-linux/69038-how-delete-hidden-files.html

u can remove the hidden files by this command

$ rm \.*
0
 
LVL 27

Accepted Solution

by:
serialband earned 500 total points
ID: 39196967
First you find them.

find . -ctime -1  -exec ls -la "{}" \;

Then you can delete them.
find . -ctime -1  -exec rm "{}" \;
0
 
LVL 34

Expert Comment

by:Duncan Roe
ID: 39197237
The posts above assume that May 25th was yesterday (that's what the -1 means). Since you mention rm -rf I assume you want to remove all files anywhere in the tree that were created on 25th May. (As an aside, Linux doesn't track create times, but it does track inode change times which is close. That's what -ctime gives you and as well as file creation it is changed by renaming or moving the file (with mv command)). This command finds by absolute date: find . -type f -newerct 2013-05-25 -not -newerct 2013-05-26. Because it is looking for a newer file, it does not find files modified at exactly 00:00:00 on 25th May - you would need to use '2013-05-24 23:59:59' and '2013-05-25 23:59:59' for that. Assuming you don't need that level of precision, do
find . -type f -newerct 2013-05-25 -not -newerct 2013-05-26 -ls
to see the files you are going to remove, then actually do it
find . -type f -newerct 2013-05-25 -not -newerct 2013-05-26 | xargs rm -f -v
The -v is optional - thought you might like to see the files being removed
0
 
LVL 34

Expert Comment

by:Duncan Roe
ID: 39197238
To only remove files in the current directory
find . -type f -maxdepth 1 -newerct 2013-05-25 -not -newerct 2013-05-26 | xargs rm -f -v
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 19

Expert Comment

by:simon3270
ID: 39198075
I assume you've spotted that the main directory (the "." entry in the listing) was modified on May 25, so all files in that directory will have been forcibly and recursively removed. (yes, I know that "rm -rf ." will usually fail, put if a path is given, it will succeed)

If you aren't removing a directory, don't use "-r" on the rm command, and only use "-f" if you really need to.  Some people always use "rm -rf" even to remove single files that they own, unaware of the dangers.  It's the same mentatlity whcih always uses "kill -9" when a simple "kill" wil suffice and has much safer results.
0
 
LVL 34

Expert Comment

by:Duncan Roe
ID: 39198185
-type f restricts to files only - directories will not be considered
0
 
LVL 19

Expert Comment

by:simon3270
ID: 39198571
And you hadn't used "-rf" anyway.  My fault for trying to follow two questions at once with similar answers.

My point is still valid, just not here!
0
 

Author Closing Comment

by:walkerdba
ID: 39219941
yes
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Currently, there is not an RPM package available under the RHEL/Fedora/CentOS distributions that gives you a quick and easy way to allow PHP to interface with Oracle. As a result, I have included a set of instructions on how to do this with minimal …
This is the error message I got (CODE) Error caused by incompatible libmp3lame 3.98-2 with ffmpeg I've googled this error message and found out sometimes it attaches this note "can be treated with downgrade libmp3lame to version 3.97 or 3.98" …
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

706 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now