Skip to main content

Thread: Bash one liner to rm files based on content


hi,

need either 1 liner or bash script recursively search folder/sub folders binary files (windows .lnk files) containing specific text string. if finds match must delete file.

after googling number of hours i've come accross below 1 liner.

why not work?

code:
find . -name '*.lnk' -print0 | xargs -0 grep -i "c:" | xargs -0 rm -f

quote posted john_spiral view post
hi,

need either 1 liner or bash script recursively search folder/sub folders binary files (windows .lnk files) containing specific text string. if finds match must delete file.

after googling number of hours i've come accross below 1 liner.

why not work?

code:
find . -name '*.lnk' -print0 | xargs -0 grep -i "c:" | xargs -0 rm -f
if run without last part, see why.

code:
find . -name '*.lnk' -print0 | xargs -0 grep -i "c:"
the output 'grep' not suitable input 'xargs'.


Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk Bash one liner to rm files based on content


Ubuntu

Comments