Delete multiple files on Linux?

How can I delete multiple files on Linux created at the same date and time? How can I manage this without using a date? The file has different names.

I have these .txt files:

-rw-r--r-- 1 root root        54 Jan  6 17:28 file1.txt
-rw-r--r-- 1 root root        33 Jan  6 17:28 file2.txt
-rw-r--r-- 1 root root        24 Jan  6 18:05 file3.txt
-rw-r--r-- 1 root root         0 Jan  6 17:28 file4.txt
-rw-r--r-- 1 root root         0 Jan  6 17:28 file5.txt

How to delete all files with a single command?

Thanks, advanced!

+4
source share
3 answers

just use rm -f file*.txtto delete all files that start with the file and end with the extension.txt

+2
source

You can use the find command and specify a time range. In your example: if you want to find all files with the changed timestamp from January 6, 17:28, you can do something like:

find . -type f -newermt '2016-01-06 17:28' ! -newermt '2016-01-06 17:29'

, exec exec:

find . -type f -newermt '2016-01-06 17:28' ! -newermt '2016-01-06 17:29' -exec rm {} \;

-name '*.txt', *.txt maxdepth,

+4

If you know the minutes of the modified file, you can delete all files with the command find. believe that the file was last modified ten minutes ago. Then you can use

find -iname "*.txt" -mmin 10 -ok rm {} \;

If you do not need to request before uninstalling, use -exec.

 find -iname "*.txt" -mmin 10 -exec rm {} \;

If you need to delete files using access time, you can use -amin

0
source

Source: https://habr.com/ru/post/1623232/


All Articles