Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does `[ -f ... ]` mean?

Tags:

shell

unix

Just want to know what is the below command do, or what -f means

if [ -f ${PDFFOLDER}/*.pdf ]; then
  rm ${PDFFOLDER}/*.pdf
fi
like image 220
John Paul Avatar asked Dec 30 '25 21:12

John Paul


1 Answers

Since [ ] and test aree the same command, the expressions within [ ] can be found in man test:

NAME
       test - check file types and compare values

SYNOPSIS
       test EXPRESSION
       test

       [ EXPRESSION ]
       [ ]
       [ OPTION

And there you also see:

-f FILE

FILE exists and is a regular file

So if [ -f "$file" ]; then... means: if the file $file exists and is a regular file (that is, not a directory or device file), then do whatever.

like image 132
fedorqui 'SO stop harming' Avatar answered Jan 05 '26 18:01

fedorqui 'SO stop harming'



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!