Solved

delete file

Posted on 2013-05-25
8
285 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 28

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
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 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.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

910 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

22 Experts available now in Live!

Get 1:1 Help Now