Find commmand returning search path with the result set
OS Platform : Oracle Linux 6.5
We are creating a shell script to purge old log files . It uses find command with rm in it.
The syntax is
find <Path of Log Directory> -exec rm -fr {} \;
Example:
find /tmp/test3 -exec rm -fr {} \;
For rm command , we use -r option to remove directories because it is not just files we want to delete. We have to purge directories too. Because sometimes our application creates directories for certain type of issues. For example, when the application crashes, it creates a 'Core Dump' directory by which several files are clubbed together and placed in a coreDump directory . Example coreDump_29_June_2015_11_05_32.
But, I have noticed that, when we try to search for files and directories in the search path, find command is returning the search path too in the result set. For example , I am trying to find all files and directories within /tmp/test3 directory . But, find is returning "/tmp/test3" in the result set too (shown in red below )
Since find is falsely returning the search path itself, rm is trying to remove it. But, rm is trying to delete a directory called "/tmp/test3" within /tmp/test3 . ie. rm /tmp/test3/tmp/test3 which doesn't exist. So, it is harmless. But, how can I prevent the find command from returning the search path itself (the line shown in red below).
I am looking for all the header files (*.h).. which as per documentation of the UNIX system shouldbe there.
I am using
find / -name *.h -print
But it does't give anything.
My question is under what condition the "find" condition will fail to find the file?
What is the work around.
... (4 Replies)
Hi,
By default FIND command searches for matching files in all the subdirectories within the specified path.
Is there a way to restrict FIND command's search path to only the specified directory and NOT TO scan its subdirectories.
Any help would be more than appreciated.
Thanks and Regards (2 Replies)
Can anybody pls look into this script and tell me where I went wrong. After running this script, it is showing like "Trying to overlay current working directory ABORT!!!"
:-(
ARGCNT=$#
if
then
echo "Two parameters are needed for this shell "
echo "Please try again with... (1 Reply)
Hello all
say i like to find files i do :
find . -name "*.txt"
but if i like to find ( and print out ) only the path's where the files are ( the *.txt files )
what can i add to the find command ? (1 Reply)
Hi,
Can anybody help with this?
When I log into my user account on my box via ssh and then instantly perform an env command I see that my path has been set as follows:
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
My user account uses the ksh shell. In my home directory there is no... (7 Replies)
Hi,
I have to write a windows XP program, that would generate a Solaris Script, which would then be transported to Solaris, executed, the execution result then needs to be returned to the XP program.
For transporting the file i was thinking of following FTP (admins rejected it) or File share on... (1 Reply)
Just started with learning python and tried something, most people here would call more than simple.
I just wanted to list all directories within my main directory. So I user the following code:
#!/usr/bin/env python
import os
if os.path.isdir("/home/testaccaunt/public_html"):
... (8 Replies)
I wanted to see if there is any duplicate of a specific command in the command search path. The following code will list all copies of "openssl" in the command search path.
find `printenv PATH | sed "s/:/ /g"` -maxdepth 1 -name openssl
However, the above code would fail if the search path... (9 Replies)
find . -type f -print0 | xargs -0 chmod 600
find . -type f
On bash, I would like to pass the search result of "find" to another command as well as to the standard output. The above code performs the same search twice -- once for "xargs -0 chmod" and another for stdout. I would like to... (5 Replies)
Hi Folks -
I was wondering if you could help convert batch code in Linux? For instance, I use the following piece of code in DOS to find a file/executable, and then the FULL path as a variable.
::-- If startMaxl.exe exists, set full path --::
for %%D in (c d e f g h i j k l m n o p q r s t... (4 Replies)