Technomancy

Entries tagged “cli”

Show which directories have the most files (regardless of size)

written by rory, on Jan 21, 2010 11:51:00 AM.

I was rsync-ing a directory to remote host using an old version of rsync, so it had to count all the files on my local machine before it could start copying (newer versions of rsync start copying before reading all the files). However this was a large directory tree, with thousands and thousands of files, and it was taking rsync a long time to count. There are tools like ncdu to show how much disk space each folder is using. However in this case I want to reduce the number of files, regardless of their size, so ncdu is useless to me.

This bash snippet will show how many files & directories are in each folder, with the most 'populous' directories at the bottom.

find | cut -d/ -f2 | uniq -c | sort -n

Running a programme overnight and don't want to hear noisy fans?

written by rory, on Jul 9, 2009 10:48:00 PM.

I want to run a long running CPU intensive programme overnight. However I don't want to hear the noisy CPU fans. The more the CPU is used, the hotter it gets and hence the fans turn on to cool it down. The usual way to limit how much a process runs is by using nice. However there won't be any process running, so it will use as much CPU as is available. Mostly this is what you want.

cpulimit (available in ubuntu), is a programme to limit what percent of CPU a process gets. It does this my constantly pausing and resuming it so that it only runs a certain amount of times per second.

This solves my problem completly, since I can limit a process to only having 15% of the CPU time. The rest of the time the CPU will be idle, so it will be cooler, so it will be quieter.

After installing it, just find the process you want to limit. then do a

cpulimit -p $PID -l $SOMEPERCENTAGE
and it'll limit that process right away.