Solaris find command - find

In Solaris, what is the syntax of find command to find files having multiple file name formats?
Eg: In my current directory and in its sub-directories if I have files like test.log, sample.out, demo.buf and some other files, how can I write single find command to find these 3 files.

this is the correct one
find . \( -name "test.log" -o -name "sample.out" -o -name "demo.buf" \) -print

Same as all other Unixes:
find . -name test.log -o -name sample.out -o name demo.buf

Related

Running Find command from the directory vs. another directory

I am doing something wrong but cannot figure out what it is. I am trying to move all files in the folder (folder A) to another folder (folder B) without any subdirectories and excluding certain files
When I am in the folder I run...
cd folderA
find . -path './*' -prune -not \( -name "file1.php" -o -name "file2.txt" \) -type f -exec mv -f {} ~/folderB/ \;
That works great. But I want to run the above find command in a bash script and do no want to have to go to the folder so I tried...
find ~/folderA/ -path './*' -prune -not \( -name "file1.php" -o -name "file2.txt" \) -type f -exec mv -f {} ~/folderB/ \;
And nothing! What am I doing wrong.
Thanks in Advance
After stripping the above command down, I found the issue. for some reason -path './*' -prune does not work outside of the direct folder. Here is the command I used to get it to work outside the folder itself...
find ~/folderA/ -maxdepth 1 -not \( -name "file1.php" -o -name "file2.txt" \) -type f -exec mv -f {} ~/folderB/ \;
Again, not sure way -maxdepth 1 would work over the other method, but it did.
FYI... if you want to go further down into the subdirectories you can by changing the 1 value

SunOS. Find files that do not contain the substring 'foo' in the file name

Now I exclude files by their extension.
find ./export/home/ ! \( -name *.log -o -name *.out -o -name *.tmp \)
But I also want to exclude files with the name containing some string 'foo'.
Need some sort of analog " like '%foo%' " (PL\SQL), to exclude files such as "1_foo2".
I can not use the GNU version of the command "find".
You are pretty close:
find ./export/home/ -type f ! \( -name "*.log" -o -name "*.out" -o
-name "*.tmp" -o -name "*foo*" \)

remove multiple files using find and rm in perl

I have a few text files in my directory which need to be removed. There are a bunch of text files in my directory:
leaves_emp1.txt
pay_emp1.txt
pf_emp1.txt
leaves_emp2.txt
pay_emp2.txt
pf_emp2.txt
[...]
I've tried using the following code to remove the files containing "emp1":
/usr/bin/find $LogDir -name \"leaves_emp1.txt\" -and -name \"pay_emp1.txt\" -and -name \"pf_emp1.txt\" -exec rm {}
But it is not working. Please help. I tried with -a and -o too. I also tried using the () for the files.
I am just using the code as follows
/usr/bin/find $LogDir -name \"*emp1.txt\" -exec rm {}
You need to avoid fork-bombs. The "exec" call in find will spawn a fork/exec with each file. I find it much easier and scalable to call something like this:
find . -type f -name '*emp1.txt' | perl -lane 'unlink $_ if -f $_' -
Note: if you want to stick with just exec, you must remember to use the "\;" at the end
find . -type f -name '*emp1.txt' -exec rm {} \;

emacs rgrep fails in find command (Windows 7)

