How to delete all files that were recently created in a directory on Linux?

I parsed something into a directory that already contains a lot of things. Instead, I wanted to break up into a separate directory. Now there are too many files to distinguish. However, the files that I unpacked were created just now (right?), And the source files were not changed for a long time (at least one day). Is there a way to delete only these raw files based on their creation information?

+5
source share
4 answers

Tar usually restores file timestamps, so time filtering is unlikely to work.

tar , , , :

tar tf file.tar --quoting-style=shell-always |xargs rm -i

, ( , , ), .

, -r, , , .

+6

. -mtime -1-type f | xargs rm

. -mtime -1-type f | xargs echo

+3

.

-, , , ( , , , Unicode). :

tar -tf file.tar | egrep '^(\./)?[^/]+(/)?$' | egrep -v '^\./$' | tr '\n' '\0' | xargs -0 rm -r

, egrepping - .

, , :

mkdir foodir
cd foodir
tar -xf ../file.tar
for file in *; do rm -rf ../"$file"; done

, , , . , ..

, ., :

mkdir foodir
cd foodir
tar -xf ../file.tar
find . -mindepth 1 -maxdepth 1 -print0 | xargs -0 sh -c 'for file in "$@"; do rm -rf ../"$file"; done' junk

, , , , :

tar -tf file.tar | egrep '^(\./)?[^/]+(/)?$' | grep -v '^\./$' | tr '\n' '\0' | xargs -0 bash -c 'for fname in "$@"; do fname="$(echo -ne "$fname")"; echo -n "$fname"; echo -ne "\0"; done' junk | xargs -0 rm -r
+1

:

tar  -tf ../test/bob.tar --quoting-style=shell-always | sed -e "s/^\(.*\/\)'$/rmdir \1'/; t; s/^\(.*\)$/rm \1/;" | sort | bash

, , bash '

tar  -tf ../test/bob.tar --quoting-style=shell-always | sed -e "s/^\(.*\/\)'$/rmdir \1'/; t; s/^\(.*\)$/rm \1/;" | sort

.

0

All Articles