Handy Linux tricks with find

I often find the need to delete files of a particular size. Instead of viewing files in a graphical interface, arranging by size and then picking the ones to delete, there is an easier way. This is taken from the following SE posts:


As mentioned there, the + or - prefixes are neither documented in the man pages nor within info. So in order to find files greater than 10MB but less than 100MB, use this:

find  .  -size +10M -size -100M  -exec rm -f  -- {} \;

The syntax of why the backslash and semi-colon is required is described here: semi-colon within find. The double-dash (--) tells the getopt interpreter that rm uses to ignore anymore options, and so allow deletion of filenames that begin with a dash(-). (Why would anyone have filenames like those👺: rm with special characters)

Alternatively, you could use xargs for the deletion.

find  .  -print0  -size +10M -size -100M  |  xargs  -0 rm -f  --

The arguments “-print0” and “-0” are required to interpret files with spaces in the names correctly. (find and xargs).

If you want to list all files based on their modification times, use this:

find  .  -type f  -mtime 0

will show all files in your current directory modified (or created) within the past 24 hours. If you’d like find to count from the beginning of today (rather than 24 hours ago), use the option “-daystart” before any time options.

The same + or - prefixes can be used here to limit the search to strictly greater/less than conditions.

ps: David Wheeler has written an excellent article on the ridiculous use of certain characters in POSIX filenames: No Sharp Corners

Linux file attributes and creation time :)

I didn’t know about the Linux ‘chattr‘ command which allows you to display and set file attributes. Using this, I learnt a neat trick on how to make a file immutable, even by the root user.

To make a file immutable, do:

chattr +i <filename>

To remove the immutable attribute, do:

chattr -i <filename>

To list the current file attributes, do:

lsattr foo/bar

It’s that simple 😎

This will change only the ctime for the file, and not its mtime. (details here: ctime vs mtime). Another interesting thing, in th Raspberry Pi context, is the atime file information. Essentially, atime should reflect the last time a file has been accessed. However, this is not very useful and only serves to increase the number of writes to a partition, every time a file is accessed. This is a dampener for performance esp. in embedded systems. Hence, on the Raspberry Pi, we mount partitions with the “noatime” attribute within fstab.

In Linux, the file creation time didn’t exist until the ext4 filesystem appeared. ctime originally did mean creation time, but it always reflected the time when a file’s metadata was changed (attributes, permissions, etc). With ext4, the creation time was stored in the file’s inode, under the field ‘crtime’. In order to get a file’s creation time we need to lookup the file’s inode, and the use stat and debugfs to find the required field. debugfs is required since there still doesn’t exist any kernel API to get crtime from stat. (birth time)

ls -i <filename>
debugfs -R 'stat <inode_number>' /dev/sdNN

(replace sdNN with the actual path to the device where the file resides). Look the the ‘crtime‘ field in the output.

Linux Scheduler

The default Linux process scheduler is the Completely Fair Scheduler (CFS). To change the default for Raspberry Pi, change the ‘elevator’ kernel parameter within /boot/cmdline.txt.

By default, it’ll have “elevator=deadline”. You can change deadline to noop or cfq. However, the default seems to be the best for interactive performance.

Things I’ve been reading about


  • Rvalue reference and move semantics
  • perfect forwarding, noexcept
  • ‘auto’, for-loop by range
  • initializer lists, lambdas


  • asynchronous calls, callbacks, events
  • AJAX requests, JSONP, Cross-origin Resource Sharing (CORS)
  • closures

Google Apps Script, CSS/Bootstrap

ABI, vtables, stack padding, C++ name mangling  …

My head is spinning 😱


Apple Macbook Multi-output audio


I was trying to watch John Oliver with my fiance today and we had the eternal problem of 2 people trying to share a pair of headphones. I had a Bluetooth headset too and I wondered if we could stream audio over both these. Voila! Someone had already worked out this neat trick here:


The last part about about sending output to a particular device is done by going into System Preferences > Sound > Output and selecting the multi-output device there.

Who calls your main()?

I was curious as how to a C program in executed by the OS and came across this interesting article:

Create your C library
The file “crt0” is created during the linking stage, which sets up the working environment and finally calls the main() within the program. The  _start function is able to set up the standard library, call the global constructors, and call exit(main(argc, argv)).

Bash shell tricks

The bash shell has so many nifty tricks. They can come in handy in order to save time with repeated tasks, recover data, etc.

1. My set of customizations for bash can be found on github. With those customizations, you can make find easier, colorize diff, man and prevent clobbering when using output redirection. I especially love the colored man pages.

2. If you want to sudo-ize the previous command, use;

sudo !!

3. rename utility: I never knew this! It makes renaming multiple files using regex patterns so much easier!

4. In scripts, instead of the awkard test command ‘[‘, use ‘(( … ))’ and ‘[[ … ]]’ in its place. It makes logical and string comparison so much easier. (ref: modern bash test operators)

Some more examples can be found here: bash trick commands

There are also some intricacies like the difference between rm and unlinkrm vs unlink

Feel free to suggest more in your comments.

Note: The file .bashrc is not loaded by bash at startup, by default. So it must be included in either the file .profile or .bash_profile.