Is there a file exists command in Ubuntu Terminal? [duplicate]

Is there somehow I can check if a file or folder exists in Ubuntu Terminal?


You can use the test command of the shell bash.

$ test -e ~/.bashrc && echo file exists || echo file not found
file exists
$ test -e ~/.bashrcx && echo file exists || echo file not found
file not found

The command

help test

prints a help text with the different options, that you can use with the test command.

You may also find the following help texts useful, as well as the links in a comment by @dessert,

help [

and

help [[

You can use the find command if you don't know where the file is (so that you must search for it in several directories) or you want to find different versions of the file.

$ sudo find / -name .bashrc
[sudo] password for sudodus: 
/etc/skel/.bashrc
/root/.bashrc
find: ”/run/user/1002/gvfs”: Permission denied
/media/multimed-2/test/test/2015-04/colour-prompt/home/guru/.bashrc
/media/multimed-2/test/test/2015-04/colour-prompt/root/.bashrc
/media/multimed-2/test/test/2015-04/colour-prompt/etc/skel/.bashrc
/media/multimed-2/rsync-bup/nio/.bashrc
/home/lfs/.bashrc
/home/myself/.bashrc
/home/nio/.bashrc
/home/sudodus/.bashrc