find-util

Filter folders whose name is a timestamp - pattern matching vs. regex matching using the find utility

生来就可爱ヽ(ⅴ<●) 提交于 2020-06-27 00:46:17
问题 I am writing a generic shell script which filters out files based on given regex. My shell script: files=$(find $path -name $regex) In one of the cases (to filter), I want to filter folders inside a directory, the name of the folders are in the below format: 20161128-20:34:33:432813246 YYYYMMDD-HH:MM:SS:NS I am unable to arrive at the correct regex. I am able to get the path of the files inside the folder using the regex '*data.txt' , as I know the name of the file inside it. But it gives me

Filter folders whose name is a timestamp - pattern matching vs. regex matching using the find utility

妖精的绣舞 提交于 2020-06-27 00:44:12
问题 I am writing a generic shell script which filters out files based on given regex. My shell script: files=$(find $path -name $regex) In one of the cases (to filter), I want to filter folders inside a directory, the name of the folders are in the below format: 20161128-20:34:33:432813246 YYYYMMDD-HH:MM:SS:NS I am unable to arrive at the correct regex. I am able to get the path of the files inside the folder using the regex '*data.txt' , as I know the name of the file inside it. But it gives me

bash find, only delete files - order of arguments

人走茶凉 提交于 2020-01-21 14:22:05
问题 Say today is April 8th and I execute the following in bash. cd /tmp mkdir hello touch -d 2015-04-01 hello Then, say I want to delete all files in /tmp that are older than one day, but NOT directories and I execute this: find /tmp -mtime +1 -delete -type f Why is directory "hello" deleted if it's not a file? Thanks! 回答1: The find command executes the expression in order. Since -delete is before -type , -type is never reached. Try: find /tmp -mtime +1 -type f -delete 回答2: David C. Rankin's

bash find, only delete files - order of arguments

孤街醉人 提交于 2020-01-21 14:21:56
问题 Say today is April 8th and I execute the following in bash. cd /tmp mkdir hello touch -d 2015-04-01 hello Then, say I want to delete all files in /tmp that are older than one day, but NOT directories and I execute this: find /tmp -mtime +1 -delete -type f Why is directory "hello" deleted if it's not a file? Thanks! 回答1: The find command executes the expression in order. Since -delete is before -type , -type is never reached. Try: find /tmp -mtime +1 -type f -delete 回答2: David C. Rankin's

bash find, only delete files - order of arguments

霸气de小男生 提交于 2020-01-21 14:20:28
问题 Say today is April 8th and I execute the following in bash. cd /tmp mkdir hello touch -d 2015-04-01 hello Then, say I want to delete all files in /tmp that are older than one day, but NOT directories and I execute this: find /tmp -mtime +1 -delete -type f Why is directory "hello" deleted if it's not a file? Thanks! 回答1: The find command executes the expression in order. Since -delete is before -type , -type is never reached. Try: find /tmp -mtime +1 -type f -delete 回答2: David C. Rankin's

Recursively search directory of binary files for hexadecimal sequence?

故事扮演 提交于 2019-12-07 16:31:17
问题 The current commands I'm using to search some hex values (say 0A 8b 02 ) involve: find . -type f -not -name "*.png" -exec xxd -p {} \; | grep "0a8b02" || xargs -0 -P 4 Is it possible to improve this given the following goals: search files recursively display the offset and filename exclude certain files with certain extensions (above example will not search .png files) speed: search needs to handle 200,000 files (around 50KB to 1MB) in a directly totaling ~2GB. I'm not too confident if the

bash find, only delete files - order of arguments

拈花ヽ惹草 提交于 2019-12-01 23:51:57
Say today is April 8th and I execute the following in bash. cd /tmp mkdir hello touch -d 2015-04-01 hello Then, say I want to delete all files in /tmp that are older than one day, but NOT directories and I execute this: find /tmp -mtime +1 -delete -type f Why is directory "hello" deleted if it's not a file? Thanks! The find command executes the expression in order. Since -delete is before -type , -type is never reached. Try: find /tmp -mtime +1 -type f -delete mklement0 David C. Rankin's helpful answer uses the correct abstract term, expression , to refer to the list of arguments starting with

Unix find: search for executable files

大兔子大兔子 提交于 2019-11-30 05:50:47
问题 What type of parameter/flag can I use with the Unix find command so that I search executables? 回答1: On GNU versions of find you can use -executable : find . -type f -executable -print For BSD versions of find, you can use -perm with + and an octal mask: find . -type f -perm +111 -print In this context "+" means "any of these bits are set" and 111 is the execute bits. Note that this is not identical to the -executable predicate in GNU find. In particular, -executable tests that the file can be

Unix find: search for executable files

我是研究僧i 提交于 2019-11-27 17:25:30
What type of parameter/flag can I use with the Unix find command so that I search executables? On GNU versions of find you can use -executable : find . -type f -executable -print For BSD versions of find, you can use -perm with + and an octal mask: find . -type f -perm +111 -print In this context "+" means "any of these bits are set" and 111 is the execute bits. Note that this is not identical to the -executable predicate in GNU find. In particular, -executable tests that the file can be executed by the current user, while -perm +111 just tests if any execute permissions are set. Older