how to search directories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to search directories
# 8  
Old 03-09-2007
Quote:
Originally Posted by snerge
On HP-UX, you have to enclose your query between double quotes "file*" but on linux you do not when using wildcards.
You have to do that on on any *nix OS, including Linux.
# 9  
Old 03-09-2007
Quote:
Originally Posted by cfajohnson
You have to do that on on any *nix OS, including Linux.
Just tryed on my ubuntu at home and it was working without double quotes, maybe not the correct behavior .....

Code:
snerge@sn-ubt:~$ cd /tmp
snerge@sn-ubt:/tmp$ ls
gconfd-snerge  kde-snerge  ksocket-snerge  orbit-snerge  ssh-jtGPjJ5607
snerge@sn-ubt:/tmp$ find . -name orb*
./orbit-snerge
snerge@sn-ubt:/tmp$

# 10  
Old 03-16-2007
Snerge - is there a switch or option I can include in my example of FIND that will ignore case?

find . -name filename*
# 11  
Old 03-16-2007
Hello kozmo,

Not that I know of, you will need to learn a little bit about regular expression

You can pass any regular expression to -name like :

Code:
find . -type f -name "[^C|c]*"

should find every file beginning with C or c ....

Have a look at man regexp and look for tutorials about regular expression.

I am no regexp guru (still learning) as it is one of the most usefull thing I have seen as a unix admin.
# 12  
Old 03-16-2007
Quote:
Originally Posted by snerge
Just tryed on my ubuntu at home and it was working without double quotes, maybe not the correct behavior .....

Code:
snerge@sn-ubt:~$ cd /tmp
snerge@sn-ubt:/tmp$ ls
gconfd-snerge  kde-snerge  ksocket-snerge  orbit-snerge  ssh-jtGPjJ5607
snerge@sn-ubt:/tmp$ find . -name orb*
./orbit-snerge
snerge@sn-ubt:/tmp$

Do this, then try it again:
Code:
touch orbit orbison orb

# 13  
Old 03-16-2007
Quote:
Originally Posted by cfajohnson
Do this, then try it again:
Code:
touch orbit orbison orb

yup, you're right !

find is now not even acting the way it was back when I tested/posted this, I'm running feisty fawn (herd 5). I guess they might be doing some change ..

I usually always put strings between doubles quotes, I think it is the best way to avoid funny behavior !

thanks
# 14  
Old 03-16-2007
Quote:
Originally Posted by snerge
yup, you're right !

find is now not even acting the way it was back when I tested/posted this, I'm running feisty fawn (herd 5). I guess they might be doing some change ..
There is no change; it doesn't work, and has never worked. You may have been lucky, and not had any files in the current directory that match the wildcard expression.

The -name operand to find takes a single argument; if the shell expands a wildcard to more than one filename, then your find syntax is wrong.

Even if it expands the wildcard to a single filename, your command will not work as it will only match that single name.
Quote:
I usually always put strings between doubles quotes, I think it is the best way to avoid funny behavior !
Don't bother to quote strings. You need to quote wildcards and variables.

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