I need to delete all files from the working directory and its sub directories using the find command, for that I am using -prune option but some how I am having a syntax issue.
I have tried the below, please help me correct the syntax
find . -name \* -type f -exec rm -f {} \;
>> Works but only remove the files from the current directory
Without seeing the error message you got, it's difficult to diagnose, however:-
If there are lots of files, your use of -name * unquoted may have expanded for each file so much that you exceeded the command line length
You might speed things up a little (if there are many many files) by using xargs bolted on like this find . -type f | xargs rm -f so it runs fewer rm commands (collects them up appropriate to the maximum command line length rather than one for each file) which may run quicker
You might speed things up a little (if there are many many files) by using \+ instead of \; if your AIX version supports it.
If you do want to specify an expression to match the file name, always quote it to avoid command line expansion. You might well have got it working with find . -name "*" ......
Generally I discourage from find | xargs , because of its unsafe space handling.
For demonstration
# printf "%s\n" file1 "filename with spaces"
file1
filename with spaces
# printf "%s\n" file1 "filename with spaces" | xargs ls
file1: No such file or directory
filename: No such file or directory
with: No such file or directory
spaces: No such file or directory
The {} + works like xargs - without such problems.
(Linux/GNU find, before it got the {} + feature, had the old work-around find -print0 | xargs -0 .)