You can run, but you can’t hide… from “find”

9 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$49.99
List Price:  $69.99
You save:  $20
€46.42
List Price:  €64.99
You save:  €18.57
£39.83
List Price:  £55.77
You save:  £15.93
CA$68.34
List Price:  CA$95.68
You save:  CA$27.34
A$75.68
List Price:  A$105.96
You save:  A$30.28
S$67.48
List Price:  S$94.48
You save:  S$27
HK$390.53
List Price:  HK$546.78
You save:  HK$156.24
CHF 45.23
List Price:  CHF 63.33
You save:  CHF 18.09
NOK kr543.62
List Price:  NOK kr761.11
You save:  NOK kr217.49
DKK kr346.42
List Price:  DKK kr485.02
You save:  DKK kr138.59
NZ$83.17
List Price:  NZ$116.44
You save:  NZ$33.27
د.إ183.60
List Price:  د.إ257.06
You save:  د.إ73.45
৳5,471.12
List Price:  ৳7,660.01
You save:  ৳2,188.88
₹4,168.17
List Price:  ₹5,835.78
You save:  ₹1,667.60
RM236.95
List Price:  RM331.75
You save:  RM94.80
₦61,737.65
List Price:  ₦86,437.65
You save:  ₦24,700
₨13,922.21
List Price:  ₨19,492.21
You save:  ₨5,570
฿1,837.56
List Price:  ฿2,572.74
You save:  ฿735.17
₺1,617.36
List Price:  ₺2,264.43
You save:  ₺647.07
B$253.57
List Price:  B$355.02
You save:  B$101.45
R925.26
List Price:  R1,295.44
You save:  R370.18
Лв90.75
List Price:  Лв127.05
You save:  Лв36.30
₩67,788.68
List Price:  ₩94,909.58
You save:  ₩27,120.90
₪185.81
List Price:  ₪260.15
You save:  ₪74.34
₱2,852.60
List Price:  ₱3,993.87
You save:  ₱1,141.27
¥7,651.71
List Price:  ¥10,713.01
You save:  ¥3,061.30
MX$848.33
List Price:  MX$1,187.73
You save:  MX$339.40
QR182.01
List Price:  QR254.83
You save:  QR72.82
P679.12
List Price:  P950.82
You save:  P271.70
KSh6,605.16
List Price:  KSh9,247.76
You save:  KSh2,642.59
E£2,394.23
List Price:  E£3,352.12
You save:  E£957.88
ብር2,861.57
List Price:  ብር4,006.43
You save:  ብር1,144.85
Kz41,791.64
List Price:  Kz58,511.64
You save:  Kz16,720
CLP$47,104.79
List Price:  CLP$65,950.47
You save:  CLP$18,845.68
CN¥361.79
List Price:  CN¥506.53
You save:  CN¥144.74
RD$2,896.80
List Price:  RD$4,055.76
You save:  RD$1,158.95
DA6,728.30
List Price:  DA9,420.16
You save:  DA2,691.86
FJ$112.64
List Price:  FJ$157.70
You save:  FJ$45.06
Q387.49
List Price:  Q542.52
You save:  Q155.02
GY$10,429.06
List Price:  GY$14,601.52
You save:  GY$4,172.46
ISK kr6,980.60
List Price:  ISK kr9,773.40
You save:  ISK kr2,792.80
DH502.81
List Price:  DH703.98
You save:  DH201.16
L883.05
List Price:  L1,236.34
You save:  L353.29
ден2,855.74
List Price:  ден3,998.26
You save:  ден1,142.52
MOP$401.24
List Price:  MOP$561.77
You save:  MOP$160.53
N$922.79
List Price:  N$1,291.99
You save:  N$369.19
C$1,835.15
List Price:  C$2,569.36
You save:  C$734.20
रु6,656.11
List Price:  रु9,319.09
You save:  रु2,662.97
S/186.09
List Price:  S/260.54
You save:  S/74.45
K192.70
List Price:  K269.79
You save:  K77.09
SAR187.48
List Price:  SAR262.50
You save:  SAR75.01
ZK1,344.69
List Price:  ZK1,882.68
You save:  ZK537.98
L230.99
List Price:  L323.40
You save:  L92.41
Kč1,163.34
List Price:  Kč1,628.77
You save:  Kč465.43
Ft18,094.88
List Price:  Ft25,334.28
You save:  Ft7,239.40
SEK kr539.27
List Price:  SEK kr755.02
You save:  SEK kr215.75
ARS$43,903.33
List Price:  ARS$61,468.17
You save:  ARS$17,564.84
Bs345.22
List Price:  Bs483.33
You save:  Bs138.11
COP$194,164.52
List Price:  COP$271,845.87
You save:  COP$77,681.34
₡25,478.72
List Price:  ₡35,672.25
You save:  ₡10,193.53
L1,231.47
List Price:  L1,724.16
You save:  L492.69
₲373,200.63
List Price:  ₲522,510.75
You save:  ₲149,310.11
$U1,910.59
List Price:  $U2,674.97
You save:  $U764.38
zł200.97
List Price:  zł281.37
You save:  zł80.40
Already have an account? Log In

