Search code examples
linuxbashshellfind

Using printf in "find" command


With the following command, I want to find a specific file name, print its name and then compress it in-place with bzip2 command. The compression works but file name is not printed.

$ find . -name *.sb.* -printf "%f\n" | xargs bzip2
$ ls
foo.sb.txt.bzip2
$

How can I fix that?


Solution

  • I suggest you to replace your command with:

    find . -name "*.sb.*" -print -exec bzip2 {} \;