how to search directories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to search directories
# 1  
Old 02-25-2007
how to search directories

Hello everybody,
i'm dummy for unix but i want to learn something.
i want to search the working directory and its subdirectories( all ) to find the files which are more than 1024 bytes.
So which commands must i learn?
Thanks to all.
# 2  
Old 02-25-2007
Quote:
Originally Posted by redbeard_06
Hello everybody,
i'm dummy for unix but i want to learn something.
i want to search the working directory and its subdirectories( all ) to find the files which are more than 1024 bytes.
So which commands must i learn?
Thanks to all.
you can do that with the find command. here is what you could start off with.

Code:
 find . -size 2

the above code will find all the files starting from the current directory and all the sub directories. with the byte size closer to 1024 bytes {1 block = 512 bytes)
# 3  
Old 02-25-2007
find . -type f -size +1024c

find files of type "regular file" which are bigger than 1024 bytes
# 4  
Old 03-09-2007
Hi folks,
I was wondering if you could tell me how to use find to locate a file without knowing the directory of the file.

I tried using find . -name filename* but I had to ctrl+c after several minutes.

Would that have eventually worked (providing the file actually exists), or do you know of a better way to search?

Also, can you advise me how I could pipe the output to a .txt file?
Thanks!

Last edited by Kozmo; 03-09-2007 at 02:38 PM..
# 5  
Old 03-09-2007
Yes it would of enventually worked. Find searches all files in all directories and sub-directories

On HP-UX, you have to enclose your query between double quotes "file*" but on linux you do not when using wildcards.

On linux oses you can use locate which maintain an index of your files which will find them pretty much instantly (but you need to keep locate's database updated)

You should try to play with the command to learn is behavior, create yourself a test directory with subdirectories and file in them so you can different type of search

good luck !
# 6  
Old 03-09-2007
Thanks Snerge it worked perfectly!
Can you advise how I could pipe the output to a .log or .txt file?
I'll need to ftp these results as the list is over 5,000 hits long.
# 7  
Old 03-09-2007
Always a pleasure to help !

find . -name "file*" > ouput.txt

You can use the > file.txt syntax with pretty much any command ....

ls -al > result.txt
netstat -an > result.txt

so on ...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to use a grep search to search for a specific string within multiple directories?

Lets say I have a massive directory which is filled with other directories all filled with different c++ scripts and I want a listing of all the scripts that contain the string: "this string". Is there a way to use a grep search for that? I tried: grep -lr "this string" * but I do not... (3 Replies)
Discussion started by: Circuits
3 Replies

2. Shell Programming and Scripting

Recursive search for files and copy to new directories

So I have extremely limited experience with shell scripting and I was hoping someone could point out a few commands I need to use in order to pull this off with a shell script like BASH or whatnot (this is on OS X). I need to search out for filenames with account numbers in the name itself... (3 Replies)
Discussion started by: flyawaymike
3 Replies

3. Shell Programming and Scripting

Search for file extensions in the given directories

Hey guys, I'm lost... I need to make a script that will work in this way: ./script.sh -e sh /usr/bin /home/student this script will result in this output: amuFormat.sh /usr/bin gettext.sh /urs/bin perfect.sh /home/student the parameter -e <ext> gives you which... (2 Replies)
Discussion started by: Miki1579
2 Replies

4. UNIX for Advanced & Expert Users

Search file in all directories.

Hi colleagues, I need to search one file in all dierctories, i have O.S. AIX 5.3, my file began with cc, the others caracters i unknow. Then i can to search one string in file in all dierctories. Thank you for advanced. (8 Replies)
Discussion started by: systemoper
8 Replies

5. UNIX for Advanced & Expert Users

word search in multiple directories

need a Command in UNIX which can find out a word from files in multiple directories e.g. /home contains multiple directories /home/d1 /home/d2 . . . . /home/dn under d1,d2...dn contains multiple files. I need to search a specific word in a files under these multiple... (1 Reply)
Discussion started by: jagkoth
1 Replies

6. Shell Programming and Scripting

find restricted search to some directories

Hi, I would like to look for files in certain sub-directories in order to avoid looking into possibly big ones. The subdirectories to search are created monthly following the convention YYYYMM. I've tried this: find . \( ! -name 2 -prune \) -o -type f -print expecting to retrieve only Y... (15 Replies)
Discussion started by: m69w
15 Replies

7. Shell Programming and Scripting

How to search through directories and sub dir

Im working on a project that basically imitates the find and whereis commands. The program will take in a file name or regular expression and, starting with the current directory search downwards and match any files with that pattern and prints the path name. I don't understand how to do this... (5 Replies)
Discussion started by: new2C
5 Replies

8. Shell Programming and Scripting

using finddepth in ftp to search for directories in perl

Hi all, I have script which downloads the build and copies onto the local machine I am able to download files in a directory, but unable to get the files in subdierctories. I am using finddepth to search for sub directories but I am unable to do so. Here is my code: ... (0 Replies)
Discussion started by: gurukottur
0 Replies

9. UNIX for Dummies Questions & Answers

Search for files in multiple directories

I want to search for a file pattern in more than one directory. How I need to do that? Here is the scenario: I am having a directory structure like the following: /log ...../20051001 ..........ftp_server_20051001.log ..........ftp_down_server.log ..........ftp_up_server.log... (7 Replies)
Discussion started by: ravikirankethe
7 Replies

10. Shell Programming and Scripting

script to search all the directories

Hi there, Is there any command or script to search all the directories for duplicated files? Thanks, Abrahim (3 Replies)
Discussion started by: abk
3 Replies
Login or Register to Ask a Question