Public
snipts » find
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
-
∞ 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'" -
∞ 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
-
∞ delete a symfony module
$find . -path '*/.svn' -prune -o -type f -print | grep -i work | xargs svn --force rm
-
∞ Find mypage.htm current dir and subdirs
find -name 'mypage.htm' -
∞ 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);
-
∞ 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 the contents of a directory to another one preserving permissions and properly handling special files
find <SOURCE_DIR> -xdev -print0 | cpio -pa0V <DESTINATION_DIR>
-
∞ Remove .svn directories recursively
find -name .svn -delete



MySQL Cookbook