B
B
brunot2016-01-19 21:14:49
linux
brunot, 2016-01-19 21:14:49

How to bulk delete files by name?

In general, there is a list that shows the full paths to the files:
example:
uploads/posts/2012-02/samurai-samourai-le.jpg
uploads/posts/2012-02/dva.jpg
uploads/posts/2012-02/ teoriya-zapoya.jpg
All these files should be deleted.
Because in puff is not strong, the question is: is there a command to perform a similar function in Linux?

Answer the question

In order to leave comments, you need to log in

7 answer(s)
O
oldbro, 2016-01-19
@brunot

xargs rm < список.txt
PS Before executing, do not forget to go to the directory where the uploads directory is located or the list should consist of absolute paths to files.

S
shamyyl, 2016-01-19
@shamyyl

rm <путь к файлу>

S
Sergei E., 2016-01-19
@SmartFinn

#!/bin/bash

while read filepath; do
    rm -fv "$filepath"
done < path/to/filelist.txt

or edit the list itself and turn it into a script by adding rm to each line before the file path.

D
Dmitry Chervonobab, 2016-01-19
@maddimons

rm -R -f .../2012-*
-R recursion- kill directory by mask.
-f will not ask, everything will crash right away.

A
abs0lut, 2016-01-19
@abs0lut

find . -name '*.jpg' -delete
and what's with the puff?

P
planc, 2016-01-20
@planc

>Because I’m not strong in puff, the question
is, how about Linux has already been answered, if necessary in PHP then:

<?php    
    
$lines = file('1.txt');    
    
array_map(function($l) {
        unlink(trim($l));
        }                                                     
   , $lines);

A
abcd0x00, 2016-01-20
@abcd0x00

If there are no spaces in the paths, then
If there are spaces, then
cat file.txt | while read f; do rm -f "$f"; done

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question