Transcript

10S of projects, hundreds of folders and thousands of files. Does this scenario sound familiar? If the answer is yes, then you probably found yourself more than once in a situation where you couldn't find a specific file. The find command will help us locate any file in our project, and much more. But first, for creating a quick playground. Let's download the electron open source project.

For this we use git clone. And now we CD into it change directory. We see here lots of different files and folders, just like in any normal sized software project. In order to find a particular file, let's say packaged package dot JSON. We will use this command the first argument Where should find search, in this case in the current folder, and the second argument is the file name to search for. And of course, the file name.

If we were to look for all read README files in the current project, the previous command format is not helpful. We need to issue a case insensitive find for demonstration purposes, we will also create a readme.md file with our cheat in our created and use this argument for case insensitive search. Okay, you see here that both readme.md and big uppercase readme.md have been found. Now, if we were to search for all JavaScript files, we would use find with these arguments, and as you can see, there are quite a few results. For narrowing down our results. Let's limit the fight to the Default app folder.

Okay, as you can see, there are only two GS files in this folder. And if we were to find all files that are not JavaScript, just add an exclamation mark before the name argument like this. You can see here all files that don't end their name with JavaScript. If we were to look for all the nodes in the directory, which are of type file, we would use this arc. And in the same way, with this one, we find all directories in a specific location. Find can also locate files based on time identifiers.

For example, in order to find all files in the you user shared directory that were modified in the last 24 hours, issue the following command and on My computer at the time of this recording I have quite a big list. Using m time modified time broadens the list even more. If we were to find for example all the files modified in the last hour, we can use modifying minimum 60 minutes. This good folder to search is slash local slash share. If we use mean, modify minimum, 90 minutes the least broadens again. Fine can also show us the list of files accessed in the less than four hours by using the access time Minus one argument like so.

While working with lots of project files, it is sometimes the case that some project remains empty and we forget to delete it. In order to locate all empty files, just do a find. Minus empty. And as we can see electron has a few empty files. Find will also show us empty directories or links. Removing empty files will keep our project clean.

But when it comes to reducing size, we sometimes want to know which files are taking up most of the space. As we said in the beginning, find can do much more than locating files in our project. Using the exec argument it can be combined with almost any other command, which gives it almost infinite capabilities. For example, if we want to find all JavaScript files that can be In the text manager, we can combine find with grep like so. This will execute the grep command on all files returned by find. Let's also search inside the file using vim so that we verified the result is correct.

As you can see, the text manager appears in this file. Moving on with the practical examples, let's say you have a folder where you want to remove all the files modified in the last 100 days. We can see our default app folder contains such files. So if we combine fine with remove like so we can do a quick cleanup. Find the can be used for Smart backups. For example, if we were to backup all JSON files in the project, we would combine find with the CPO backup utility using a pipe and a standard output redirection.

Sound sounds complex, but it isn't just check this command CPU sounds like Star Wars snake. We can see that in this command, we created a backup dot CPU o file of type CPU and archive. Now this could probably have been written with exec also but it's critical you understand that pipes can be can also be used in this type of scenarios to gather with redirects. When you're doing reports, you may have to count the numbers of lines written. In order to do this, we combine fun With a word count, like this, this will give us all JavaScript files and the number of designs. We can pipe this to cat.

Here we go to only output the number of lines and then pipe to the paste command, we do this. This will merge all our lines with a plus sign as a delimiter. This of course can be translated to an arithmetic operation, which we can calculate using the binary calculator. Here we go, long line. And this last command will tell us how many lines our JavaScript files contain. Of course, these are not actual lines of code as they can be empty lines, or comments.

For precise calculation of lines of code. You can use this lock utility In order to mass rename files like changing the file extension name to note for all JavaScript files, we can use this command. You can see the Rename syntax is quite similar to set. And there are no more JavaScript files left because they have all been renamed to the suffix note. Some software projects require all source code files to have a copyright header. As this is not required in the beginning, oftentimes we can find ourselves in the situation that we have to add copyright information in the beginning of all our files.

In order to do this we can combine find with said like this. Why this is basically doing is telling the computer to find all node files and add the copyright notice in the beginning of each file, followed by a new line. We can check one random file. And yes, the copyright notice is there. As you can imagine, find has lots of use cases. The examples I've shown you are only the first piece of the pie.

Learning find along with set and the Jeet Creek can set you free from your EDA, when it comes to finding refactoring or working with git, which means you can more easily switch from one either to the other because you don't have to learn all the features. You just use your friendly CLI tools

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.