Business web hosting - The structure of the UNIX directory tree sometimes

The structure of the UNIX directory tree sometimes makes locating files and commands difficult. To locate a file, often you need to search through a directory and all its subdirectories. The easiest way to do this is to use the find command: find dir -name file -print Here dir is the name of a directory where find should start its search, and file is the name of the file it should look for. The name option of the find command also works with the standard filename substitution operators covered in Chapter 8. For example, the command find dir -name “*txt” -print displays a list of all the files in the directory dir and all its subdirectories that end with the string txt. How can I grep for a string in every file in a directory? When you work on a large project involving many files, remembering the contents of the individual files becomes difficult. It is much easier to look through all the files for a particular piece of information. You can use the find command in conjunction with the xargs command to look for a particular string in every file contained within a directory and all its subdirectories: find dir -type f -print | xargs grep “string” Here dir is the name of a directory in which to start searching, and string is the string to look for. Here you specify the -type option to the find command so that only regular files are searched for the string. How do I remove all the files in a directory matching a particular name? Some editors and programs create large numbers of temporary files. Often you need to clean up after these programs, to prevent your hard drive from filling up. To generate the list of files to delete, you can use the find command. Most of the time you can combine the find command with the xargs command, but in this case the filenames can contain one or more spaces. Spaces can confuse the xargs command, so you need to use a for loop instead: OLDIFS=”$IFS” IFS=’ ‘ for FILE in find . -type f -name “*string*” -print do rm “$FILE” done IFS=”$OLDIFS” Here string is a string that should be part of the name of each file you want to delete. So that the for loop is set to the correct value of FILE in each iteration, IFS needs to be set to the newline character.
If you are looking for cheap and quality webhost to host and run your website check Jboss Web Hosting services.

Leave a Reply