increase your productivitya lot in UNIX based operating system, e.g. Redhat Linux or Solaris. If you are a QA, support personnel, and your works involve lots of searching text on Linux machine or if you are a Java or C++ programmer and your code resides in UNIX, find command can significantly help you to look for any word inside your source file in the absence of an IDE. It is the alternative way of searching for things in UNIX; grep is another Linux command which provides similar functionality like find but in my opinion, later is much more potent than grep in UNIX. Like any other command strength to find lies in its various options, which is worth learning, but, to be frank, hard to remember. If you can be even able to remember all the options mentioned in this article, you will be taking much more advantage of the find command than average developers, QA, support people, and Linux users. By the way, I have been sharing my experience on Unix and Linux command, and its different options, usage, and example, and this article are in continuation of my earlier post like
how to convert an IP address to the hostname in Linux. If you are new here, you may find these tips useful for your day-to-day development and support work.
10 Tips on find command in UNIX
1. How to run last executed find command in UNIX!find will repeat the last find command executed. It saves a lot of time if you re searching for something, and you need to run the same command again and again.
Bash Shell Scripting: Crash Course For Beginners. A short course that provides enough information to make most out of bash shell. And if you don't have time for an online course, then following bash tricks from Julia Evans is the best you can have. Just knowing these tips will improve your speed and productivity in Linux.
2. How to find files that have been modified less than one day, minute, or hour in Linux
find -mtime is used to search files based upon modification time. This is, in fact, my favorite find command tips while looking out some production issues just to check which files have been modified recently, could be likely cause of the issue, believe me, it helps a lot and many times gives you enough hint of any problem due to intended or unintended file change. Along with –mtime, there are two more options related to time, find -atime, which denotes the last accessed time of the file and find –ctime denotes last changed time. The + sign is used to search for greater than, - sign is used to search for less than and without a sign is used for exact. For example, find –mtime -1 will search all files which have been modified.
javin@testenv1 ~/java : find . -mtime -1 (find all the files modified less than 1 day)../StockTrading.java
javin@testenv1 ~/java : find . -mtime +1 (find all the files modified more than 1 day)./.vimrc./OnlineStockTrading.java./StockTrading.java~
3. How to find all the files and directories which hold the 777 permission in UNIX
file and directory permission in Unixand some
chmod examplesto change permissions in Unix.
Learn Linux in 5 Days and Level Up Your Career, another excellent course for anyone who wants to work in Linux. And, if you don't have time for class, the following diagram from none other than Julia Evans is again a great one to refresh your concepts about file permissions in Linux.
4. Case insensitive search using find in UNIX
UNIX Interviews, and interviews often asked questions during interviews on both system admin and application developer jobs.
UNIX find and xargs command Example
xargscan be used to do whatever witch each file found by find command, for example, we can delete that file, list content of that file or can apply any comment on that file.
5. How to delete temporary files using find command in UNIXIn order to delete files, you can use either –delete option of find command or use xargs in combination. It's better to create housekeeping script for such task which can perform cleanup on a periodic basis.
whitespacein the path when piping to xargs (use with the xargs -0 option) as suggested by Ebon Elaza.
6. How to find all text file which contains word Exceptionfind . –name "*.java" –print | xargs grep “MemoryCache”, this will search all java files starting from the current directory for the word "MemoryCache". We can also leave -print option in all cases because its default for UNIX finds command as pointed out by Ben in comments. You can further sort the result of find command using
Sort command in Unix.
7. Finding files only in the current directory not searching on subdirectoriesWhile using the find command, I realized that sometimes I only need to
find files and directoriesthat are new, only in the current directory, so I modified the find command as follows. You can use find –type option to specify the search for the only file, link, or directory, and -maxdepth option specifies how deep find command has to search.
Linux Command Line Interface (CLI) Fundamentalscourse on Pluarlsight.
Example 8 – How to find files based on the size in Unix and LinuxThe following find example shows how you can use find –size options to
find files based upon a certain size. This will find all files in current directory and sub-directory, greater than some size using find command in UNIX:
find commandas in below example of find:
Example 9 – How to find files some days older and above a specific sizeWe can combine –mtime and –size to find files which are some days old and greater than some size in Unix. A prevalent scenario where you want to delete
some large old files to free some spacein your machine. This example of find command will find which are more than 10 days old and size greater than 50K.
10) Find and AWKYou can use "awk" in a combination of find to print a formatted output, e.g. next command will find all of the
symbolic linksin your home directory, and print the files your symbolic links points to:
Tip: $* : $* is one of the
special bash parameters which is used to expands positional parameters from position one.
How to use find command on filenames with space in UNIX
xargs: WARNING: a NUL character occurred in the input. It cannot be passed through in the argument list. Did you mean to use the --null option?
ls: cannot access ./cash: No such file or directoryls: cannot access equity: No such file or directoryls: cannot access trading: No such file or directory
The Linux Command Line: A Complete Introduction, a great book, and must-read for any programmer, tester, system administrator, security guy or developers, who work on UNIX and Linux based environment.
5 free Linux coursesto start your journey into the beautiful world o Linux command line.
Essential points about find command in UNIX and Linux
P. S. - If you want to learn Linux from scratch and looking for some free resources, then you can also check out this list of
free Linux courses for Programmers and Developers. It contains some of the free online courses from Udemy, Pluralsight, and Coursera to learn Linux online.
My friend circle has a lot of programmers and non-programmers. When it comes to buying
Guys, It's a fun time here, as Holidays are approaching, it's Movie time for many of us. Being a computer programmer, I love movies which are based on programmers life, wor..
Would You Try Programmable Pasta? - Seeker 2018-06-09 00:00
Men's Humor Photo 2018-06-08 22:59
Simply tag a Black Panther fan in this post and click the link below to get your free jersey!🔥🔥🔥
ICC - International Cricket Council Photo 2018-06-08 22:19
ICC - International Cricket Council
REPORT ➡️ http://bit.ly/WIvsSL1Report3