Recursive chmod distinguishing files from folders

Version 3 An even better method is: find “$target” -type f -exec chmod -c “$mode_files” {} \; \ -or -type d -exec chmod -c “$mode_dir” {} \; A true one-liner! 😀 Version 2 A better method is this: find “$target” -type f -exec chmod -c “$mode_files” {} \; find “$target” -type d -exec chmod -c “$mode_dir” {} \; This one can also be used from the command line. Version 1

Continue reading

Recursive file/directory change-detection

Disclaimer This article explores a way in which an approximate “fingerprint” of a file tree can be created! If all you want is to detect file changes a much more appropriate method would be to use inotify/incron. Version 2 (update) Another, much faster method would be to use ls -lR to browse over the filesystem. On a newly installed Debian virtual machine (on Xen) hashing the entire filesystem (the root

Continue reading

Detect number of CPUs on a machine

UPDATE: Steven pointed out (very nicely) that there’s no need for cat in this picture, grep would do just fine on its own. So, thanks Steven! Detect how many CPU cores are present on the running machine: grep -c processor /proc/cpuinfo This can be very useful when writing multi-threaded programs to properly match the number of threads with the number of CPU cores.

Continue reading