Latest 100 public
snipts » find
showing 1-20 of 46 snipts for find
-
∞ Hide 'Permission denied' messages for find cmd
find . -name 'foobar' 2>/dev/null -
∞ Find/replace on specific and all domain level
Single domain: domainName=DOMAIN.COM; outFile=JSOUT`date +%s`; cd ~/domains/$domainName; curFile=`pwd | sed "s~.*\(/domains/.*\)~\1/~"`; for x in `find . -type f -perm -u+r -name "*.js" -o -name "*.min" -o -name "*.min.js" -o -name "*.html" | egrep -v JSBAK`; do if grep -q "var st1 = 0;document.write(unescape" $x; then echo $x >> $outFile; sed -i.JSBAK "s~var\ st1\ =\ 0;document\.write(unescape('[0-9A-Z%]*'));var\ gr0=0;~~" $x; fi; done; if [ -f $outFile ]; then sed "s~\.\(.*\)~$curFile\1~g" $outFile; echo ""; sed "s~\.\(.*\)~$curFile\1.JSBAK~g" $outFile; rm $outFile; else echo "No files found"; fi; All domains: outFile=JSOUT`date +%s`; cd ~/domains/; for x in `find . -type f -perm -u+r -name "*.js" -o -name "*.min" -o -name "*.min.js" -o -name "*.html" | egrep -v JSBAK`; do if grep -q "var st1 = 0;document.write(unescape" $x; then echo $x >> $outFile; sed -i.JSBAK "s~var\ st1\ =\ 0;document\.write(unescape('[0-9A-Z%]*'));var\ gr0=0;~~" $x; fi; done; if [ -f $outFile ]; then sed "s~\.\(.*\)~/domains\1~g" $outFile; echo ""; sed "s~\.\(.*\)~/domains\1.JSBAK~g" $outFile; rm $outFile; else echo "No files found"; fi;
-
∞ find stl
#include <iostream> #include <vector> using namespace std; int main() { vector<string>myvector; vector<string>::iterator it; myvector.push_back("LOL"); myvector.push_back("Whaaaaaaatt?!"); myvector.push_back("Hmm."); myvector.push_back("Okay."); myvector.push_back("AEIOU"); it=find(myvector.begin(),myvector.end(),"AEIOU"); if (it!=myvector.end()) cout<<"Found!"; else cout<<"Not found!"; return 0; }
-
∞ Recursively find text in files
find . -name "*.html" -exec grep -i -H " keyword(s) " {} \; >> ~/output/to/file.txt
-
∞ UF
class UF { private: int *id, *sz; int find(int x) { while (x != id[x]) x = id[x]; return x; } public: UF(int N) { id = new int[N]; sz = new int[N]; for (int i = 0; i < N; i++) { id[i] = i; sz[i] = 1; } } int find(int p, int q) { return (find(p) == find(q)); } void unite(int p, int q) { int i = find(p), j = find(q); if (i == j) return; if (sz[i] < sz[j]) { id[i] = j; sz[j] += sz[i]; } else { id[j] = i; sz[i] += sz[j]; } } };
-
∞ Find the most recently changed files recursively
find . -type f -printf '%TY-%Tm-%Td %TT %p\n' | sort -
∞ Find and Replace Function
function strReplace(str:String, search:String, replace:String):String { return str.split(search).join(replace); } var str:String = "Hello World!"; str = strReplace(str, "Hello", "Goodbye"); trace(str); //outputs Goodbye World!
-
∞ RegEx - Find and Replace
var str:String = "Hello World!"; var myPattern:RegExp = /Hello/g; //regex to remove all hellos str = str.replace(myPattern, "Goodbye"); trace(str); // Goodbye World!
-
∞ Massive operations on files containing spaces in their names
# This example shows how to copy all the files located in the "name" # directory to the "dest" directory taking care of the white spaces # in the filenames, if any. find ${path} -name "${name}" | while read i do cp "$i" ${dest} done
-
∞ phone bok using find
#include <iostream> #include <map> #include <string> using namespace std; int main() { map<string,int> map1; map1.insert(map<string,int>::value_type("john",94324219)); map1.insert(map<string,int>::value_type("jack",62343234)); map1.insert(map<string,int>::value_type("jill",36352342)); map1.insert(map<string,int>::value_type("jane",29967324)); map1.insert(map<string,int>::value_type("tom",19887678)); map1.insert(map<string,int>::value_type("sue",83547324)); map1.insert(map<string,int>::value_type("bob",40335609)); cout<<"Initial contents in map:\n"; map<string,int>::iterator p; for(p = map1.begin();p != map1.end();p++) cout<< p->first <<" "<< p->second <<endl; while(1) { cout<<"Enter name to search :"; string name; cin>>name; p=map1.find(name); if(p==map1.end()) cout<<"name"<<name<< "not found in map1"; else cout<<" " <<p->first<<" "<< p->second <<endl; } return 0; }
-
∞ Recursively change permissions to directories only
# This example sets permissions 600 to directories only recursively. # To do the same with files instead of directories, simply put a "!" before "-type". find . -type d -exec chmod 600 {} \;
-
∞ Locate Large Files on Linux
Finds all files over 20,000KB (roughly 20MB) in size and presents their names and size in a human readable format. Replace "find /" with desired directory: find / -type f -size +20000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }' -
∞ Consider using find and xargs
Consider using find and xargs for doing something across a group of files without risking breaking your script because you're operating on too many files (shell wildcard expansion has limits). Using GNU find and xargs: http://hacktux.com/bash/file find . -name '*.foo' -type f -print0 | xargs -0I {} ~/bin/my-script '{}' will run "/bin/my-script" on all files (-type f) whose name ends in ".foo" in the current working directory (the dot after the find command) and every directory therein (find is recursive unless you tell it not to be). When you make /bin/my-script all you need to do is describe how to process one file. find will normally print the list of matching files with a newline. Here we tell find to use NULLs to terminate each list entry (-print0) you can handle pathnames with spaces and other characters that break most scripts. The -0 tells xargs what to use to know where each filename ends. Just don't forget to quote properly in your script (called /bin/my-script here) so the complete pathname is preserved. I'm also telling xargs where each filename is in the command (-I {} says to use the open/close curly brace as a placeholder for the pathname). This is optional if the last argument to the command is the pathname. -
∞ find broken links
Find broken symlinks: #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~# http://www.zulustips.com/2007/01/26/how-to-find-broken-symlinks.html # obliterate single-quotes from file names find $SOME_DIRECTORY -iname “*’*” -print0 | xargs -0 rename tr/\’//d # Function to find and remove bad links from files that don’t have single quotes in their names find $SOME_DIRECTORY -type l -print0 | xargs -0 -I ‘{}’ sh -c “[ -e ‘{}’ ] || rm -f ‘{}’” or symlinks -dr / # Recurse and delete broken links starting from / http://linuxgazette.net/issue65/tag/5.html find . -type l ! -exec test -e {} \; -print0 | xargs -0 rm http://www.commandlinefu.com/commands/view/954/find-broken-symlinks #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~# # simple function to clean out borken symbolic links based on my old blgrep.sh # script from when the amarok PBI broke the amarok ports installation. clean_homedirs() { rm /Programs/$PROGDIR/<linked files> for BL in `ls -F "$1" | grep "@" | sed "s/@//g" 2> /dev/null`; do DEL=$(file /tmp/foo | egrep ".*broken symbolic link to .*" \ | awk '{print $1}' | sed -e 's/://g') echo MSG: Removing: $DEL unlink $DEL done } http://forums.pcbsd.org/viewtopic.php?f=33&t=11158 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~# find . -maxdepth 1 -type l -printf '%l\n' -o -type f -print -o -type d -print http://stackoverflow.com/questions/130329/how-do-you-get-what-a-symbolic-link-points-to-without-grep #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~# #!/usr/bin/perl use strict; while(chomp(my $file = <>)) { while(-l $file) { $file = readlink $file; } print "$file\n"; } -
∞ Search file by content (improved)
grep -r 'public static void main(' . #will do the same thing. In fact, you can also use grep -rI 'public static void main(' . #for searching only text files. And if you only want to list the files without the matching content, use grep -rI –files-without-matches 'public static void main(' .
-
∞ Search file by content.
find . -type f | xargs grep 'public static void main(' -
∞ recursive command to perform sudo actions
// linux: recursive command to perform sudo actions find . -print | sed -e 's/^/\"/' -e 's/$/\"/' | xargs sudo ...
-
∞ find and xargs with spaces
$find . -type f -print0 | xargs -0 wc -l -
∞ find files modified within the last 30 mins - (could be +30 for over 30 mins, or 30 for exactly 30 mins)
find /var/www/ -cmin -30
-
∞ watch a find/rm in action as it moves through thousands of files
watch -n .5 "ps auxwwf | egrep 'find|rm'"


