IMPORTANT!

Snipt is going open source. We've toyed with this idea for quite a while, and have finally decided it's the right way to move forward.

A few things:
  • The entire Snipt source code will be released on GitHub under the 3-clause BSD License on Friday, September 10th.
  • While we'd like to think we're perfect, we realize we're only human. By open sourcing the software that runs this website, certain bugs or security flaws may be discovered that could compromise the privacy of your snipts.
  • Only the Lion Burger team will be able to push commits to the Snipt.net site. Contributors should send a pull request to add new features or submit patches.
  • By using this site, you agree not to be too angry or take any legal action against Lion Burger should this whole thing go up in flames some day.
  • Follow us on Twitter for updates.
I agree, close this message
Sign up to create your own snipts, or login.

Latest 100 public snipts » find The latest public find snipts.

showing 1-20 of 46 snipts for find
  • Hide 'Permission denied' messages for find cmd
    find . -name 'foobar' 2>/dev/null
    

    copy | embed

    0 comments - tagged in  posted by hallmark on Aug 22, 2010 at 9:11 p.m. EDT
  • 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;
    

    copy | embed

    0 comments - tagged in  posted by malkir on Jul 28, 2010 at 10:30 p.m. EDT
  • 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;
    }
    

    copy | embed

    0 comments - tagged in  posted by wafflesncheese on Jul 18, 2010 at 10:03 a.m. EDT
  • Recursively find text in files
    find . -name "*.html" -exec grep -i -H " keyword(s) " {} \; >> ~/output/to/file.txt
    

    copy | embed

    0 comments - tagged in  posted by rendrag on Apr 29, 2010 at 2:56 p.m. EDT
  • 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]; 
    		}
    	}
    
    };
    

    copy | embed

    0 comments - tagged in  posted by jj09 on Apr 20, 2010 at 3:59 p.m. EDT
  • Find the most recently changed files recursively
    find . -type f -printf '%TY-%Tm-%Td %TT %p\n' | sort
    

    copy | embed

    0 comments - tagged in  posted by d1s4st3r on Apr 09, 2010 at 10:18 a.m. EDT
  • 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!
    

    copy | embed

    0 comments - tagged in  posted by corbanb on Apr 01, 2010 at 3:44 p.m. EDT
  • 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!
    

    copy | embed

    0 comments - tagged in  posted by corbanb on Apr 01, 2010 at 3:39 p.m. EDT
  • 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
    

    copy | embed

    0 comments - tagged in  posted by d1s4st3r on Feb 25, 2010 at 1:02 p.m. EST
  • 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;
    }
    

    copy | embed

    0 comments - tagged in  posted by saravanansaravanan on Jan 31, 2010 at 9:47 p.m. EST
  • 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 {} \;
    

    copy | embed

    0 comments - tagged in  posted by d1s4st3r on Jan 27, 2010 at 12:59 p.m. EST
  • 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 }' 
    

    copy | embed

    0 comments - tagged in  posted by abecker on Dec 17, 2009 at 11:35 a.m. EST
  • 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.
    

    copy | embed

    0 comments - tagged in  posted by rschu68 on Dec 02, 2009 at 11:13 a.m. EST
  • 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";
    }
    

    copy | embed

    0 comments - tagged in  posted by rschu68 on Nov 25, 2009 at 7:11 a.m. EST
  • 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(' .
    

    copy | embed

    0 comments - tagged in  posted by hongster on Nov 12, 2009 at 9:34 p.m. EST
  • Search file by content.
    find . -type f | xargs grep 'public static void main('
    

    copy | embed

    0 comments - tagged in  posted by hongster on Nov 11, 2009 at 5:49 a.m. EST
  • recursive command to perform sudo actions
    // linux: recursive command to perform sudo actions
    
    find . -print  | sed -e 's/^/\"/' -e 's/$/\"/' | xargs sudo ...
    

    copy | embed

    0 comments - tagged in  posted by robertbanh on Nov 08, 2009 at 7:35 p.m. EST
  • find and xargs with spaces
    $find . -type f -print0 | xargs -0 wc -l
    

    copy | embed

    0 comments - tagged in  posted by tayhimself on Oct 23, 2009 at 7:02 p.m. EDT
  • 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
    

    copy | embed

    0 comments - tagged in  posted by malkir on Oct 07, 2009 at 10:17 p.m. EDT
  • watch a find/rm in action as it moves through thousands of files
    watch -n .5 "ps auxwwf | egrep 'find|rm'"
    

    copy | embed

    0 comments - tagged in  posted by malkir on Sep 18, 2009 at 10:02 p.m. EDT
Sign up to create your own snipts, or login.