Thegeekscope.com find files-in_linux_using_find_command
Upcoming SlideShare
Loading in...5
×
 

Thegeekscope.com find files-in_linux_using_find_command

on

  • 551 views

In Linux, find Command is used to search for specific files and folders. The beauty of the linux find command lies in its ability to perform complex searches. Find command provides plenty of options ...

In Linux, find Command is used to search for specific files and folders. The beauty of the linux find command lies in its ability to perform complex searches. Find command provides plenty of options to specify size, modification date, type, owner, permission while performing a search operation.

This article describes some of the most useful options availble with the linux find command with the help of examples.

For more articles like this, visit www.thegeekscope.com

Statistics

Views

Total Views
551
Views on SlideShare
550
Embed Views
1

Actions

Likes
0
Downloads
2
Comments
0

1 Embed 1

http://twitter.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Thegeekscope.com find files-in_linux_using_find_command Thegeekscope.com find files-in_linux_using_find_command Document Transcript

  • thegeekscope.com http://w w w .thegeekscope.com/find-files-in-linux-using-find- command/Find Files in Linux using Find CommandIn Linux, find Command is used to search for specific files and folders. The beauty of the linux findcommand lies in its ability to perform complex searches. Find command provides plenty of options tospecify size, modification date, type, owner, permission while performing a search operation.This article describes some of the most useful options availble with the linux find command with thehelp of examples.Find Files Based on Filename PatternSyntax: find <SEARCH_PATH> -type [f|d] -name "<PATTERN>"type ‘f’ indicates that search for filestype ‘d’ indicates that search for directories The Geek ScopeExample: Search for files in the /root folder which contains the string “monitor” in the filename # find /root -type f -name "*monitor*" /root/monitor_script.sh /root/monitor_script.sh.v2 /root/monitor_script.sh.v1Example: Search for folders in the /root folder which contains the string “monitor” in the foldername # find /root -type d -name "*monitor*" /root/test/test_monitor123Example: Search for files/folders in the /root folder which contains the string “monitor” in the name # find /root -name "*monitor*" /root/test/test_monitor123 /root/monitor_script.sh /root/monitor_script.sh.v2 /root/monitor_script.sh.v1 www.thegeekscope.com
  • Find Files Based on Modification Time in DaysSyntax: find <SEARCH_PATH> -mtime <x> Integer <x> indicates days <x> along with ‘+’ sign indicates, modified before x days <x> along with ‘-’ sign indicates, modified within last x days <x> with no sign indicates, modified exactly x days agoExample: Search /etc folder for files/folders modified exactly 7 days ago # find /etc -mtime 7Example: Search /etc folder for files/folders modified before 7 days # find /etc -mtime +7 The Geek ScopeExample: Search /etc folder for files/folders modified in last 7 days # find /etc -mtime -7You can use ‘atime‘ in place of ‘mtime’ to find files and folders based on last access time in days.Example: Search /etc folder for files/folders accessed in last 7 days # find /etc -atime -7Find Files Based on Modification Time in MinsSyntax: find <SEARCH_PATH> -mmin <x> Integer <x> indicates minutes www.thegeekscope.com
  • <x> along with ‘+’ sign indicates, modified before x mins <x> along with ‘-’ sign indicates, modified within last x mins <x> with no sign indicates, modified exactly x mins agoExample: Search /home folder for files/folders modified exactly 60 minutes ago # find /home -mmin 60Example: Search /home folder for files/folders modified before 60 minutes # find /home -mmin +60Example: Search /home folder for files/folders modified in last 60 minutes # find /home -mmin -60You can use ‘amin‘ in place of ‘mmin’ to find files and folders based on last access time in mins. The Geek ScopeExample: Search /etc folder for files/folders accessed in last 60 mins # find /etc -amin -60Find Files Based on SizeSyntax: find <SEARCH_PATH> -size <x>Integer <x> indicates size in bytes/kilobytes/megabytes/gigabytes <x> along with ‘+’ sign indicates size larger than x <x> along with ‘-’ sign indicates size smaller than x <x> with no sign indicates, size exactly equal to xExample: Search /etc folder for files/folders having size exactly equal to 20015 bytes www.thegeekscope.com
  • # find /etc -size 20015cExample: Search /root folder for files/folders having size greater than 2 megabytes # find /etc -size +2MExample: Search /home folder for files/folders having size less than 1 kilobytes # find /etc -size -1kFind Files Based on PermissionsSyntax: find <SEARCH_PATH> -perm <permission>Example: Search /etc folder for files/folders with permission 755 (read,write,execute for owner andread,execute for group owner and others) The Geek Scope # find /etc -type f -perm 664Find Empty files and FoldersSyntax: find -emptyExample: Find all empty files/folders available in a system # find / -emptyFind Files Owned by a Specific UserSyntax: find <SEARCH_PATH> -user <username> www.thegeekscope.com
  • Example: Find all files/folders owned by user ‘kam’ # find / -user kamFind Files Owned by a Specific GroupSyntax: find <SEARCH_PATH> -group <groupname>Example: Find all files/folders owned by group account ‘projectx’ # find / -group projectxUse ‘-and’ and ‘-or’ qualifier to join search patternsExample: Search /root folder for files/folders modified in last 7 days and having size less than 200kB The Geek Scope # find /etc -mtime -7 -and -size -200kExample: Search /home folder for files/folders accessed in last 2 hours or having size greater than10MB # find /etc -amin -120 -or -size +10MTagged as: Find Command, Find Files, Find files in LInux, Find files in Unix, Linux Find Command,Search Files, Using Find Command www.thegeekscope.com