47
loading...
This website collects cookies to deliver better user experience
300x200
or 400x220
and where either png
or jpg
files.find
but the more filetypes and pconditions the longer the command.find /tmp -name '*.png' -or -name '*.jpg'
Important: the find
command in MacOS and in GNU/Linux (Ubuntu, Debian, etc..) are slightly different and not all syntax can be used between systems.
A regular expression is a special text string for describing a search pattern. You can think of regular expressions as wildcards on steroids. You are probably familiar with wildcard notations such as *.txt
to find all text files in a file manager. The regex equivalent is .*\.txt
. -[regexbuddy]
find -E . -regex '.*\.(jpg|png)'
find ./ -regextype posix-extended -regex '.*(jpg|png)$'
find -E . -regex '.*(300x200|400x220)\.(jpg|png)'
find ./ -regextype posix-extended -regex '.*(300x200|400x220)\.(jpg|png)$'
'
) if you change the sintax and add an $
at the end in the case of Linux.'.*(SAM).*\.(jpg|png)'
find -E . -regex '.*(SAM).*\.(jpg|png)'
find ./ -regextype posix-extended -regex '.*(SAM).*\.(jpg|png)$'
xargs is a command on Unix and most Unix-like operating systems used to build and execute commands from standard input. It converts input from standard input into arguments to a command. -[Wikipedia]
xargs
comes in. Let’s say you would like to remove all the jpg and png files that have SAM
in the filename.find -E . -regex '.*(SAM).*\.(jpg|png)' | rm
find ./ -regextype posix-extended -regex '.*(SAM).*\.(jpg|png)$' | rm
something-AAAxBBB.jpg
find -E . -regex '.*(1024x576|278x380|506x380|1024x576|508x380|1024x681|550x366|550x309|350x220|380x380|768x768|285x380|768x1024|1024x1024|213x380|576x1024|550x367|253x380|681x1024|1024x768)\.(jpg|png)' | xargs rm
47