Solved

delete file

Posted on 2013-05-25
8
317 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
[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
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 29

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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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
 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

733 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