What are the different ways to identify a given file is an ordinary file or a directory?
Yes we can do it by giving the command :
ls -l <filename>
What else?
What are the different ways to identify a given file is an ordinary file or a directory?
Yes we can do it by giving the command :
ls -l <filename>
What else?
Within a script, it would look like this
if [ -d /home/surjyap ] ; then
echo " /home/surjyap" is a directory
elif [ -f /home/surjyap ] ; then
echo "/home/surjyap is file"
fi ;
Vino
no not by using if. is there any other command or technique available?
Yes.
This one just popped out of my head. Very unconventional tho'...
Use rm
Look at the demo below.
sh-2.05b$ mkdir suryap
sh-2.05b$ ls -l
drwxr-xr-x 2 -------- g900 4096 Nov 5 01:58 suryap
sh-2.05b$ rm suryap/
rm: cannot remove `suryap': Is a directory
sh-2.05b$ rm -r suryap/
sh-2.05b$ ls -l suryap
ls: suryap: No such file or directory
sh-2.05b$ touch suryap
sh-2.05b$ ls -l
-rwxr-xr-x 2 -------- g900 4096 Nov 5 02:00 suryap
sh-2.05b$ rm suryap
sh-2.05b$ ls -l suryap
ls: suryap: No such file or directory
vino
man file
man stat