Hi.
Maybe I'm not seeing something, but I'm wondering about the syntax of this command:
What I'm wondering is, 1: why use grep when you can simply include the wildcard in the original 'ls' command. And 2: Why use a temporary file at all?
I use Acronis, so I've used a directory of ".tib" files as an example.
I would do this:
(note -l is redundant when using -1)
This lists the files to be deleted, one per line.
All we need to do is delete these files, right?
This will run "rm -f " on every file returned by the "ls | tail" pipe.
Not actually tested on my files, as Acronis rotates old backups for me. But I tested this one:
Which properly "ls'd" the files to be deleted.
Anyway, that's how I would do it. The beauty of *nix (linux, unix, bsd, etc). There's more than one way to do it.
Maybe I'm not seeing something, but I'm wondering about the syntax of this command:
Code:
ls -ltd1 /mnt/tank/Backups/Desktop/* | grep ".*\.omg" | tail +3 > /tmp/list && xargs rm < /tmp/list
What I'm wondering is, 1: why use grep when you can simply include the wildcard in the original 'ls' command. And 2: Why use a temporary file at all?
I use Acronis, so I've used a directory of ".tib" files as an example.
I would do this:
Code:
ls -td1 /mnt/backup/somewhere/*.tib | tail +3
(note -l is redundant when using -1)
This lists the files to be deleted, one per line.
All we need to do is delete these files, right?
Code:
rm -f `ls -td1 /mnt/backup/somewhere/*.tib | tail +3`
This will run "rm -f " on every file returned by the "ls | tail" pipe.
Not actually tested on my files, as Acronis rotates old backups for me. But I tested this one:
Code:
ls -l `ls -td1 /mnt/backup/somewhere/*.tib | tail +3`
Which properly "ls'd" the files to be deleted.
Anyway, that's how I would do it. The beauty of *nix (linux, unix, bsd, etc). There's more than one way to do it.