Unix find eliminate file
If you just want to get a list of zero byte sized files, remove the -exec and -delete options. This will cause find to print out the list of empty files. Toggle navigation Stack Pointer. Home About Contact. Since -printf option is not available on OSX find here is one command that works on OSX find, just in case if someone doesn't want to install gnu find using brew etc: find.
Unfortunately this strips the whole path of each found file, including intermediate subdirectories, and just prints the filename itself. You are right. This solution is only good for files in current directory. For nested files we need to use: find.
Valheru Valheru 37 1 1 bronze badge. While this code may solve the question, including an explanation of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please edit your answer to add explanations and give an indication of what limitations and assumptions apply.
Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Helping communities build their own LTE networks. G-Man Says 'Reinstate Monica' Jan Jan 7, 30 30 silver badges 39 39 bronze badges. Using -delete is simpler syntax and no child processes spawned to do delete but may not work on all systems.
Could an attacker craft a filename that would cause this to delete something you didn't want deleted? So it's completely safe no matter what characters the filenames contain. AdminBee Greenonline 1, 4 4 gold badges 14 14 silver badges 21 21 bronze badges.
Greg Greg 1. This will not work with files with spaces in them. You can use a while loop instead which should take care of files with spaces. Neeraj Mhatre Neeraj Mhatre 1. The OP asked "I want to delete all the files older than 15 days", which your answer doesn't provide. They also did not ask for a restriction to php files.
If that is your blogspot page, please indicate ownership explicitly, instead of the generic "below link", otherwise you become suspect of simply spamming your site. Sign up or log in Sign up using Google.
You may specify "or" with the -o flag and the use of grouped parentheses. To match all files modified more than 7 days ago and accessed more than 30 days ago, use:. You may specify "not" with an exclamation point. To match all files ending in. You can specify the following actions for the list of files that the find command locates:. For example, for a long listing of each file found, use:.
0コメント