Tag Info

New answers tagged

1

If you understand C programming language, I think it is possible to rewrite the rm source code and make a little patch for kernel. I saw this on one server and it was imposible to delete some important directoryes and when you type 'rm -rf /direcotyr' it send email to sysadmin.


0

In any case I'd stop working on the device being used as soon as possible to avoid any disk writes, and boot into a dedicated recovery OS, like SystemRescueCd, which is a Live-CD so you can mount your disk read-only in order to prevent further data loss. Those distros include a lot of recovery tools mentioned by others, and you can install most missing. I ...


2

String interpolation causes this. There are a number of ways to selectively prevent this from happening. The bash hackers wiki has some good examples, though the specifics may vary if you're not actually using bash. In short, you can prevent interpolation with single quotes, or you can escape the characters. [me:~/work]$ export foo=bar [me:~/work]$ echo ...


2

Going through lib/quotearg.c in the coreutils source reveals that the quoting is dependent on your locale setting. In my Linux Mint 17 (en_GB.UTF-8) I have both left and right quote the same (‘) whereas a system with en_US.UTF-8 as locales have backquote before (left-of) the filename. This article has some background


5

Option -0 of xargs means that output from pipe is interpreted as null terminated items. In such case you also need to create input for the pipe with find ... -print0.


6

Simple use: find . -size +1M -delete If you insist using xargs and rm with find, just add -print0 in your command: find . -size +1M -print0 | xargs -r0 rm -- Other way: find . -size +1M -execdir rm -- {} + From man find: -print0 True; print the full file name on the standard output, followed by a null character (instead of the newline ...


0

The problem here is that the stdin (the standard input) for the command ran from xargs (in this case rm) is redirected from /dev/null, and the stdin is the file descriptor used by rm to obtain the user's confirmation. You could use the -a option so that rm obtain the list of files from an intermediate file previously generated by the find command (the -a ...


2

xargs reads data from stdin. When you use rm -i rm also tries to read the answer from stdin (try touch test && echo y | r -i test ; ls test) but stdin is closed by xargs (I assume) so rm reacts as if you had pressed ctrl-d at the prompt. Another solution might be find's -exec option: touch test find . -name test -exec rm -i {} \;


0

You would be much better off using tmpwatch tmpwatch recursively removes files which haven't been accessed for a given time. Normally, it's used to clean up directories which are used for temporary holding space such as /tmp.


1

If you use the -prune option as suggested in this answer, the error message doesn't occur. Quoting from the above answer, Use -prune on the directories that you're going to delete anyway to tell find not to bother trying to find files in them. Testing mkdir koko cd koko touch file{1,2} cd .. find . -type d -name "koko" -prune -exec rm -rf {} \; ...


1

The problem is that find has found a directory, it matches your selection and then the command is executed. However, find wants to do what comes naturally, and that's recursing through a directory tree, but the directory it's just found has disappeared! Hence the error message. You can work around this by supplying the --depth option, which means process ...


0

Sorry to write this as an answer, I can't comment yet. I'll be interested to see what the fsck turns up. If you create another hard link to the file, does that hard link have the same problem? At least then you can rule out issues with the file reference...


0

Below python script does the job, days from on which the files should be deleted can be configured with days variable. #!/usr/bin/env python3 import os import re import datetime days=60 delta = datetime.date.today() - datetime.timedelta(days=days) files = [ x for x in os.listdir() if re.search('_\d{8}\.', x)] for file in files: date = ...


2

OK, I have remade this script, and by sorting it backwards it looks like it should work. It compares the year and month to the previous one, and if it is lower it should be the last entry for that month. #!/bin/bash #the tac reverses the listing, so we go from newest to oldest, vital for our logic below FILES=`ls | tac` #create a cutoff date by taking ...


0

You can try this in while loop: #!/bin/bash A=vtm_data_12month_20140301.txt B=`ls vtm_data_12month_20140301.txt | awk -F "_" '{print $4}' | awk -F "." '{print $1}'` C=`date --date="60 days ago" +%Y%m%d` if [ "$B" < "$C" ] then rm -fr $A else echo "$A is not older" fi


0

The following code does not preserve the last file of each month. #! /bin/bash cmp_timestamp=$(date --date="60 days ago" +%Y%m%d) while read filename; do [[ $filename =~ _(20[0-9][0-9][01][0-9][0123][0-9])\. ]] timestamp=${BASH_REMATCH[1]} printf "%-40s : %s\n" "$filename" "${timestamp}" if [ "$timestamp" -lt ...


-2

find . -name -mtime +0.5 -print -delete is another option to delete large number of files quickly.



Top 50 recent answers are included