{"id":8890,"date":"2016-07-22T00:18:09","date_gmt":"2016-07-21T23:18:09","guid":{"rendered":"http:\/\/probook\/DebianAdmin\/?p=3527"},"modified":"2016-07-22T00:18:09","modified_gmt":"2016-07-21T23:18:09","slug":"exploring-find-cmd-options-continuing-with-metacharacters-2","status":"publish","type":"post","link":"https:\/\/stevepedwards.today\/DebianAdmin\/exploring-find-cmd-options-continuing-with-metacharacters-2\/","title":{"rendered":"Exploring Find Cmd Options \u2013 Continuing With Metacharacters"},"content":{"rendered":"<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_8890\" class=\"pvc_stats all  \" data-element-id=\"8890\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n<p>Regular expression metacharacters usage consist of the following:<\/p>\n<p>^ $ . [ ] { } - ? * + ( ) | \\<\/p>\n<p>These cannot be read about using the man pages for each symbol except the [ -test\u201d chars e.g:<\/p>\n<p><span style=\"color: #0000ff;\">man ^<\/span><\/p>\n<p><span style=\"color: #cc0000;\">No manual entry for ^<\/span><\/p>\n<p>These metacharacters can be read and expanded by the shell as special characters, or -escaped\u201d by prefixing with the backslash -\\\u201d or quoted in -\u201d to prevent expansion.<\/p>\n<p>For the first example to show the difference between a literal or unescaped metacharacter, starting with probably the most commonly used metacharacter \u2013 the *;<\/p>\n<p>Using the find command for example, an erroneous usage search attempt for any files that match ANY other character at the start of the file name:<\/p>\n<p><span style=\"color: #0000ff;\">find Videos\/ -name *<\/span><\/p>\n<p><span style=\"color: #cc0000;\">find: paths must precede expression: chapter1.txt<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]<\/span><\/p>\n<p><span style=\"color: #ffffff;\">This fails with stderror output as the shell attempts to expand the * to output all the files in the current directory (ABOVE Videos) so fails as a search path order conflict. <\/span><\/p>\n<p><span style=\"color: #ffffff;\">But, if the asterisk is quoted, all files in the Video dir are listed, as they all start with a character of some sort.<\/span><\/p>\n<p><span style=\"color: #ffffff;\"><span style=\"color: #0000ff;\">find Videos\/ -name '*'<\/span><\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/Martial Law 9-11- Rise Of The Police State.mp4<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/What Happened on the Moon.mp4<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/The Untold Secrets of NASA - Unbelievable Mars - Space Documentary(2015).mp4<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/Peter Joseph's 'Where are we going'.mp4\u2026..etc.<\/span><\/p>\n<p><span style=\"color: #ffffff;\">So, escaping does the same:<\/span><\/p>\n<p><span style=\"color: #ffffff;\"><span style=\"color: #0000ff;\">find Videos\/ -name <\/span><span style=\"color: #0000ff;\">\\<\/span><span style=\"color: #0000ff;\">*<\/span><\/span><\/p>\n<p><span style=\"color: #ffffff;\">so gives the same result as above \u2013 all files in Videos are found and listed.<\/span><\/p>\n<p><span style=\"color: #ffffff;\">If the asterisk is prefixed or appended by another character, then it is not escaped so it can do the job it is intended for. To find all files starting with a \"0\u201d<\/span><\/p>\n<p><span style=\"color: #0000ff;\">find Videos\/ -name 0*<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/027 Richard Dolan Montreal - ModernKnowledge @ CapricornRadioTV.mp4<\/span><\/p>\n<p><span style=\"color: #ffffff;\">What if you want to find all files starting with any number? You can use a range defined as:<\/span><\/p>\n<p><span style=\"color: #0000ff;\">find Videos\/ -name '[0-9]*'<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/9-11- Decade of Deception (Full Film NEW 2015).mp4<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/027 Richard Dolan Montreal - ModernKnowledge @ CapricornRadioTV.mp4<\/span><\/p>\n<p><span style=\"color: #ffffff;\">but, the equivalent numbers alone also\u00a0show files beginning with a 0 or a 9:<\/span><\/p>\n<p><span style=\"color: #0000ff;\">find Videos\/ -name '[09]*'<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/9-11- Decade of Deception (Full Film NEW 2015).mp4<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/027 Richard Dolan Montreal - ModernKnowledge @ CapricornRadioTV.mp4<\/span><\/p>\n<p><span style=\"color: #ffffff;\">The lesson here is: Don't assume your command structure is correct globally on the basis of 1 result set! It just happens that this directory happens only to have files beginning with a 0 and a 9 so give the same result as 2 very different search conditions!<\/span><\/p>\n<p><span style=\"color: #ffffff;\">So, in English, you understand [0-9]\u00a0as -find any file starting with a 0 OR a 1 OR a 2...9.\u201d<\/span><\/p>\n<p><span style=\"color: #ffffff;\">To do the opposite \u2013 find all files NOT beginning with numbers:<\/span><\/p>\n<p><span style=\"color: #0000ff;\">find Videos\/ -name '[!0-9]*'<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/Martial Law 9-11- Rise Of The Police State.mp4<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/What Happened on the Moon.mp4<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/The Untold Secrets of NASA - Unbelievable Mars - Space Documentary(2015).mp4<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/Peter Joseph's 'Where are we going'.mp4\u2026..etc.<\/span><\/p>\n<p><span style=\"color: #ffffff;\">Note the shebang ! Has to be INSIDE the brackets as outside is interpreted by find as being the start of a file name, not a logical NOT parameter:<\/span><\/p>\n<p><span style=\"color: #0000ff;\">find Videos\/ -name '![0-9]*'<\/span><\/p>\n<p><span style=\"color: #ffffff;\">(no files found as none begin with a -!\u201d)<\/span><\/p>\n<p><span style=\"color: #ffffff;\">For NOT in a find command context, it would be a space delimited operator, separated from and before the file name option, to find all files NOT beginning with a number:<\/span><\/p>\n<p><span style=\"color: #0000ff;\">find Videos\/ ! -name '[0-9]*'<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/Martial Law 9-11- Rise Of The Police State.mp4<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/What Happened on the Moon.mp4<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/The Untold Secrets of NASA - Unbelievable Mars - Space Documentary(2015).mp4<\/span><\/p>\n<p><span style=\"color: #ffffff;\"><span style=\"color: #cc0000;\">Videos\/Peter Joseph's 'Where are we going'.mp4\u2026..<\/span><span style=\"color: #cc0000;\">etc.<\/span> <\/span><\/p>\n<p><span style=\"color: #ffffff;\">What about file name order relating to case and given by a range? <\/span><\/p>\n<p><span style=\"color: #ffffff;\">It's complex due to the POSIX or other ASCII standard your PC is set to, AND how find lists it's results depending on inode order also. This is why you get some seemingly weird results for alphabetical listings.<\/span><\/p>\n<p><span style=\"color: #ffffff;\">First \u2013 so I know how many files I have totally in Videos:<\/span><\/p>\n<p><span style=\"color: #0000ff;\">find Videos\/ -name '*' | wc -l<\/span><\/p>\n<p><span style=\"color: #cc0000;\">137<\/span><\/p>\n<p><span style=\"color: #ffffff;\">Will Shott's TLCL.pdf gives examples for grep on p273 that show ranges the likes of:<\/span><\/p>\n<p><span style=\"color: #0000ff;\">find Videos\/ -name '[ABCDEFGHIJKLMNOPQRSTUVWXZY]*' | wc -l<\/span><\/p>\n<p><span style=\"color: #cc0000;\">131<\/span><\/p>\n<p><span style=\"color: #ffffff;\">So I know I am not seeing ALL files, as 2 begin with numbers,<\/span><\/p>\n<p><span style=\"color: #0000ff;\">find Videos\/ -name '[0-9]*' | wc -l<\/span><\/p>\n<p><span style=\"color: #cc0000;\">2<\/span><\/p>\n<p><span style=\"color: #ffffff;\">and 3 with lowercase e.g.<\/span><\/p>\n<p><span style=\"color: #0000ff;\">find Videos\/ -name '[abcdefghijklmnopqrstuvwxyz]*' | wc -l<\/span><\/p>\n<p><span style=\"color: #cc0000;\">3<\/span><\/p>\n<p><span style=\"color: #ffffff;\">This does not account for all 137 files, so check these can be found using a number range [0-9], a lowercase range [a-z] and an uppercase range [A-Z] together to be sure as:<\/span><\/p>\n<p><span style=\"color: #0000ff;\">find Videos\/ -name '[ABCDEFGHIJKLMNOPQRSTUVWXZYabcdefghijklmnopqrstuvwxyz]*' | wc -l<\/span><\/p>\n<p><span style=\"color: #cc0000;\">134<\/span><\/p>\n<p><span style=\"color: #ffffff;\">then:<\/span><\/p>\n<p><span style=\"color: #0000ff;\">find Videos\/ -name '[ABCDEFGHIJKLMNOPQRSTUVWXZYabcdefghijklmnopqrstuvwxyz0123456789]*' | wc -l<\/span><\/p>\n<p><span style=\"color: #cc0000;\">136<\/span><\/p>\n<p><span style=\"color: #ffffff;\">BUT that's NOT exactly correct \u2013 I'm missing 1 file!? <\/span><\/p>\n<p><span style=\"color: #ffffff;\">How can I find it??<\/span><\/p>\n<p><span style=\"color: #ffffff;\">Use the NOT shebang ! with the find option...? Aha! A file that begins with a quote \" ' \u201d<\/span><\/p>\n<p><span style=\"color: #0000ff;\">find Videos\/ ! -name '[0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXZY]*'<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/<b>'Why in the World are They Spraying' <\/b>Documentary HD (multiple language subtitles).mp4<\/span><\/p>\n<p><span style=\"color: #ffffff;\">I found that file by elimination logic in the find command, but how would you escape the quote character to find that file \u2013 assuming you knew it existed? It cannot be escaped in the range box \u2013 it is seen as a delimiter itself so expects input!<\/span><\/p>\n<p><span style=\"color: #0000ff;\">find Videos\/ ! -name '[\\'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXZY]*'<\/span><\/p>\n<p><span style=\"color: #cc0000;\">&gt;<\/span><\/p>\n<p><span style=\"color: #ffffff;\">Going back to basics as at the start above using the \\ escape does it:<\/span><\/p>\n<p><span style=\"color: #0000ff;\">find Videos\/ -name \\'*<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/'Why in the World are They Spraying' Documentary HD (multiple language subtitles).mp4<\/span><\/p>\n<p><span style=\"color: #ffffff;\">Because the ASCII range of keys is keymap dependent, but POSIX lists the historcal map numerically as Shott states:<\/span><\/p>\n<p><span style=\"color: #ffffff;\">-<i>Back when Unix was first developed, it only knew about ASCII characters, and this fea-<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>ture reflects that fact. In ASCII, the first 32 characters (numbers 0-31) are control codes<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>(things like tabs, backspaces, and carriage returns). The next 32 (32-63) contain printable<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>characters, including most punctuation characters and the numerals zero through nine.<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>The next 32 (numbers 64-95) contain the uppercase letters and a few more punctuation<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>symbols. The final 31 (numbers 96-127) contain the lowercase letters and yet more punc-<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>tuation symbols. Based on this arrangement, systems using ASCII used a collation order<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>that looked like this:<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>This differs from proper dictionary order, which is like this:<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ...To support this ability, the POSIX standards introduced a concept called a locale, which<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>could be adjusted to select the character set needed for a particular location. We can see<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>the language setting of our system using this command:<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>[me@linuxbox ~]$ echo $LANG<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>en_US.UTF-8<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>With this setting, POSIX compliant applications will use a dictionary collation order<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>rather than ASCII order. This explains the behavior of the commands above. <b>A character<\/b><\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i><b>range of [A-Z] when interpreted in dictionary order includes all of the alphabetic char-<\/b><\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i><b>acters except the lowercase -a\u201d<\/b>, hence our results\u2026To partially work around this problem, the POSIX standard includes a number of character classes which provide useful ranges of characters.\u201d <\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\">I have only 1 file that starts with a lowercase -a\u201d:<\/span><\/p>\n<p><span style=\"color: #0000ff;\">find Videos\/ -name a*<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/<b>antigravity<\/b> hutchison effect.mp4<\/span><\/p>\n<p><span style=\"color: #ffffff;\">So, if my $LANG variable is POSIX compliant:<\/span><\/p>\n<p><span style=\"color: #0000ff;\">$LANG <\/span><\/p>\n<p><span style=\"color: #cc0000;\">en_GB.UTF-8: command not found<\/span><\/p>\n<p><span style=\"color: #ffffff;\">I should NOT find that one file with Shott's <i><b>[A-Z] \u2013 <\/b><\/i>and I don't \u2013 only the string\u00a0\"anti\"<i> <\/i><\/span><\/p>\n<p><span style=\"color: #0000ff;\">find Videos\/ -name '[A-Z]*' | grep anti<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/ILLUMINATI SECRETS - The New Atl<strong>anti<\/strong>s - FEATURE FILM.mp4<\/span><\/p>\n<p><span style=\"color: #0000ff;\">find Videos\/ -name '[A-Z]*' | wc -l<\/span><br \/>\n<span style=\"color: #ff0000;\">131<\/span><br \/>\n<span style=\"color: #0000ff;\">find Videos\/ -name '[a-Z]*' | wc -l<\/span><br \/>\n<span style=\"color: #ff0000;\">134<\/span><\/p>\n<p><span style=\"color: #ffffff;\">Knowing this, AND that the find command also sorts in a combo of inode order, it can be understood why there is apparent illogical alphabetical listing order; RRC; in the output, such as part of all the files here:<\/span><\/p>\n<p><span style=\"color: #0000ff;\">find Videos\/ -name '*'<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/Richplanet 2016 UK Tour - PART 2 OF 3.mp4<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/RP EP26 PT1.mp4<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/Crop Circles- The Hidden Truth - Part 4.mp4<\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i><b>Table 19-2: POSIX Character Classes<\/b><\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i><b>Character Class Description<\/b><\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>[:alnum:] The alphanumeric characters. In ASCII, equivalent to:<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>[A-Za-z0-9]<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>[:word:] The same as [:alnum:], with the addition of the underscore<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>(_) character.<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>[:alpha:] The alphabetic characters. In ASCII, equivalent to:<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>[A-Za-z]<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>[:blank:] Includes the space and tab characters.<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>[:cntrl:] The ASCII control codes. Includes the ASCII characters 0<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>through 31 and 127.<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>[:digit:] The numerals zero through nine.<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>[:graph:] The visible characters. In ASCII, it includes characters 33<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>through 126.<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>[:lower:] The lowercase letters.<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>[:punct:] The punctuation characters. In ASCII, equivalent to:<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>[-!\"#$%&amp;'()*+,.\/:;&lt;=&gt;?@[\\\\\\]_`{|}~]<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>[:print:] The printable characters. All the characters in [:graph:]<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>plus the space character.<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>[:space:] The whitespace characters including space, tab, carriage<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>return, newline, vertical tab, and form feed. In ASCII,<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>equivalent to:<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>[ \\t\\r\\n\\v\\f]<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>[:upper:] The uppercase characters.<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>[:xdigit:] Characters used to express hexadecimal numbers. In ASCII,<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>equivalent to:<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>[0-9A-Fa-f]<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>Remember, however, that this is not an example of a regular expression, rather it is the<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>shell performing pathname expansion\u2026.POSIX Basic Vs. Extended Regular Expressions<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>Just when we thought this couldn\u2019t get any more confusing, we discover that POSIX also<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>splits regular expression implementations into two kinds: basic regular expressions<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>(BRE) and extended regular expressions (ERE). The features we have covered so far are<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>supported by any application that is POSIX compliant and implements BRE. Our grep<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>program is one such program.<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>What\u2019s the difference between BRE and ERE? It\u2019s a matter of metacharacters. With BRE,<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>the following metacharacters are recognized:<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>^ $ . [ ] *<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>All other characters are considered literals. With ERE, the following metacharacters (and<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>their associated functions) are added:<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>( ) { } ? + |<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>However (and this is the fun part), the -(\u201d, -)\u201d, -{\u201d, and -}\u201d characters are treated as<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>metacharacters in BRE if they are escaped with a backslash, whereas with ERE, preced-<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>ing any metacharacter with a backslash causes it to be treated as a literal. Any weirdness<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>that comes along will be covered in the discussions that follow.\u201d<\/i><\/span><\/p>\n<p><span style=\"color: #0000ff;\">ls \/usr\/sbin\/[[:upper:]]*<\/span><\/p>\n<p><span style=\"color: #cc0000;\">\/usr\/sbin\/ModemManager \/usr\/sbin\/VBoxControl<\/span><\/p>\n<p><span style=\"color: #cc0000;\">\/usr\/sbin\/NetworkManager \/usr\/sbin\/VBoxService<\/span><\/p>\n<p><span style=\"color: #ffffff;\">Find can be used similarly. Find all files starting with a lower case letter:<\/span><\/p>\n<p><span style=\"color: #0000ff;\">find Videos\/ -name '[[:lower:]]*'<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/screencasts<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/hutchison effect wiki never before seen footage 3 25 2011.mp4<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/antigravity hutchison effect.mp4<\/span><\/p>\n<p><span style=\"color: #ffffff;\">Find all files NOT beginning with letters: <\/span><\/p>\n<p><span style=\"color: #0000ff;\">find Videos\/ ! -name '[[:alpha:]]*'<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/'Why in the World are They Spraying' Documentary HD (multiple language subtitles).mp4<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/9-11- Decade of Deception (Full Film NEW 2015).mp4<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/027 Richard Dolan Montreal - ModernKnowledge @ CapricornRadioTV.mp4<\/span><\/p>\n<p><span style=\"color: #ffffff;\">Same as [0-9] above:<\/span><\/p>\n<p><span style=\"color: #0000ff;\">find Videos\/ -name '[[:digit:]]*'<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/9-11- Decade of Deception (Full Film NEW 2015).mp4<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/027 Richard Dolan Montreal - ModernKnowledge @ CapricornRadioTV.mp4<\/span><\/p>\n<p><span style=\"color: #ffffff;\">Note complexity is required to NOT find either letters OR numbers = my\u00a0\"quote\" started file name:<\/span><\/p>\n<p><span style=\"color: #cc0000;\"><span style=\"color: #0000ff;\">find Videos\/ ! -name '[[:alpha:]]*' ! -name '[[:digit:]]*<\/span>'<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/'Why in the World are They Spraying' Documentary HD (multiple language subtitles).mp4<\/span><\/p>\n<p><span style=\"color: #ffffff;\">This can be simplified to a NOT alphanumeric range:<\/span><\/p>\n<p><span style=\"color: #0000ff;\">find Videos\/ ! -name '[0-9a-Z]*'<\/span><\/p>\n<p><span style=\"color: #0000ff;\">find Videos\/ -name '[!0-9a-Z]*'<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/'Why in the World are They Spraying' Documentary HD (multiple language subtitles).mp4<\/span><\/p>\n<p><span style=\"color: #ffffff;\">Find all files without white space anywhere in the name:<\/span><\/p>\n<p><span style=\"color: #0000ff;\">find Videos\/ ! -name '*[[:blank:]]*'<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/Irrefutable.mp4<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/RichDLoydPye.mp4<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/screencasts<\/span><\/p>\n<p>A really handy addition to the above for Linux systems is to rename all white spaced files without white space, say, for an MP3 collection, that show horrible looking Album\/Track names on the command line often;\u00a0using the -exec addition seen already in Cool Commands Posts:<\/p>\n<p><strong>BEFORE:<\/strong><\/p>\n<p><span style=\"color: #0000ff;\">ls \/Storebird\/MP3\/Candy\\ Dulfer\\ -\\ Sax-A-Go-Go\\ \\(74321_111812\\)\/Candy\\ Dulfer\\ \\ \\ -\\ 2\\ Funky.mp3<\/span><\/p>\n<p>run it for directories first:<\/p>\n<p><span style=\"color: #0000ff;\">find \/Storebird\/MP3\/ -type d -name '*[[:blank:]]*' -exec rename \"s\/ \/\/g\" {} +;<\/span><\/p>\n<p><strong>AFTER:<\/strong><\/p>\n<p><span style=\"color: #0000ff;\">ls \/Storebird\/MP3\/CandyDulfer-Sax-A-Go-Go\\(74321_111812\\)\/<\/span><\/p>\n<p>Re-run it for files:<\/p>\n<p><span style=\"color: #0000ff;\">find \/Storebird\/MP3\/ -type f -name '*[[:blank:]]*' -exec rename \"s\/ \/\/g\" {} +;<\/span><\/p>\n<p><span style=\"color: #0000ff;\">ls \/Storebird\/MP3\/CandyDulfer-Sax-A-Go-Go\\(74321_111812\\)\/CandyDulfer-2Funky.mp3<\/span><\/p>\n<p>You could then edit\u00a0and append these two lines to a simple shell script or alias to run on any directory you cd into e.g.:<\/p>\n<p><span style=\"color: #0000ff;\">find -type d -name \"*[[:blank:]]*\" -exec rename \"s\/ \/\/g\" {} +; <\/span><\/p>\n<p><span style=\"color: #0000ff;\">find -type f -name \"*[[:blank:]]*\" -exec rename \"s\/ \/\/g\" {} +;<\/span><\/p>\n<p><span style=\"color: #0000ff;\">vi ~\/rmspaces.sh<\/span><\/p>\n<p><a href=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2016\/07\/rmspaces.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-3800\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2016\/07\/rmspaces.png\" alt=\"rmspaces.png\" width=\"578\" height=\"114\" \/><\/a><\/p>\n<p><iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/dhR3i-GsHUk?autoplay=1&amp;version=3&amp;loop=1&amp;playlist=dhR3i-GsHUk\" width=\"560\" height=\"315\" frameborder=\"0\" align=\"left\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p><a href=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2016\/07\/candyd.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-3802\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2016\/07\/candyd.png\" alt=\"candyd.png\" width=\"704\" height=\"480\" \/><\/a><\/p>\n<p>term file searches are now tidy:<\/p>\n<p><a href=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2016\/07\/candynospace.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-3807\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2016\/07\/candynospace.png\" alt=\"candynospace.png\" width=\"730\" height=\"148\" \/><\/a><\/p>\n<p>To find and\/or remove any files beginning with undesirable chars like my \"quote\" file that may start with any of<\/p>\n<p><strong><i>[-!\"#$%&amp;'()*+,.\/:;&lt;=&gt;?@[\\\\\\]_`{|}~]<\/i><\/strong><\/p>\n<p><span style=\"color: #0000ff;\">find Videos\/ -name '[[:punct:]]*'<\/span><br \/>\n<span style=\"color: #ff0000;\">Videos\/'Why in the World are They Spraying' Documentary HD (multiple language subtitles).mp4<\/span><\/p>\n<p>That MP3 dir could have all those \"Windows\" legacy backslashes found\u00a0too eh..?<\/p>\n<p><span style=\"color: #0000ff;\">find -type d -name '*[[:punct:]]*'\u00a0<\/span><\/p>\n<p>Be safe and do the search check only FIRST before any\u00a0rename! Make sure it does what you want it to!<\/p>\n<p><span style=\"color: #ffffff;\">I'll quote Shott completely for this last important example:<\/span><\/p>\n<p><strong><span style=\"color: #ffffff;\">-<i>Finding Ugly Filenames With find<\/i><\/span><\/strong><\/p>\n<p><span style=\"color: #ffffff;\"><i>The find command supports a test based on a regular expression. There is an important<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>consideration to keep in mind when using regular expressions in find versus grep.<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>Whereas grep will print a line when the line contains a string that matches an expres-<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>sion, find requires that the pathname exactly match the regular expression. In the fol-<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>lowing example, we will use find with a regular expression to find every pathname that<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>contains any character that is not a member of the following set:<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>[-_.\/0-9a-zA-Z]<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>Such a scan would reveal path names that contain embedded spaces and other potentially<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>offensive characters:<\/i><\/span><\/p>\n<p><span style=\"color: #0000ff;\"><i>find . -regex '.*[^-_.\/0-9a-zA-Z].*'<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>Due to the requirement for an exact match of the entire pathname, we use .* at both ends<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>of the expression to match zero or more instances of any character. In the middle of the<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>expression, we use a negated bracket expression containing our set of acceptable path-<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\"><i>name characters.\u201d<\/i><\/span><\/p>\n<p><span style=\"color: #ffffff;\">It's easier for me to show the opposite, nicely named files in Videos, using that handy command, but negated:<\/span><\/p>\n<p><span style=\"color: #0000ff;\">find Videos\/ ! -regex '.*[^-_.\/0-9a-zA-Z].*'<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/Irrefutable.mp4<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/RichDLoydPye.mp4<\/span><\/p>\n<p><span style=\"color: #cc0000;\">Videos\/screencasts<\/span><\/p>\n<p><span style=\"color: #ffffff;\">The point to take from that example is that find supports specific regex and iregex options \u2013 see the man page. <\/span><\/p>\n<p><span style=\"color: #cc0000;\">-regex pattern<\/span><\/p>\n<p><span style=\"color: #cc0000;\"> File name matches regular expression pattern. This is a match<\/span><\/p>\n<p><span style=\"color: #cc0000;\"> on the whole path, not a search. For example, to match a file<\/span><\/p>\n<p><span style=\"color: #cc0000;\"> named `.\/fubar3', you can use the regular expression `.*bar.' or<\/span><\/p>\n<p><span style=\"color: #cc0000;\"> `.*b.*3', but not `f.*r3'. The regular expressions understood<\/span><\/p>\n<p><span style=\"color: #cc0000;\"> by find are by default Emacs Regular Expressions, but this can<\/span><\/p>\n<p><span style=\"color: #cc0000;\"> be changed with the -regextype option.<\/span><\/p>\n<p>That finds the weird file names in the mp3 folder for sure:<\/p>\n<p><span style=\"color: #0000ff;\"><span style=\"color: #ffffff;\">stevee@dellmint \/Quadra\/MP3 $<\/span> find . -regex '.*[^-_.\/0-9a-zA-Z].*'<\/span><\/p>\n<p><a href=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2016\/07\/regexmp3s.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-3812\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2016\/07\/regexmp3s.png\" alt=\"regexmp3s.png\" width=\"698\" height=\"743\" \/><\/a><\/p>\n<p>There are many album names with numbers enclosed in brackets () that can be found using:<\/p>\n<p><span style=\"color: #0000ff;\">find CandyD* -regex '.*[()]*'<\/span><\/p>\n<p><a href=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2016\/07\/candybraces.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-3816\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2016\/07\/candybraces.png\" alt=\"candybraces.png\" width=\"698\" height=\"471\" \/><\/a><\/p>\n<p>It's one thing to find them, but another to remove these brackets with their contents...<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_8890\" class=\"pvc_stats all  \" data-element-id=\"8890\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n<p>Regular expression metacharacters usage consist of the following: ^ $ . [ ] { } - ? * + ( ) | \\ These cannot be read about using the man pages for each symbol except the [ -test\u201d chars e.g: man ^ No manual entry for ^ These metacharacters can be read and expanded <a href=\"https:\/\/stevepedwards.today\/DebianAdmin\/exploring-find-cmd-options-continuing-with-metacharacters-2\/\" class=\"more-link\">...<span class=\"screen-reader-text\">\u00a0 Exploring Find Cmd Options \u2013 Continuing With Metacharacters<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-8890","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"a3_pvc":{"activated":true,"total_views":2,"today_views":0},"_links":{"self":[{"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/posts\/8890","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/comments?post=8890"}],"version-history":[{"count":0,"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/posts\/8890\/revisions"}],"wp:attachment":[{"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/media?parent=8890"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/categories?post=8890"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/tags?post=8890"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}