Delete files by extension. Delete files to display.
The first part of the assignment works, but how to add a conclusion to this?
find $1 -name "*.$2" -print0 | xargs -0r rm -- The easiest way is to add the -t switch to the -t utility. In this case, it will print the command being executed.
However, if this output format does not suit you, you can copy the output of the find utility to a temporary file. And then print its contents. For example,
tempfile=`mktemp` find "$1" -name "*.$2" -print0 | tee "${tempfile}" | xargs -0r rm -- cat "${tempfile}" | xargs -0ri echo "Файл '{}' был удалён" rm -- "${tempfile}" Good day!
if you simply output deleted files to a string, you can try this:
find $1 -name "*.$2" -print0 -delete or
find $1 -name "*.$2" -print0 -exec rm {} + The output will be something like this:
./1.txt./2.txt./3.txt Source: https://ru.stackoverflow.com/questions/634299/
All Articles