i seriously do not recommend using "find" for this problem, as (as you know) it searches recursively...
i prefer the straightforward approach:
once i'm happy with that output:
This is using some of the ideas also offered above. Primarily, the idea that you are able to check your work (multiple times) before running the final 'rm' command.
oh... and you can add "| grep -v ^d" in that pipeline to avoid grabbing directories.
i seriously do not recommend using "find" for this problem, as (as you know) it searches recursively...
i prefer the straightforward approach:
I seriously recommend against recommending to not use find for this task .
find does not have to recurse into subdirectories if that is not desired. On GNU/Linux and *BSD systems, all finds support -maxdepth n. On systems that do not support that primary, the following gets the job done:
Your "straightforward approach" is actually more complicated, brittle, and error prone. In addition to all the reasons mentioned by agama in post #6, filenames with whitespace will not make it through intact.
grep/awk are misc text processing tools. find's primaries know what they're looking at. In my opinion, find is the right tool for the job.
he following are the files available in my directory
RSK_123_20141113_031500.txt
RSK_123_20141113_081500.txt
RSK_126_20141113_041500.txt
RSK_126_20141113_081800.txt
RSK_128_20141113_091600.txt
Here, "RSK" is file prefix and 123 is a code name and rest is just timestamp of the file when its... (7 Replies)
To delete log files content older than 30 days and append the lastest date log file date in the respective logs
I want to write a shell script that deletes all log files content older than 30 days and append the lastest log file date in the respective logs
This is my script
cd... (2 Replies)
let say i have list of file
PermissionsDirectoriesGroupSizeDateDirectory or file
drwx------2users4096Nov 2 19:51mailv
drwxr-s---35www 32768Jan 20 22:39public_htmlt
drwx------ 2 users 4096 Nov 2 19:51 mail
drwxr-s--- 35 www 32768 Jan 20 22:39 public_html
drwxr-s--- 35 www 32768 Jan... (3 Replies)
Hello,
I have several files in a specific directory.
A specific string in one file can occur in another files.
If this string is in other files. Then all the files in which this string occured should be deleted and only 1 file should remain with the string.
Example.
file1
ShortName "Blue... (2 Replies)
I've got a problem how to delete files from specific directory.
I don't want do it recursively but only in specific directory.
So, command like
find /home/dirname/ -mtime +8 -type f -exec rm {} \;
is not for me because this command will remove ifs files in
/home/dirname and all... (2 Replies)
There is a system logging a huge amount of data and we need to delete some of the older logs .I mean the files that are created before one week from today. Here is a listing of files that are sitting there:
/usr/WebSphere/AppServer/logs
# ls -l
-rw-r--r-- 1 root system 3740694 May... (5 Replies)
Hi all.
I have a database log file in which log data get appended to it daily. I want to do a automatic maintainence of this log by going through the log and deleting lines belonging to a certain date.
How should i do it? Please help. Thanks.
Example. To delete all lines prior to Jun... (4 Replies)
Hi all,
I want to remove the files from a folder whcih contain a specific text in it.
eg:
If i have the files like
xxxx.NAME.adadd.ajfaj.kjfha
agsg.NAME.dfshd.djsh.sdjhf
asgd.NAME2.sdhj.djhf.sjdhf
shdd.NAME2.dhse.tywe.eyio
How to remove the files which contain the pattern "NAME"... (3 Replies)
Hello,
I have these files in my directory.
ABC123 ABC12.sls.20080809111121
ABC233 ABC12.sls.20080403123212
ABC543 ABC12.sls.20080804231212
ABC323 ABC12.sls.20080809111232
ABC765 ABC12.sls.20080809112343
ABC654 ABC12.sls.20080809113133
I want to delete only files in first... (2 Replies)
i have a directory "ABC" with lots of old files and sub directories in it.
the issue now is i want to delete away files which are older than 15 days in "ABC" without deleting the files in the sub directories and without deleting the sub directory.
i tried using find command but it will drill down... (2 Replies)