The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Identify type of file DebianJ Shell Programming and Scripting 1 11-17-2005 11:55 AM
"File in use" - how to identify locks on this file and release them? vadimsf UNIX for Dummies Questions & Answers 1 09-05-2003 03:10 PM
problem using rsh for ordinary users! nikk IP Networking 8 11-05-2001 08:17 AM
Newbie question about difference between executable file and ordinary file Balaji UNIX for Dummies Questions & Answers 1 11-29-2000 06:49 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-05-2005
surjyap surjyap is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 40
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 (permalink)  
Old 11-05-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
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 (permalink)  
Old 11-05-2005
surjyap surjyap is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 40
no not by using if. is there any other command or technique available?
  #4 (permalink)  
Old 11-05-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
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 (permalink)  
Old 11-05-2005
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,211
man file
man stat
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:22 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0