identify whether idrectory or ordinary file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting identify whether idrectory or ordinary file
# 1  
Old 11-05-2005
identify whether idrectory or ordinary file

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?
# 2  
Old 11-05-2005
Within a script, it would look like this

Code:
if [ -d /home/surjyap ] ; then
echo " /home/surjyap" is a directory
elif [ -f /home/surjyap ] ; then
echo "/home/surjyap is file"
fi ;

Vino
# 3  
Old 11-05-2005
no not by using if. is there any other command or technique available?
# 4  
Old 11-05-2005
Quote:
Originally Posted by surjyap
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.

Code:
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

Code:
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
# 5  
Old 11-05-2005
man file
man stat
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare large file and identify difference in separate file

I have a very large system generated file containing around 500K rows size 100MB like following HOME|ALICE STREET|3||NEW LISTING HOME|NEWPORT STREET|1||NEW LISTING HOME|KING STREET|5||NEW LISTING HOME|WINSOME AVENUE|4||MODIFICATION CAR|TOYOTA|4||NEW LISTING CAR|FORD|4||NEW... (9 Replies)
Discussion started by: jubaier
9 Replies

2. Shell Programming and Scripting

wanted to find both link file and ordinary file using single find command

find . -type fl o/p is only the ordinary file. where in it wont give the link files. (2 Replies)
Discussion started by: nikhil jain
2 Replies

3. UNIX for Dummies Questions & Answers

How to give an ordinary user the superuser (root) ID which is 0

How to give an ordinary user the superuser (root) ID which is 0 (9 Replies)
Discussion started by: sharaola
9 Replies

4. Linux

grant root privileges to ordinary user

Hi, Is it possible to grant root privileges to an ordinary user? Other than 'sudo', is there some way under Users/Groups configuration? I want ordinary user to be able to mount, umount and use command mt. /Brendan (4 Replies)
Discussion started by: brendan76
4 Replies

5. AIX

[Help] Give privilege to an ordinary user

I'm trying to give a non-root user the right to start IBM HTTP Server, the web server is listening on port 80, but for AIX, ports under 1024 are privilege ports which can be used only by root. /usr/IBMIHS/bin# ./apachectl start (13)Permission denied: make_sock: could not bind to address :::80... (1 Reply)
Discussion started by: ibmer414
1 Replies

6. HP-UX

heads up unable tp login using ordinary account

Hi Mentors, I have a unix box HPC8000 HPUX 11.11 had just a problem loging in on CDE using ordinary account. The problem looks like this when an ordinary account will login to it will automatically closed and the login promtp will appear. If the root will login no problem at all. I tried... (0 Replies)
Discussion started by: eykyn17
0 Replies

7. Shell Programming and Scripting

Identify type of file

hi all, i have the next question: how can i identify the type of a file? . I'm working in Unix (Solaris 5.7) and i would like identify if a file is or not is a "flat file". I need have a program what separates the flat file in a directory, and the excel file in another directory. I must get... (1 Reply)
Discussion started by: DebianJ
1 Replies

8. IP Networking

problem using rsh for ordinary users!

Hello, I'm going to use the remote tape via rsh , I think that all the necessary process have been done as below: (suppose the machine name that want to use tape is : m1 & the source machine is: m2 ) 1-in m2 machine i add: + m1 in .rhosts... (8 Replies)
Discussion started by: nikk
8 Replies

9. UNIX for Dummies Questions & Answers

Newbie question about difference between executable file and ordinary file

Hi, I am newbie in unix and just started learning it. I want to know what is the difference between an executable file and a file (say text file). How to create executable file? What is the extension for that? How to differentiate ? How does it get executed? Thanks (1 Reply)
Discussion started by: Balaji
1 Replies
Login or Register to Ask a Question