Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

short way to check (one liner) if a file exists or not

I’m looking for a very short way to check if a file exists or not. If the file exists 1 should be printed and if not 0 should be printed.

The below syntax doesn’t print anything? Just an empty output

if [ -f /proc/$pid/stat ]; then echo '1' else echo '0' fi

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

[ -f file ] && echo 1 || echo 0

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading