Finding DIR


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding DIR
# 1  
Old 03-18-2013
Finding DIR

Done this basic level script called mydir that prints the message File is a directory if
the file is a directory.


Code:

Code:
#!/bin/kasha
 
cat LIST | while read LINE
do
  if [[ $? -eq 0 ]]
  then
    ls -ltr $LINE >out
    give=$LINE
    grep $1 out > out.txt
    grep ^d out.txt
    if [[ $? -eq 0 ]]
    then
      echo "Directory "$give
    if
  if
done

Code:
LIST file Contains Directory path
/dir/man
/dir/con
/dir/sam

If you have any better way to find plz post...

Last edited by Scott; 03-18-2013 at 02:35 PM.. Reason: Removed excessive font-formatting
# 2  
Old 03-18-2013
Please, can you clarify? You have a list of directories. You want a script that receive a name as argument. If exists in one of directories in list a directory with the name in paremeter echoes a message.
Is this what you want?
# 3  
Old 03-18-2013
Yes Franzpizzo ...you are correct

The script is working. But we need to specify the directory names in the LIST(file)..

If i want to search from root ?
# 4  
Old 03-18-2013
You can get rid of the useless cat:

Code:
while read ...
do
...
done < inputfile

# 5  
Old 03-19-2013
Ok Corona..But i need to specify the directory names in the LIST(file) to search..

Instead, i want to search the directory from root "/" to all the child tables. Post if any
# 6  
Old 03-19-2013
What do you mean by 'all the child tables'?

Code:
for DIR in /*
do
        [ -d "$DIR" ] || continue

        echo "$DIR is a dir"
done

# 7  
Old 03-19-2013
I mean Child Directorys....

Ya the above script will check each and every file from /*.

But im passing the directory name as a argument and checking weather it is a File or a directory.
LIKE:
./file directoryname

How this should be done ?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Assign read write permission to the user for specific dir and it's sub dir and files in AIX

I have searched this quite a long time but couldn't find the right method for me to use. I need to assign read write permission to the user for specific directories and it's sub directories and files. I do not want to use ACL. I do not want to assign user the same group of that directories too.... (0 Replies)
Discussion started by: blinkingdan
0 Replies

2. Shell Programming and Scripting

Finding latest file in dir but getting syntax errors

I believe there are couple of syntax issues in my script, couldn't find them :( can someone help me with fixing it to make it work. cd /abcde/ #get the latest filename excluding subdirs filename=`ls -ltr | grep ^- | tail -1 | awk '{print $8}'` #get system date and file timestamp and... (3 Replies)
Discussion started by: simpltyansh
3 Replies

3. UNIX for Beginners Questions & Answers

Finding Files with Perl on a Hidden Dir?

Greetings! Been a while since I futzed around with Perl, and came upon a minor headscratcher for the community ;) Here's the basic code which I'm trying to make tick over:#!/usr/bin/perl use strict; use warnings; use diagnostics; print " starting "; while (-e "~/.somedir/testFile")... (9 Replies)
Discussion started by: LinQ
9 Replies

4. UNIX for Dummies Questions & Answers

Finding latest dir based on it's name (yyyymmdd)

Hi Folks, As part of my application I need to find out what the latest directory based on the name of that directory (not it's file system timestamp). Example: I have a directory which contains below directories (each of while contains files etc) 20120000/ 20120000/ latest (symbolic link to... (5 Replies)
Discussion started by: DOWD_R
5 Replies

5. Shell Programming and Scripting

KSH - Find paths of multiple files in CC (dir and sub-dir))

Dear Members, I have a list of xml files like abc.xml.table prq.xml.table ... .. . in a txt file. Now I have to search the file(s) in all directories and sub-directories and print the full path of file in a output txt file. Please help me with the script or command to do so. ... (11 Replies)
Discussion started by: Yoodit
11 Replies

6. Shell Programming and Scripting

Finding the Latest file in a Dir

Hi Everyone, I am writing a shell script and I am struck here: I need to find the latest file in a directory depending upon the date. For example: The files in the directory are: Filename_bo_20110619 Filename_bo_20110620 Filename_bo_20110621 Filename_bo_20110622 So here, I want... (2 Replies)
Discussion started by: filter
2 Replies

7. UNIX for Dummies Questions & Answers

How to list all files in dir and sub-dir's recursively along with file size?

I am very new to unix as well as shell scripting. I have to write a script for the following requirement. In have to list all the files in directory and its sub directories along with file path and size of the file Please help me in this regard and many thanks in advance. (3 Replies)
Discussion started by: nmakkena
3 Replies

8. Shell Programming and Scripting

A script to find dir, delete files in, and then del dir?

Hello!! I have directories from 2008, with files in them. I want to create a script that will find the directoried from 2008 (example directory: drwxr-xr-x 2 isplan users 1024 Nov 21 2008 FILES_112108), delete the files within those directories and then delete the directories... (3 Replies)
Discussion started by: bigben1220
3 Replies

9. Shell Programming and Scripting

a script to clone a dir tree, & overwrite the dir struct elsewhere?

hi all, i'm looking for a bash or tcsh script that will clone an empty dir tree 'over' another tree ... specifically, i'd like to: (1) specify a src directory (2) list the directory tree/hiearchy beneath that src dir, w/o files -- just the dirs (3) clone that same, empty dir hierarchy to... (2 Replies)
Discussion started by: OpenMacNews
2 Replies

10. UNIX for Dummies Questions & Answers

Finding current working dir path

Hi Folks, In a Unix (ksh) script, is there a way to determine the current working directory path of another logged-in user? Of course, I can use "pwd" to find my own path. But, how do I find it for another active user? Thanks for any input you can provide. LY (6 Replies)
Discussion started by: liteyear18
6 Replies
Login or Register to Ask a Question