Sponsored Content
Top Forums Shell Programming and Scripting Search for a file in specific directory Post 302365208 by jadoo_c2 on Monday 26th of October 2009 09:54:39 AM
Old 10-26-2009
Search for a file in specific directory

I have to search a file in a prticular directory. filename will be passed through command line. The directory may contain subdirectory.

i.e.
suppose directory in /u03/appl (it can hard coded in script). This directory may contain subdirectory.

$ scriptname.sh filename

output should be file name if it is there in directory tree.

i've tried some thing but didn't get success. Please help me out
below is code that i had tried

Code:
#!/bin/bash
echo $1
if test $# -eq 0 ; then
  echo usage: "${0##/*} [Dir name]"
  exit
fi
echo 'Search in directory /u03/appl for the $1'
for arg in $* ; do
  #if test -e $arg ; then
  files=$(ls -lR /u03/appl | grep '[^d]' | awk '{print $9}') # <=
  for file in $files ; do
    if [[ $1 = $file ]]
    then
      echo 'got it'
    else
      echo 'try again'
    fi
done
#echo $files
#fi
done
#End


Last edited by Franklin52; 10-26-2009 at 11:02 AM.. Reason: Please indent your code and use code tags!
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Linux shortcutkey to search specific file from a list of directory?!

Hi, I'm the new user of linux/unix. Can I ask that anybody know how to use the linux/unix shortcut key to search a specific file from a list of directory? For example, I know the file name that I want to search. But I forget which directory or location is my desired file put.Got any shortcut... (7 Replies)
Discussion started by: patrick87
7 Replies

2. UNIX for Dummies Questions & Answers

How to search all the files in a directory for a specific string

Hi Guys, I want to search the content of all the files (of a particular type like .txt) in a directory for a specific string pattern. Can anyone help me? Thanks (7 Replies)
Discussion started by: mwrg
7 Replies

3. UNIX for Advanced & Expert Users

allow user to use sudo cp on a specific directory and only a specific file

Is there a way to allow a user to use sudo cp on a specific directory and only a specific file? (6 Replies)
Discussion started by: cokedude
6 Replies

4. UNIX for Dummies Questions & Answers

How to search directory for specific file?

I am new to Unix scripting and would like some help. Here is my scenario: 1) I have a text files that contains two fields: file name and retention period in months: File1 36 file2 24 File3 12 2) The directory I am searching contains sequential files. 3) I need to be able to take the file name... (10 Replies)
Discussion started by: Mustafa19804
10 Replies

5. Shell Programming and Scripting

Urgent request to consider:Search specific name in a file and fetch specific entries

Hi all, I have 2 files, One file contain data like this FHIT CS CHRM1 PDE3A PDE3B HSP90AA1 PTK2 HTR1A ESR1 PARP1 PLA2G1B These names are mentioned in the second file(Please see attached second file) as # Drug_Target_X_Gene_Name:(Where X can be any number (1-1000) (1 Reply)
Discussion started by: manigrover
1 Replies

6. Shell Programming and Scripting

Search specific name in a file and fetch specific entries

Hi all, I have 2 files, One file contain data like this FHIT CS CHRM1 PDE3A PDE3B HSP90AA1 PTK2 HTR1A ESR1 PARP1 PLA2G1B These names are mentioned in the second file(Please see attached second file) as (7 Replies)
Discussion started by: manigrover
7 Replies

7. Shell Programming and Scripting

Change to directory and search some file in that directory in single command

I am trying to do the following task : export ENV=aaa export ENV_PATH=$(cd /apps | ls | grep $ENV) However, it's not working. What's the way to change to directory and search some file in that directory in single command Please help. (2 Replies)
Discussion started by: saurau
2 Replies

8. UNIX for Dummies Questions & Answers

Search for a specific String in a log file for a specific date range

Hi, I have log file which rolls out every second which is as this. HttpGenRequest - -<!--OXi dbPublish--> <created="2014-03-24 23:45:37" lastMsgId="" requestTime="0.0333"> <response request="getOutcomeDetails" code="114" message="Request found no matching data" debug="" provider="undefined"/>... (3 Replies)
Discussion started by: karthikprakash
3 Replies

9. Shell Programming and Scripting

Shell scripting-I need a script which should watch a directory for a file with specific directory

I need a script which should watch a directory for a file with specific directory. If it finds a file in directory, it should search for few specific keyword in the file. if the keyword exists, it should trim string from specific column. The file should be moved to another directory and the a... (8 Replies)
Discussion started by: akashdeepak
8 Replies

10. UNIX for Dummies Questions & Answers

How to search in specific directory using find?

Hi, Is there any way to use find command and search only specific subdirectories in a directory. for example /home/d1 /home/d2 /home/d3 i want to search in the following directories /home /home/d1 /home/d2 i do not want the find command to search the /home/d3 directory. (6 Replies)
Discussion started by: Little
6 Replies
aedir(5)							File Formats Manual							  aedir(5)

NAME
aedir - aegis directory structures DESCRIPTION
The project directory structure is dictated by aegis at the top level, but is completely under the project's control from various points below the top level. The project directory has the following contents project/ baseline/ aegis.conf ...project specific... test/ [0-9][0-9]/ t[0-9][0-9][0-9][0-9]a.sh t[0-9][0-9][0-9][0-9]m.sh history/ ...echo of baseline... delta.[0-9][0-9][0-9]/ ...echo of baseline... info/ state change/ [0-9]/ [0-9][0-9][0-9] The directory is structured in this way so that it is possible to pick an entire project up off the disk, and be confident that you got it all. The location of the root of this tree is configurable, and may even be changed during the life of a project. The contents of the baseline subdirectory, other than those given, are defined by the project, and not dictated by aegis. The contents of the delta.NNN directory, when it exists, are an image of the baseline directory. It is frequently linked with the base- line, rather than a copy of it; see the link_integration_directory field description in aepconf(5) for more information. The contents of the history contains the edit histories of the baseline directory, and is in all other ways an image of it. Note that baseline always contains the latest source; the history directory is just history. The actual files in the history directory tree will not always have names the same as those in the baseline; compare the methods used by SCCS and RCS. The contents of the baseline/test directory are the tests which are created by changes. Test histories are also stored in the history subdirectory. Tests are treated as project source. The edit histories are separated out to simplify the task of taking a "snapshot" of the source of a project, without airing all the dirty laundry. The baseline directory always contains the latest source, and so the history directory need not be readily accessible, because the build mechanism (something like make(1), but preferably better) does not need to know anything about it. Similarly for tests. The baseline/aegis.conf file is used to tell aegis everything else it needs to know about a project. See aepconf(5) for more information. This file is a source file of the project, and is treated in the same way as all source files. The name of this file is not mandatory. SEE ALSO
aenc(1) create a new change aenpr(1) create a new project aegis(5) aegis file format syntax aepconf(5) project configuration file format COPYRIGHT
aegis version 4.24.3.D001 Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Peter Miller The aegis program comes with ABSOLUTELY NO WARRANTY; for details use the 'aegis -VERSion License' command. This is free software and you are welcome to redistribute it under certain conditions; for details use the 'aegis -VERSion License' command. AUTHOR
Peter Miller E-Mail: millerp@canb.auug.org.au //* WWW: http://www.canb.auug.org.au/~millerp/ Reference Manual Aegis aedir(5)
All times are GMT -4. The time now is 11:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy