1

I have a downloader running (in perl) that tries to execute a mv system command.

The output from the mv

mv: cannot move `./PMC5318673/EXCLI-15-758.pdf' to `/directory/EXCLI-15-758.pdf': No space left on device

There is space on the drive but I believe that this folder has used up all it's inodes.

so the solution that we came up with is to delete the oldest file in the directory and attempt to move the file there, and if there is still no space to do the mv delete the next oldest file.

I need a system command that is quick to run. (ls takes forever, since there's probably millions of files or more ??) that can delete the oldest file. As well it seems like that the files might be in sub-folders sometimes.

As well, If you can think of a different idea than deleting the oldest files please let me know.

0
3

In zsh:

rm -- **/*(.om[-1])

(or from a different shell: zsh -c 'rm -- **/*(.om[-1])')

which means:

  1. **/* gather files recursively

  2. ( ... ) is a zsh glob qualifier

  3. . means only consider "plain" files (not directories, etc)

  4. om means order them by modification time

  5. -1 means select only the oldest file

Credit to Gilles' answer here for the inspiration

1

delete the oldest file

find . -name '*some-pattern*' -type f -printf '%T+ %p\n' | sort | head -n1 | awk '{print $2}' | xargs rm -v

the purpose of -name '*some_pattern*' here is to restrict the matches only to files you want to be deleted

2
  • how long will the sort take? there's millions of files.
    – yankel
    Apr 2 '17 at 9:19
  • @yankel just run the command but leave off the xargs rm bit, that will tell you how long it will take Apr 2 '17 at 9:24
1

Someone answered the question and then deleted their answer, but I used the answer they gave.

find /path -mtime +1000 -exec rm -rf {} \;

This would delete files older than 1000 days.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.