Unix find command to locate a file
I see what you meant Marcus. Show 1 more comment. Active Oldest Votes. Improve this answer. Thx — purityKEF. Add a comment. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. The pattern in this case is Apple. So we print the first two lines as shown in the below screenshot:.
Similarly, use the —B flag to print the line before a matching pattern. In this example, we are using the grep —B1 with pattern 4 grep —B1 4 filename. See the command below:. Note that, instead of A1 or B1 you can use any positive integer number with the dash —A or—B flag. It will print that number of lines after and before the matching pattern.
Lastly, the —A and —B i. Skip to content Search for: Search Close. Close Menu. Thank you for reading this post. Kindly share it with others. Connect with D. I allow to create an account. When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.
Disagree Agree. Notify of. Inline Feedbacks. Next Entry Microsoft Purchases Ally. The find command will begin looking in the starting directory you specify and proceed to search through all accessible subdirectories. You may specify more than one starting directory for searching. By default, multiple options are joined by "and". You may specify "or" with the -o flag and the use of grouped parentheses.
To match all files modified more than 7 days ago and accessed more than 30 days ago, use:. You may specify "not" with an exclamation point. This next example is similar, but here I use the -i argument to the grep command, telling it to ignore the case of the characters string , so it will find files that contain string , String , STRING , etc.
When these files are found, their permission is changed to mode rw-r--r This find command searches through the htdocs and cgi-bin directories for files that end with the extension. When these files are found, their permission is changed to mode rwxr-xr-x. This example shows that the find command can easily search through multiple sub-directories htdocs , cgi-bin at one time:.
From time to time I run the find command with the ls command so I can get detailed information about files the find command locates. That's nice, but what if I want to see the last modification time of these files, or their filesize?
No problem, I just add the ls -ld command to my find command, like this:. The "-l" flag of the ls command tells ls to give me a "long listing" of each file, while the -d flag is extremely useful in this case; it tells ls to give me the same output for a directory.
Normally if you use the ls command on a directory, ls will list the contents of the directory, but if you use the -d option, you'll get one line of information, as shown above. Be very careful with these next two commands. If you type them in wrong, or make the wrong assumptions about what you're searching for, you can delete a lot of files very fast. Make sure you have backups and all that, you have been warned.
0コメント