April 30, 2011

Finding the memory usage of a process

I recently needed to figure out how to determine the memory usage of a process so I could log it over time. I used the following command to accomplish this.

mike@shiner $ ps -p 7557 -o pid,vsz,rss
  PID      VSZ    RSS
 7557  1983664 298536

You'll need to replace '7557' with the process id you're investigating. The meaning of 'VSZ' and 'RSS' is copy and pasted here from the man page:

     rss        resident set size
     vsz        virtual size in Kbytes (alias vsize)

'RSS' represents the amount of memory resident in RAM. The rest of the memory is held in swap space or the filesystem. 'VSZ' is the amount of virtual memory allocated to the process.

April 26, 2011

Moving multiple files

I recently learned that you can move multiple files in one invocation of mv. As long as the last argument is a directory, then all the previous files/directories will be moved into it.

mike@shiner $ mv one.txt two.txt three.txt foobar

If the last argument isn't a directory, then you'll see an error.

mike@shiner $ mv one.txt two.txt three.txt 
mv: target `three.txt' is not a directory

April 5, 2011

How to convert Unix timestamps

It's been a long *time* since my last post, hence I thought I'd do a post that involves time. I often run into the situation where I have a Unix timestamp and I need to determine the date. You can use the following to do this.

mike@shiner $ date -d @1252278000
Sun Sep  6 19:00:00 EDT 2009

The following shows how to get the Unix timestamp for a particular moment in time.

mike@shiner $ date -d "2009-09-06 19:00:00" "+%s"
1252278000