This seems like a dumb question and maybe it should be directed to a forum for gnuwin32, but I'll give it a try here.
I'm using grep from within emacs for Windows. I've had to use grep-find vs rgrep, which I would prefer to use because it weeds out many files I don't want to grep. Unfortunately, rgrep seems to create a 'find' command that is so long that it chokes and gives an error.
Using M-x rgrep to search for 'import' in my python files (silly example, I know) gives this output:
find . -type d "(" -path "/SCCS" -o -path "/RCS" -o -path "/CVS" -o -path "/MCVS" -o -path "/.svn" -o -path "/.git" -o -path "/.hg" -o -path "/.bzr" -o -path "*/_MTN" -o -path "*/_darcs" -o -path "/{arch}" ")" -prune -o "(" -name ".#" -o -name ".o" -o -name "~" -o -name ".bin" -o -name ".bak" -o -name ".obj" -o -name ".map" -o -name ".ico" -o -name ".pif" -o -name ".lnk" -o -name ".a" -o -name ".ln" -o -name ".blg" -o -name ".bbl" -o -name ".dll" -o -name ".drv" -o -name ".vxd" -o -name ".386" -o -name ".elc" -o -name ".lof" -o -name ".glo" -o -name ".idx" -o -name ".lot" -o -name ".fmt" -o -name ".tfm" -o -name ".class" -o -name ".fas" -o -name ".lib" -o -name ".mem" -o -name ".x86f" -o -name ".sparcf" -o -name ".dfsl" -o -name ".pfsl" -o -name ".d64fsl" -o -name ".p64fsl" -o -name ".lx64fsl" -o -name ".lx32fsl" -o -name ".dx64fsl" -o -name ".dx32fsl" -o -name ".fx64fsl" -o -name ".fx32fsl" -o -name ".sx64fsl" -o -name ".sx32fsl" -o -name ".wx64fsl" -o -name ".wx32fsl" -o -name ".fasl" -o -name ".ufsl" -o -name ".fsl" -o -name ".dxl" -o -name ".lo" -o -name ".la" -o -name ".gmo" -o -name ".mo" -o -name ".toc" -o -name ".aux" -o -name ".cp" -o -name ".fn" -o -name ".ky" -o -name ".pg" -o -name ".tp" -o -name ".vr" -o -name ".cps" -o -name ".fns" -o -name ".kys" -o -name ".pgs" -o -name ".tps" -o -name ".vrs" -o -name ".pyc" -o -name ".pyo" ")" -prune -o -type f "(" -iname "*.py" ")" -exec grep -i -nH -e "import" {} +
find: paths must precede expression
Usage: find [-H] [-L] [-P] [path...] [expression]
If I cut and paste this command into a cygwin window, which pulls find from /usr/bin, it works just fine and finds several instances. If I paste the same command into a cmd window which then uses gnuwin32/bin/find.exe, I get the same error as above (find: paths must precede expression). I also tried the command in a mingw shell and it works there (using /msys/1.0/bin/find.exe). To complicate matters, copying the mingw version of find into /gnuwin32/bin/ didn't help. No errors, but the grep never actually finds anything. Worse, doing that breaks 'grep-find' in the same way; nothing gets found.
I'm guessing there's a limit to the length of the overall command that I'm hitting here when using the gnuwin32 version of 'find'.
I think I could just give up on gnuwin32 and change my path to point to /msys/1.0/bin for commands that I use, but those commands wouldn't run in a cmd window any longer, at least not without having access to mingw DLLs. Part of me wants to know why the gnuwin32 version of find is choking. Any ideas? Sorry for the long-winded question.
Does emacs know where are the executables?
I have something like this in my .emacs you may want adopt as per your file paths
;;; excutable paths (for unix commands from MSYS and git from msysgit)
(setq exec-path (append exec-path
'("C:/MinGW/msys/1.0/bin/"
"C:/MinGW/bin/"
"c:/MinGW/mingw32/bin"
"C:/Program Files (x86)/Git/bin")))
For me, the correct answer to this problem was found here:
Gnuwin32 find.exe expands wildcard before performing search
I downloaded unxutils.zip listed in the above answer and extracted the find.exe from there to my emacs bin folder. I don't recommend copying to emacs bin folder as a best practice but it avoids a lot of configuration overhead and it gets you up and running instantly.

Linux find command gotcha?

Hi I am trying to find all js & css files in one find command. I tried all of the below but in vain:
find WebContent -name "*.[jc]ss?"
find WebContent -name "*.[jc]ss{0,1}"
find WebContent -name "*.[jc][s]{1,2}$"
find WebContent -name "*.[jc]s{1,2}"
find WebContent -name "*.[jc]s[s]?"
Now what??
-name accepts arguments that are globs, not regular expressions. You could use -regex if you wanted to use regular expressions, but the -o option (meaning "or") is probably the simplest solution:
find WebContent -name "*.js" -o -name "*.css"
Try this
find WebContent -regextype posix-extended -regex '.*\.(css|js)$'
use the -iname option case insensitive
find WebContent \( -iname "*.js" -o -iname "*.css" \)
you can do boolean expressions with find. -o stands for OR.
find -name "*.js" -o -name "*.cpp"