Which options of the find command can you use to locate files owned by a particular user
The find command in UNIX is a command line utility for walking a file hierarchy. It can be used to find files and directories and perform subsequent operations on them. It supports searching by file, folder, name, creation date, modification date, owner and permissions. By using the ‘-exec’ other UNIX commands can be executed on files or folders found. Show Syntax : $ find [where to start searching from] [expression determines what to find] [-options] [what to find] Options :
Examples : Consider the following tree hierarchy : 1. Search a file with specific name. $ find ./GFG -name sample.txt It will search for sample.txt in GFG directory. Output :
2. Search a file with pattern. $ find ./GFG -name *.txt It will give all files which have ‘.txt’ at the end. Output :
3. How to find and delete a file with confirmation. $ find ./GFG -name sample.txt -exec rm -i {} \; When this command is entered, a prompt will come for confirmation, if you want to delete sample.txt or not. if you enter ‘Y/y’ it will delete the file. Output :
4. Search for empty files and directories. $ find ./GFG -empty This command find all empty folders and files in the entered directory or sub-directories. Output :
5. Search for file with entered permissions. $ find ./GFG -perm 664 This command find all the files in the GFG directory or sub-directory with the given permissions. Output :
6. Search text within multiple files. $ find ./ -type f -name "*.txt" -exec grep 'Geek' {} \; This command print lines which have ‘Geek’ in them and ‘-type f’ specifies the input type is a file. Output :
?list=PLqM7alHXFySFc4KtwEZTANgmyJm3NqS_L To use the find . -name "pattern" -print Replace OptionsThe general form of the command is: find (starting directory) (matching criteria and actions) The You have several options for matching criteria:
You can use
By default, multiple options are joined by "and". You may specify "or" with the \( -mtime +7 -atime +30 \) To match all files modified more than 7 days ago or accessed more than 30 days ago, use: \( -mtime +7 -o -atime +30 \) You may specify "not" with an exclamation point. To match all files ending in \! -name notme.txt -name \*.txt You can specify the following actions for the list of files that the
Executed commands must end with -exec ls -l {} \; Matching criteria and actions may appear in any order and are evaluated from left to right. Full examples
For more, consult the Unix manual page by entering at the Unix prompt: man find Some of the above information came from Essential System Administration, Aeleen Frisch (O'Reilly & Associates, Inc., 1991). Related documents This is document admm in the Knowledge Base. How do you find a file owned by a particular user in Linux?You need to use the find command to search for files in a directory hierarchy.. directory-location : Locate files or directories in this directory location.. -user { user-name } : Find the file belongs to user.. -name {file-name} : File name or pattern.. Which command is used for locating files?The locate command is a Unix utility used for quickly finding files and directories. The command is a more convenient and efficient alternative to the find command, which is more aggressive and takes longer to complete the search.
What are different search options available for a file in find command?The find command in UNIX is a command line utility for walking a file hierarchy. It can be used to find files and directories and perform subsequent operations on them. It supports searching by file, folder, name, creation date, modification date, owner and permissions.
What is the command to find a specific file in Linux?Basic Examples. find . - name thisfile.txt. If you need to know how to find a file in Linux called thisfile. ... . find /home -name *.jpg. Look for all . jpg files in the /home and directories below it.. find . - type f -empty. Look for an empty file inside the current directory.. find /home -user randomperson-mtime 6 -iname ".db". |