![]() -exec wc: We’re going to execute the wc command on the filenames that are matched with the search string.-type f: We’re only looking for files, not directories.-name “*.page”: We’re looking for files with names that match the “*.page” search string.The find command is recursive by default, so subdirectories will be searched too. : Start the search in the current directory. The command is made up of these elements. This will count the words in the matching files. We can use ls to see the archive file that is created for us. The tar utility will create an archive file called “page_.” tar -cvzf page_: This is the command xargs is going to feed the file list from find to. ![]() xargs -o: The -0 arguments xargs to not treat whitespace as the end of a filename.This means that that filenames with spaces in them will be processed correctly. Directories will not be listed because we’re specifically telling it to look for files only, with -type f. The print0 argument tells find to not treat whitespace as the end of a filename. name “*.page” -type f -print0: The find action will start in the current directory, searching by name for files that match the “*.page” search string. The command is made up of different elements. name "*.page" -type f -print0 | xargs -0 tar -cvzf page_ We’ll run this command in a directory that has many help system PAGE files in it. This is a long-winded way to go about it, but we could feed the files found by find into xargs, which then pipes them into tar to create an archive file of those files. We can use find with xargs to some action performed on the files that are found. That’s “almost the same” thing, and not “exactly the same” thing because there can be unexpected differences with shell expansions and file name globbing. This achieves almost the same thing as straightforward piping. It is more lightweight and doesn’t force any changes to the filesystem when they are unneeded.To address this shortcoming the xargs command can be used to parcel up piped input and to feed it into other commands as though they were command-line parameters to that command. And identify which files will need to have their ownership changed. This command easily helps you determine if your permissions are set correctly. Some sample output would look like this./logs/access.log.2016_09_30.03.gz - user:root group:web “%u” and “%g” output the user and group of the file that is found. “%p” outputs the filename and relative directory structure. The final section ‘-printf “%p – user:%u group:%g\n”‘ tells find how to output the results. Changing that to “-and” would only show files that are not owned by the “web” user or group. The “-or” tells the find command to match files that are either not owned by the “web” user or group. Then “! -user web” specifies that it should check for files that are NOT “!” owned by the “web” user. The “! -group web” section tells the find command to check for files that are NOT “!” owned by the “web” group. The find command searches from the “.” current directory and recursively checks all files and folders. ! -group web -or ! -user web -printf "%p - user:%u group:%g\n" The command was created using some help from this site and this site. ![]() But without forcing a change to the ownership, which seemed to possibly be the cause of the hanging process. But it lead me to craft a command that would allow the client to easily check permissions on their files. After some lengthy research I am still stumped as to exactly what the source of the issue is. These files were shared between a few web servers on an NFS share. However the hung chown command would cause extra load on the server and lead to system instability. The chown was to ensure that all the files were writable and wouldn’t gum up the git process. As a result of the chown they would periodically see the process hang. The issue came up because a client would run a recursive chown on a directory before running git. And find files that were not owned by a specific user or group. Recently ran into an issue where I needed to search recursively through a file structure.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |