Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

My goal is to match specific files from specific sub directories. I have the following folder structure

`-- data
    |-- a
    |-- a.txt
    |-- b
    |-- b.txt
    |-- c
    |-- c.txt
    |-- d
    |-- d.txt
    |-- e
    |-- e.txt
    |-- org-1
    |   |-- a.org
    |   |-- b.org
    |   |-- org.txt
    |   |-- user-0
    |   |   |-- a.txt
    |   |   |-- b.txt

I am trying to list the files only inside the data directory. I am able to get the correct result using the following command in RHEL

find  ./testdir/ -iwholename "*/data/[!/].txt"
a.txt
b.txt
c.txt
d.txt
e.txt

If I run the same command in Ubuntu it is not working.

Can anyone please tell me why it is not working in Ubuntu ?

Edit:

After some tests I realized that as per my post it is working properly in both RHEL and Ubuntu. The problem lies somewhere else. The file which I have in my Ubuntu system are data files.

It is very strange that for these file types it is not listing both in RHEL and Ubuntu.

[supratik@testserver ~]$ ls testprog/data/
a.txt  data.dat

[supratik@testserver ~]$ file testprog/data/a.txt
testprog/data/a.txt: ASCII text

[supratik@testserver ~]$ file testprog/data/data.dat
testprog/data/data.dat: data

[supratik@testserver ~]$ find  ./testprog/ -iwholename "*/data/[!/].txt"
./testprog/data/a.txt

[supratik@testserver ~]$ find  ./testprog/ -iwholename "*/data/[!/].dat"

share|improve this question
    
What happens in Ubuntu ? What are a,b,c,d etc ? –  Iain Nov 18 '11 at 16:25
    
In Ubuntu I just get a prompt back, I don't get the list of files. "a, b, c,d, e" are also files. I created them using touch for testing. –  Supratik Nov 18 '11 at 16:28
    
Did you try using ls piped into grep -E instead? –  mbrownnyc Nov 18 '11 at 16:32
    
I think you're using a glob rather than a regex... –  Vatine Nov 19 '11 at 11:34
    
@mbrownnyc I have a many sub directories inside the data folder. So ls will work for me, but find will be much cleaner solution. I am surprised why find is not listing the binary files or am I missing something. –  Supratik Nov 19 '11 at 11:44

1 Answer 1

I just checked this on CentOS 5.6,6.0 and Ubuntu 9.04,10.04 and 11.04 and I get the same answer on all of them viz

find  ./testdir/ -iwholename "*/data/[!/].txt"
./testdir/data/c.txt
./testdir/data/d.txt
./testdir/data/a.txt
./testdir/data/e.txt
./testdir/data/b.txt

You can get similar results with

Find ./testdir/data/ -maxdepth 1 -name '*.txt'
share|improve this answer
    
@lain Please check my edited reply on my post. Can you please tell me why I am getting this strange result? I can not use -maxdepth because I have sub folders inside it which I am filtering out by multiple regex with -iwholename. –  Supratik Nov 19 '11 at 11:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.