{"id":782,"date":"2018-07-01T18:23:47","date_gmt":"2018-07-01T15:23:47","guid":{"rendered":"http:\/\/leonidassavvides.com\/blog\/?p=782"},"modified":"2018-07-01T18:23:47","modified_gmt":"2018-07-01T15:23:47","slug":"find-linux-command-tricks-asked-in-exams-and-how-to-write","status":"publish","type":"post","link":"https:\/\/www.leonidassavvides.com\/blog\/2018\/07\/find-linux-command-tricks-asked-in-exams-and-how-to-write\/","title":{"rendered":"find Linux command tricks asked in exams and how to write"},"content":{"rendered":"<div style=\"margin-top: 0px; margin-bottom: 0px;\" class=\"sharethis-inline-share-buttons\" ><\/div><p style=\"text-align: center;\"><strong>find<\/strong> Linux command tricks asked in exams and how to write<\/p>\n<p style=\"text-align: center;\">======================<\/p>\n<pre><span style=\"color: #00ff00;\"><strong>A\n<\/strong><\/span>\nThe <strong>find<\/strong> Operators <strong>(!, -o, and -a)<\/strong>\nThere are three operators that are commonly used with <strong>find<\/strong>. The <strong>! operator<\/strong> is used\nbefore an option to negate its meaning. So,\n<strong>\nfind . ! -name \"*.c\" -print<\/strong>\n\nselects all but the C program files.<\/pre>\n<pre><strong><span style=\"color: #00ff00;\">B<\/span><\/strong><\/pre>\n<pre>To look for both <strong>shell<\/strong> and <strong>perl<\/strong> scripts, use the <strong>-o operator<\/strong>, which represents an <strong>OR condition<\/strong>. \nWe need to use an escaped pair of parentheses here:<\/pre>\n<pre><strong>find \/home \\( -name \"*.sh\" -o -name \"*.pl\" \\) -print<\/strong>\n\n<em>The ( and ) are special characters that are interpreted by the shell to run commands in<\/em>\n<em>a group<\/em>. The <em>same characters are used by find to group expressions using<\/em> the\n<strong>-o and -a operators<\/strong>, the reason why they need to be escaped.<\/pre>\n<pre><strong><span style=\"color: #00ff00;\">C<\/span><\/strong><\/pre>\n<pre>Also to find all *.sh (shell scripts) files for user tux execute:<\/pre>\n<pre><strong>find \/home -user \"tux\" -name \"*.sh\" -print \nfind \/home -user \"tux\" -name \"*.sh\" -exec ls {} &gt;| file.txt \\; # write listing in file.txt \n\nthese two commands  are equivalent to these two &gt;&gt;&gt;\n\nfind \/home \\( -user \"tux\" -a -name \"*.sh\" \\) -print\nfind \/home \\( -user \"tux\" -a -name \"*.sh\" \\) -exec ls {} &gt;| file.txt \\; # write listing in file.txt \n\nI conclude in some commands use find for finding:\n\nDirectories with sticky bit set:\nfind \/ -type d -perm -1000 -exec ls -ld {} \\;\n\nFiles with SGID set:\nfind \/ -type f -perm -2000 -exec ls -l {} \\;\n\nFiles with SUID set:\nfind \/ -type f -perm -4000 -exec ls -l {} \\;\n\nFiles with SUID and SGID set:\nfind \/ -type f \\( -perm -4000 -a -perm -2000 \\) -exec ls -l {} \\;\n\nFiles with SUID or SGID set:\nfind \/ -type f \\( -perm -4000 -o -perm -2000 \\) -exec ls -l {} \\;\n\n\n<a href=\"https:\/\/www.leonidassavvides.com\/blog1\/wp-content\/uploads\/2018\/07\/2018-07-07_08-08-45-find-exp.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-795\" src=\"https:\/\/www.leonidassavvides.com\/blog1\/wp-content\/uploads\/2018\/07\/2018-07-07_08-08-45-find-exp.png\" alt=\"\" width=\"759\" height=\"709\" srcset=\"https:\/\/www.leonidassavvides.com\/blog\/wp-content\/uploads\/2018\/07\/2018-07-07_08-08-45-find-exp.png 759w, https:\/\/www.leonidassavvides.com\/blog\/wp-content\/uploads\/2018\/07\/2018-07-07_08-08-45-find-exp-300x280.png 300w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/a>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nNote:\nALL THESE COMMANDS - IF NOT WORK - MAKE THE APPROPRIATE SPACING eg  \\( -user \"tux\" like exactly I write<\/strong><\/pre>\n<p>Further Reading Resources<\/p>\n<p><a href=\"https:\/\/likegeeks.com\/linux-command-line-tricks\/\">https:\/\/likegeeks.com\/linux-command-line-tricks\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>find Linux command tricks asked in exams and how to write ====================== A The find Operators (!, -o, and -a) There are three operators that are commonly used with find. The ! operator is used before an option to negate its meaning. So, find . ! -name &#8220;*.c&#8221; -print selects all but the C program &hellip; <a href=\"https:\/\/www.leonidassavvides.com\/blog\/2018\/07\/find-linux-command-tricks-asked-in-exams-and-how-to-write\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;find Linux command tricks asked in exams and how to write&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[],"class_list":["post-782","post","type-post","status-publish","format-standard","hentry","category-tech"],"_links":{"self":[{"href":"https:\/\/www.leonidassavvides.com\/blog\/wp-json\/wp\/v2\/posts\/782","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.leonidassavvides.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.leonidassavvides.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.leonidassavvides.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.leonidassavvides.com\/blog\/wp-json\/wp\/v2\/comments?post=782"}],"version-history":[{"count":0,"href":"https:\/\/www.leonidassavvides.com\/blog\/wp-json\/wp\/v2\/posts\/782\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.leonidassavvides.com\/blog\/wp-json\/wp\/v2\/media?parent=782"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.leonidassavvides.com\/blog\/wp-json\/wp\/v2\/categories?post=782"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.leonidassavvides.com\/blog\/wp-json\/wp\/v2\/tags?post=782"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}