Search file in a unix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search file in a unix
# 1  
Old 03-26-2012
Search file in a unix

Hi All,

There is one file in one of the directory in my Unix. I don't remember the file name and location exactly, But i have some what idea about the file name.

Is it possible that the Unix can search that file in all directories and if any of the file name resemble that name i have given should display it
# 2  
Old 03-26-2012
find

Yes, You can use find in unix.

Code:
find . -name "PartOfFileName"

For More Information, just do the below in your unix terminal.
Code:
man find

Cheers,
RangaSmilie
# 3  
Old 03-26-2012
search file in a unix

Hi,

You can use find command ,

Code:
find `pwd` -name "partoffilename"

if you need to get the full path means you can use this

cheers,
shanmu
# 4  
Old 03-26-2012
For the above commands you need to change "partoffilename" to "*partoffilename*"
# 5  
Old 03-26-2012
Hi.

For files that have been around for some time, I usually try locate first:
Code:
#!/usr/bin/env bash

# @(#) s1	Demonstrate finding files via "locate", "updatedb".

pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && $C locate 

pe
locate 968.tar

exit 0

producing:
Code:
% ./s1

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: FreeBSD, 8.0-RELEASE, i386
bash GNU bash 4.0.33
locate - ( /usr/bin/locate, Nov 21 08:56:25 2009 )

/usr/home/drl/968.tar

Noting, however:
Code:
     The locate program may fail to list some files that are present, or may
     list files that have been removed from the system.  This is because
     locate only reports files that are present in the database, which is typ-
     ically only regenerated once a week by the
     /etc/periodic/weekly/310.locate script.  Use find(1) to locate files that
     are of a more transitory nature.

-- excerpt from man locate, q.v.

On GNU/Linux, the command updatedb can be used by root to refresh the database.

Best wishes ... cheers, drl
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search a string in a file which is also present in another file in UNIX

Hi there, I am new to Unix and had below requirement to finish my task. I have file1.dat which has data as shown below. case1.txt case2.txt case3.txt case4.txt file1.dat has only file names I have folder which has above files mentioned in file1.dat ./all_files case1.txt... (6 Replies)
Discussion started by: raj028
6 Replies

2. Shell Programming and Scripting

UNIX Scripting help to input string and search a file to find

Hi Don, this is not homework question. I work for a Credit card company and my development goal this year is to learn Unix. I would love if others can help me get started, thanks. Hi everyone I am new to Unix and need help writing a script that can ask user for an input, then search that input... (2 Replies)
Discussion started by: 12ic11
2 Replies

3. Shell Programming and Scripting

UNIX Scripting help to input string and search a file to find

Hi everyone, I am new to Unix and need help writing a script that can ask user for an input, then search that input within a file I know will have to use the read and grep commands, anyone can give me somewhere to start would help Task: Write a script to display which volume pool a given... (1 Reply)
Discussion started by: 12ic11
1 Replies

4. UNIX for Dummies Questions & Answers

UNIX Scripting help to input string and search a file to find

Hi everyone, I am new to Unix and need help writing a script that can ask user for an input, then search that input within a file I know will have to use the read and grep commands, anyone can give me somewhere to start would help Task: Write a script to display... (1 Reply)
Discussion started by: 12ic11
1 Replies

5. Shell Programming and Scripting

UNIX shell script to search a string in a file

Hi folks, I am new for shell script, I hope somebody to help me to write shell script My requirement is below steps 1. I have apache access.log i.e located in /var/log/httpd/ Ex. 127.0.0.1 - - "GET... (14 Replies)
Discussion started by: Chenchireddy
14 Replies

6. Shell Programming and Scripting

UNIX: Search file between two Date stamps

Hi, I have a requirement to find a file based on date stamp provided by user. In one of the shared location I get data file say “datafile<dataformat>“. And User will provide the date based on which I need to select a file which is 7 days older, if a file not present within 7 days, then I need... (3 Replies)
Discussion started by: santhosh86467
3 Replies

7. Shell Programming and Scripting

How to search and append words in the same file using unix scripting file operations

Hi , I have a file myhost.txt which contains below, 127.0.0.1 localhost 1.17.1.5 atrpx958 11.17.10.11 atrpx958zone nsybhost I need to append words only after "atrpx958" like 'myhost' and 'libhost' and not after atrpx958zone. How to search the word atrpx958(which is hostname) only,... (5 Replies)
Discussion started by: gsreeni
5 Replies

8. Shell Programming and Scripting

Need help in retrieving log from a UNIX file using the search patterns

Hi everyone, I am trying to retrieve certain log from a big file. The log size can be from 200 - 600 lines. I have 3 search patterns, out of which 2 (first and last lines) search patterns are common for all the transactions but 3rd search pattern (occurs in the middle of transaction) is... (5 Replies)
Discussion started by: msrayudu
5 Replies

9. Shell Programming and Scripting

Unix script to search within a .tar or .gz file

HI, I want to get few line from the file which is in .gz file. .gz file contains many txt files and I want to search a string in all these txt files and need to get the previous 3 line as output including current line(where search string present). I tried the zgrep and got the line number,... (5 Replies)
Discussion started by: sateesh512
5 Replies

10. UNIX for Dummies Questions & Answers

Unix search a string in the text file

File name : Sample.txt Actually i would like to read <schema>Oracle<schema> string from input file and return only once database as my output. Please advise me. Moved to appropriate forum. (1 Reply)
Discussion started by: balajikalai
1 Replies
Login or Register to Ask a Question