Need help in writing script for finding files in the unix machine?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help in writing script for finding files in the unix machine?
# 1  
Old 10-03-2008
Need help in writing script for finding files in the unix machine?

I would like to find whether a file exists in the UNIX machine. That i can check using

if [-f $file];then
echo "exists"
echo " `cat $file` "
else
echo "invalid file"
fi.

and i can find out using :
find / -name "filename" . But it i have wanted to search in all directories. How to get this???

Please suggest.
# 2  
Old 10-03-2008
Hammer & Screwdriver Is this what you are looking for?

I often use a filename called file1 when testing things. So, it ends up in many of my subdirectories.

Code:
[ ~/tmp ] > find . -name file1
./file_lookup/file1
./sort_stuff/file1
./sort_stuff/moved/file1
./verify_format/file1
./edit_text/file1
./text_manip/file1
./sep2files/file1
./unique/file1
./repl_list/file1
./header_ins/file1
./fixed_data/file1
./join_lines/file1
./add_files/file1
./math/file1
./3rec_types/file1
./copy_archive/file1
./concat_files/file1
./extract_data/file1
./remove_lines/file1
./co_loop/file1
./complex_select/file1
./combine_common/file1
./awk_do_something_next/file1

If you want to search your entire system, try the following:
Code:
> find / -name file1 2>/dev/null

The 2>/dev/null is to redirect all the possible errors from the system telling you that you do not have rights to read certain directories. This just makes the output 'cleaner' to read. And, go grab a cup of coffee as this search may take a few minutes, or more.
# 3  
Old 01-21-2009
How to change the format

Hi,

Will you please help me if i want the file having extension .txt will come in the format below and stored in a particular file

Example:

Path:/ap06/cfc/hyperion

-rw-rw---- 1 cfahyp cfghyp 7263 Jan 21 20:17 k1.txt
-rw-rw---- 1 cfahyp cffhyp 7263 Jan 21 20:17 k2.txt
-rw-rw---- 1 cfdhyp cfchyp 7263 Jan 21 20:17 k3.txt

Can you help me out.


I have given

find . -name "*.txt" | cat >> k1.txt --------- command

i gives the files in k1.txt file.

Please help.Thanks in Advance.

-- Kaash
# 4  
Old 01-22-2009
dear kaash,

We appreciate your presentation of the question . but we expect more details of your requirement .

BTW find will search any type of file , irrespective of it's extension , by adding key word -type f , if want more particular result then add key word -name (as you did).

Please write the question from the reader's prospective , simple and understandable , as he has to understand the problem from the writer's prospective and will try to provide you the solution(faster/delay) based on your query.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding total distinct count from multiple csv files through UNIX script

Hi All , I have multiple pipe delimited csv files are present in a directory.I need to find out distinct count on a column on those files and need the total distinct count on all files. We can't merge all the files here as file size are huge in millions.I have tried in below way for each... (9 Replies)
Discussion started by: STCET22
9 Replies

2. Shell Programming and Scripting

How to transfer files from unix machine to local machine using shell script?

Hi All.. Am new to Unix!! Am creating a shell script in which a scenario is like i have transfer the output file from unix machine (Server) to local directory (Windows xp). And also i have to transfer the input file from the local directory to Unix machine (Server) Any help from you... (1 Reply)
Discussion started by: vidhyaS
1 Replies

3. Shell Programming and Scripting

shell script to copy files frm a linux machine to a windows machine using SCP

I need a shell script to copy files frm a linux machine to a windows machine using SCP. The files keeps changing day-to-day. I have to copy the latest file to the windows machine frm the linux machine. for example :In Linux, On July 20, the file name will be 20.txt and it should be copied to... (3 Replies)
Discussion started by: nithin6034
3 Replies

4. Shell Programming and Scripting

ftp from windows to unix using a perl script on unix machine

i need to ftp a file from windows to a unix machine by executing a sript(perl/shell/php) from that unix machine.i can also use HTML and javascript to build forms. (3 Replies)
Discussion started by: raksha.s
3 Replies

5. Shell Programming and Scripting

need help writing this unix script

Create an executable script file called "newname" that will perform the followings: 1. Rename a file upon the user's request. If the file exists, prompt the user for confirmation before renaming the file. The screen should prompt the user for a. "Name of file you want to rename." Use the "\c"... (7 Replies)
Discussion started by: wiggles
7 Replies

6. Shell Programming and Scripting

help writing this unix script

I am working on writing scripts. Here is a script I need help with. I have also wrote what I think it is. I would really appreciate any help that I can get. Create an executable script file called "newname" that will perform the followings: 1. Rename a file upon the user's request. If the... (2 Replies)
Discussion started by: wiggles
2 Replies

7. Shell Programming and Scripting

writing script in UNIX for copying files in two server

can anyone help me in writing script in UNIX for copying files in two server from the third server after checking the files in the third server and if there is anything new in the third server automatically it should be added to the rest of the two servers and if same file is existing in the two... (4 Replies)
Discussion started by: REKHA09
4 Replies

8. Shell Programming and Scripting

Writing script for finding a string and replacing

Hi all i need some help in writing a small script that searches a string and then replaces it by a new string for searching the best result i get is from find comand combined with xargs e.g. find . -name "*.*" |xargs grep -l "search string" this command I use in root directory and this... (4 Replies)
Discussion started by: Aditya_IT
4 Replies

9. Filesystems, Disks and Memory

Writing files from Unix to 3480 Tape

I am trying to learn what command I would need to enter to tell my very old tape writer to write a large > 210 MB file from a UNIX box to 3480 tapes. I can get a single tape to write < 210 MB but if the file is large I am not aware of what command to enter to tell it to split the input file across... (0 Replies)
Discussion started by: james.hodge@eds
0 Replies

10. UNIX for Dummies Questions & Answers

Unix shell script for finding top ten files of maximum size

I need to write a Unix shell script which will list top 10 files in a directory tree on basis of size. i.e. first file should be the biggest in the whole directory and all its sub directories. Please suggest any ideas (10 Replies)
Discussion started by: abhilashnair
10 Replies
Login or Register to Ask a Question