Solved

delete file

Posted on 2013-05-25
8
305 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 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VMware Workstation 12 Player 16 122
awk sed 8 65
SMB share across internet 15 65
trouble on installing syslog-ng on CentOS 7 7 54
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" …
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
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 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…

839 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