Sign up to create your own snipts, or login.

Public snipts » find The latest public find snipts.

showing 1-20 of 39 snipts for find
  • convert cPanel accounts after activating suPHP
    #!/bin/bash
    
    # Script must be run by a user with access to all accounts, their files and folders
    
    # Known limitation:
    # - handles only sites located in /account/public_html/, so it won't work for
    #   websites in /account/public_html_other/ or /account/public_html/other/
    
    # the root is the folder that contains all your account folders
    # default is pwd (Parent Working Directory)
    rootDir=`pwd`
    
    # accounts' webroot foldername
    webRoot="public_html"
    
    # loop through folders in current folder
    for i in $(find . -type d -maxdepth 1 -mindepth 1); do
        echo .................
        accountName=${i:2}
        echo Account: ${accountName}
    
        # check if folder has a webroot subfolder
        if [ -d $rootDir/$accountName/$webRoot ]; then
            cd $rootDir/$accountName/$webRoot
    
            # change owner for all files and folders in webroot
            chown -R $accountName:nobody *
    
            # change access for all files in current account's webroot
            find . -type f -exec chmod 0644 {} \;
    
            # change access for all folders in current account's webroot
            find . -type d -exec chmod 0755 {} \;
    
            echo Owner and file/dir access was changed for files/dirs in webroot
    
            $accountWebRoot=$rootDir/$accountName/$webRoot
        
            # Deactivate the Joomla FTP-layer where needed
            if [ -e $accountWebRoot/configuration.php ]; then
        
                cp $accountWebRoot/configuration.php $accountWebRoot/configuration_backup.php
        
                searchStr="ftp_enable = '1'"
                replaceStr="ftp_enable = '0'"
        
                sed "s/${searchStr}/${replaceStr}/g" <$accountWebRoot/configuration_backup.php >$accountWebRoot/configuration.php
        
                echo configuration.php was processed: Joomla FTP layer deactivated
            else
                echo configuration.php was not found for this account
            fi
    
        else
            echo a webroot was not found for this account, so no changes were done
        fi
    done
    

    copy | embed

    0 comments - tagged in  posted by torkil on Mar 16, 2010 at 8:20 a.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
  • awk find access_log
    awk '$1~/THINGYOUWANT/' /var/www/vhosts/*/statistics/logs/access_log | head
    
    #or for all occurrences use below, head only prints top 10 lines
    
    awk '$1~/THINGYOUWANT/' /var/www/vhosts/*/statistics/logs/access_log
    

    copy | embed

    0 comments - tagged in  posted by AvidDeville on Sep 04, 2009 at 3:34 p.m. EDT
  • delete a symfony module
    $find . -path '*/.svn' -prune -o -type f -print | grep -i work | xargs svn --force rm
    

    copy | embed

    0 comments - tagged in  posted by tayhimself on Aug 13, 2009 at 10:00 a.m. EDT
  • Find mypage.htm current dir and subdirs
    find -name 'mypage.htm'
    

    copy | embed

    0 comments - tagged in  posted by dorseye on Aug 10, 2009 at 9:51 p.m. EDT
  • Example of how to use memchr and memset
      const int size = 100;
      const char val = 23;
      char* p = malloc(size);
      char* q;
    
      memset(p, 0, size);
      p[42] = val;
      q = memchr(p, val, size);
      printf("element at pos:%d with val:%d\n", q-p, *q);
      free(p);
    

    copy | embed

    0 comments - tagged in  posted by OutOfBrain on Jul 14, 2009 at 5:01 p.m. EDT
  • http://find-guru.com
    Find Guru connects Teachers and Students in a unique way facilitating knowledge transfer and mentor ship through the internet.
    
    
    http://find-guru.com
    

    copy | embed

    1 comment - tagged in  posted by findguru on May 21, 2009 at 2:07 a.m. EDT
  • Copy the contents of a directory to another one preserving permissions and properly handling special files
    find <SOURCE_DIR> -xdev -print0 | cpio -pa0V <DESTINATION_DIR>
    

    copy | embed

    0 comments - tagged in  posted by d1s4st3r on Apr 20, 2009 at 2:53 a.m. EDT
  • Remove .svn directories recursively
    find -name .svn -delete
    

    copy | embed

    0 comments - tagged in  posted by wvega on Apr 16, 2009 at 5:28 p.m. EDT
Sign up to create your own snipts, or login.