Working with FIND command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Working with FIND command
# 1  
Old 07-31-2013
Working with FIND command

Hi ,
In /home/etc/files path ran the following command
Code:
find . -name 'ABC*' | wc -l

The output of the above command is 25 as expected

In path /home path ran the following command
Code:
find . -name '/home/etc/files/ABC*' | wc -l

The output of the abvoe command is 0 .

Why the above command is not giving the correct output when executing in the home directory ?

Please Help
# 2  
Old 07-31-2013
The name argument should be a file name (or glob), not a path. . (the path) should contain the path.

Code:
find /home/etc/files -name "ABC*" | wc -l

This User Gave Thanks to Scott For This Post:
# 3  
Old 07-31-2013
The dot in
Code:
find .

invokes the search from present working directory. The command is trying to find files under present directory and with name
Code:
/home/etc/files/ABC*

If you had a file as below then it would be appearing in the result.

Code:
/home/etc/files/home/etc/files/ABC*

To find for files under /home/etc/files enter below command

Code:
find /home/etc/files -name 'ABC*' | wc -l

This User Gave Thanks to krishmaths For This Post:
# 4  
Old 07-31-2013
Quote:
Originally Posted by krishmaths
If you had a file as below then it would be appearing in the result.

Code:
/home/etc/files/home/etc/files/ABC*

Your analysis is incorrect.

-name only matches against a file's name (the basename of a multi-component pathname). There are two characters that are forbidden in UNIX filenames: / (which is reserved as the pathname component delimiter) and the null byte (which the C standard library uses to terminate strings). Since the pattern argument in -name '/home/etc/files/ABC*' contains one of the illegal characters, /, that usage of -name can never match anything and will always evaluate falsely, hence zero matches.

Regards,
Alister

Last edited by alister; 07-31-2013 at 03:43 PM..
This User Gave Thanks to alister For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find command not working on AIX

Hello, I am running find command in an AIX Server to find last 7 days modified directories/files. >cd /usr/openv/netbackup/db/class >ls -l total 0 drwxr-xr-x 3 root system 256 May 28 2014 Catalog-Backup drwxr-xr-x 3 root system 256 Sep 18 2012 ... (4 Replies)
Discussion started by: rahul2662
4 Replies

2. Shell Programming and Scripting

Maxdepth option of find command not working

Can you please figure out what is the issue here $ find . -maxdepth 1 -type f -size 0 -print find: bad option -maxdepth please find the OS details $ uname -a HP-UX g5u1216 B.11.31 U ia64 2614088426 unlimited-user license Use code tags, thanks. (6 Replies)
Discussion started by: TomG
6 Replies

3. Shell Programming and Scripting

[Solved] Find command is not working

Hello Friends, I have a problem about a little script, when i run the following two lines one by one on CLI then they work well: /usr/bin/mkdir `perl -e 'use POSIX qw(strftime); print strftime "%Y-%m-%d",localtime(time() - 30*24*60*60);'` find . -type f -name "fuseesb.log.*" -mtime 30... (5 Replies)
Discussion started by: EAGL€
5 Replies

4. Shell Programming and Scripting

sed find and replace command not working

Hi, Am trying to replace a character '-' with 'O' in position 289 in my file but am not success with below command. sed 's/^\(.\{289\}\)-/\1O/' filename sed: 0602-404 Function s/^\(.\{289\}\)-/\1O/ cannot be parsed. Thanks in Advance Sara Video tutorial on how to use code tags in The... (9 Replies)
Discussion started by: Sara183
9 Replies

5. Shell Programming and Scripting

Need help! command working ok when executed in command line, but fails when run inside a script!

Hi everyone, when executing this command in unix: echo "WM7 Fatal Alerts:", $(cat query1.txt) > a.csvIt works fine, but running this command in a shell script gives an error saying that there's a syntax error. here is content of my script: tdbsrvr$ vi hc.sh "hc.sh" 22 lines, 509... (4 Replies)
Discussion started by: 4dirk1
4 Replies

6. UNIX for Advanced & Expert Users

command for recently modified files - "find" command not working

I have three files a.txt , b.txt , c.txt in a directory called my_dir1 .These files were created before two or three months . I have a tar file called my_tar1.tar which contains three files a.txt , b.txt , d.txt . Somebody untarred the my_tar1.tar into my_dir1 directory. So existing two files were... (1 Reply)
Discussion started by: joe.mani
1 Replies

7. Shell Programming and Scripting

daystart option not working in find command

Hi, I am trying to list all the files created / modified today in a directory. With reference to this thread, https://www.unix.com/shell-programming-scripting/20324-capture-all-today-files.html I have used the below command to list all the files modified today. find . -daystart -type f... (8 Replies)
Discussion started by: arunkumarmc
8 Replies

8. Shell Programming and Scripting

find command not working

Hi all, find command not working for me in a perticular directory.The same command is working fine in any other directory. Following is the command i issued: find . -type f -print my question is , is it possbile to disable a command only for a perticular directory ??...of course... (4 Replies)
Discussion started by: panyam
4 Replies

9. UNIX for Dummies Questions & Answers

Find command not working as expected

I have a script with a find command using xargs to copy the files found to another directory. The find command is finding the appropriate file, but it's not copying. I've checked permissions, and those are all O.K., so I'm not sure what I'm missing. Any help is greatly appreciated. This is... (2 Replies)
Discussion started by: mpflug
2 Replies

10. UNIX for Advanced & Expert Users

find command not working

Hi, Having issues with the . parameter in the find command. Issuing "find . -name \*.pl" gives me find: cannot open .: No such device I got it working by substituting . with *, so "find * -name \*.pl" gives the correct listing. bin/test.pl "which find" lists /bin/find. Anybody... (7 Replies)
Discussion started by: jabrady
7 Replies
Login or Register to Ask a Question