Find command in windows 7 - windows

Recently migrated from windows XP to Windows 7.
I am using the eclipse environment for building the project. I have a make file with the below command
clean:
find . -type f -name "*.o" -exec rm {} \;
This was used to search and delete the object files in the current directory.
After I moved to windows 7 the same command does not work. Below is the output of the command on Windows 7.
cs-make all
find . -type f -name "*.o" -exec rm {} \;
Access denied - .
File not found - -TYPE
File not found - F
File not found - -NAME
File not found - -EXEC
File not found - RM
File not found - {}
File not found - ;
cs-make: *** [clean] Error 1***
My account has admin rights. Also I tried running eclipse using "run as admin".
If someone knows the solution please let me know.

Related

MacOS - One line command is working in terminal but not in .sh script?

MacOS High Sierra
I have a command that I currently use in terminal:
find /private/my/tmp -mindepth 1 -maxdepth 1 -type d -not -name -specialfolder -exec rm -r {} \;
which searches the folder private/my/tmp and removes all folders except one that is named "specialfolder".
This is working perfectly from the terminal, but I cannot get it working as .sh shell script. I have used chmod +x /scripts/myscript.sh to make it executable but this has not made any difference.
The shell script is:
#!/bin/sh
find /private/my/tmp -mindepth 1 -maxdepth 1 -type d -not -name -specialfolder -exec rm -r {} \;
Running it from the terminal as "sh myscript.sh" does not produce any result, no errors, nothing.
What do I need to fix to get this to work as a .sh script?
PS - I had considered it may be a permissions issue, but I have set permissions with chmod -R 777 on the /private/my/tmp folder and still no difference.

Get "unknown predicate `-delete" Error in script

The following script I have saved in an .sh file on the server that clears a few directories of old files and directories.
#!/bin/bash
find /PATH_TO_DIRECTORY_1 -mtime +5 -type f -delete
find /PATH_TO_DIRECTORY_2 -mtime +5 -type f -delete
find /PATH_TO_DIRECTORY_3 -mtime +5 -type d -exec rm -rv {} +
This is the error message when I run the script:
'ind: unknown predicate `-delete
In addition to
$'\r': command not found
I don't think the latter disturbs the code but the first one surely does.
Mind that I edit my code on Windows 10 and my server is an Ubuntu 64x run through Amazon Web Services (EC2).
I encountered the same issue.
The problem was that my file was in dos format.
Using the command dos2unix on my file, solve the problem.

missing argument to -exec

I am having a problem with a bash command returning the following error:
/usr/bin/find: missing argument to `-exec'
The actual command I am running is:
/usr/bin/find /backup-directory/ -maxdepth 1 -type f -mtime +14 -printf "%f\n" -exec /usr/local/bin/aws s3 mv /backup-directory/{} s3://my-s3-bin/{}\;
The goal was to have this command called from the crontab nightly to search a directory and move any file older than 14 days to Amazon S3 using the aws cli.
The find command works correctly up until just before the -exec, with the following output:
/usr/bin/find /backup-directory/ -maxdepth 1 -type f -mtime +14 -printf "%f\n"
20161030002947.Pg
20161029002644.Pg
20161027002705.Pg
20161028002402.Pg
20161031002440.Pg
And just the aws cli move command with explicit file name to move works as intended: The following command will move 20161030002947.Pg for instance, from the local backup directory to the s3 bin.
/usr/local/bin/aws s3 mv /backup-directory/20161030002947.Pg s3://my-s3-bin/20161030002947.Pg
I don't know why it is breaking when I put them together with the -exec and {} parameters.
The reason everything is called from the full path is to make sure there are no unforeseen issues when the command is called from crontab, and the OS on this particular server is Debian 8.
I suggest to replace
{}\;
by
{} \;

Stop bash script when find gets to a folder with permission denied

How can I stop script when command "find" gets to a folder with permission denied.
I make a list of all folders in my PC.
I would like to stop the searching process when "find" finds a permission denied folder.
DIRS=$(find . -type d)
Thanks a lot
Can't test this now, but you should check with exec if the folder is executable.
Something like
find -type d -print0 -not -exec test -x '{}' \; -quit

Bash Script OSX not deleting files it finds

I have this bash script here
#!/bin/bash
find /Users/ -name "*.mov" -o -name "*.flv" -o -name "*.mp4" -o -name "*.avi" -o -name "*.wmv" -o -name "*.mpeg" -o -name "*.avi" -o -name "*.wmv" -o -name "*.f4v" -o -name "*.m4v" -o -name "*.mxf" -o -name "*.ts" -type f -mtime +7 -exec rm -rf {} \;
It finds all the files that are older than 7 days, and that works fine, but when I want it to remove the result set that I found it doesn't delete any of the files. Is there something I'm doing wrong? This is on Mac OSX 10.6
Any help would be great. Thanks!
Instead, of -exec rm -rf {}\;, try the -delete option if it's available on your version of the find command. This will show an error message after each failed attempt to delete. That might give you more information what's going on.
$ find . -name "*.foo" -type f -mtime +7 -delete
find: -delete: unlink(./four.foo): Permission denied
find: -delete: unlink(./one.foo): Permission denied
find: -delete: unlink(./three.foo): Permission denied
find: -delete: unlink(./two.foo): Permission denied
Neither find is returning the actual exit code from the delete/rm command. You may want to do something like this:
find . -name ... -type f -mtime +7 | while read file
do
if rm -fr $file
then
echo "Successfully deleted $file"
else
echo "Error deleting file: Exit code $?"
fi
done
That might give you a better understanding of what's going on.
Maybe you should run the command with sudo ? You may not have full access to all directories as a normal user.
The find command is in /usr/bin, which isn't in the default PATH for cron jobs. Either run it as /usr/bin/find, or set PATH at the beginning of your script.

Resources