ls -l | awk '{if ($5 == 100) {print $8}}' | xargs rm
A short, simple, and sweet bash command for removing files of a certain size. In this case, the size is 100 bytes. This was something I needed today, so I thought I’d post it.
So what’s going on here? ls -l lists files in the current directory, and -l provides extra information (permissions, size, owner, date, etc…). The | then pipes that output to awk. $5 is referencing the 5th field outputted by ls -l, which in thise case, is the size. If $5 is a desired size, then output $8, which is the name of the file. The file names are then piped into xargs rm, which removes the files.
View Comments
blog comments powered by