Linux One Liner – Finding Stuff

Let’s say you created a file in your home directory but can’t work out which directory you put it in.

<br /> $ find ~ -name somefile.txt<br />

You can replace ~ (tilda) with a directory e.g. / (slash) for search all locations on your system.

Let’s say you want to find all the JPEG’s you have.
<br /> $ find ~ -name "*.jpg"<br />

Now to improve on this, I know I put a JPEG somewhere in the past few days, give me just the files from the past 3 days.
<br /> $ find . -name "*.jpg" -mtime -3<br />

And what if you only wanted files greater then 2MB
<br /> $ find . -name "*.jpg" -mtime -3 -size +2M<br />

If you want to look at a more detailed listing of the files found, like the format you are familar with using ls, try this.
<br /> $ find . -name "*.jpg" -mtime -3 -exec ls -l {} ;<br />

You can find more then files, lets find all the directories you have.
<br /> $ find ~ -type d<br />

I haven’t added it, but historically you needed to add -print on the end to print the results, seems nowadays this is optional.

I briefly used the -exec option above, I used it for various purposes. Here are a few.
<br /> $ find /backup-location -name "backup.*.tar.gz" -mtime +3 -print -exec rm -f {} ;<br /> $ find . -name CVS -exec rm -rf {} ;<br />

The first I run against my backup directory, that removes the online backups older then 3 days. Of course I’ve also got offline backups.
The second is when I checkout stuff from CVS and I want to prune all the CVS information. NOTE: Using the rm -rf command is very dangerous, you should only use this when you know your stuff. Used in the wrong way you delete everything, if you don’t have backups, there ain’t any UNDO in Linux. Also if you do it as root, you can effectively kill your installation in a split second.

There are other commands that perform various level of finding (e.g. commands via path) and other various stuff. A topic for another time, but to entice you.

<br /> $ which find<br /> $ whereis find<br /> $ locate find<br />

Tagged with: General Linux One Liners

Producing IQR and Outlier statistics with SQL

The interquartile range (IQR) measures the spread of the middle 50% of a distribution — the distance between the first quartile (Q1) and the third quartile (Q3). Combined with Tukey’s 1.

Producing Mode statistics with SQL

The mode is the value or values that appear most frequently in a dataset. Unlike the mean or median, it applies naturally to categorical and ordinal data — star ratings, product codes, survey responses — and reveals what is most common, not what is average.

Extending MySQL Capabilies with UDFs, Plugins and Components - Part 2

MySQL offers three different approaches to extending the SQL capabilities with the default product you download and install. These are: User Defined Function (UDF) MySQL Manual MySQL Plugin MySQL Manual MySQL Component MySQL Manual In my prior post I provided a new uuidv function that accepted a numeric argument to return a string of the version of UUID specified.