Archive for March, 2010


Get disk usage from the command line (du and df)

March 10, 2010

the du command can be used to get the size of files or directories from the command line. The usual usage is:

du -h

This will tell you how much disk space is being used by everything in the current directory. The -h stands for ‘human readable’ which one would have thought would be the default but exists for legacy reasons. The default behaviour without -h is to display the number of blocks taken up by the files.

To see the size of each file in a directory use:

du -h *

To see the disk usage statistics for all mounted drives you can use the df command which provides the amount of space in total, how much is used and how much is left. Its useful as it also provides the percentage used:

df -h


Groups on the Linux Command Line

March 9, 2010

Something I always forget how to do is create a new group on the command line and then add users to it. It is important to get these commands right as a missed option can really screw up the permissions for your user!

To create a new group called subversion:

sudo groupadd subversion

To add user foo to this group do:

usermod -a -G subversion foo

Missing the -a from the last command means foo will ONLY be a member of the subversion group, all other group associations are dropped.



March 9, 2010

Tried using screen today to share a terminal between two developers. This is useful for running background tasks where more than one person wants to check the output occasionally.

One user starts up a screen session and then grants the other user access to it.

To run screen run:

screen -S ScreenSessionName

Where ScreenSessionName can be anything you like.

From within the screen session you can now hit Ctrl^a followed by typing

:multiuser on

Now you can grant access to other users on the same system by typing

:acladd user2

Where user2 is the login name of the other user.  That person can now connect to the same terminal session by typing:

screen -x user1/ScreenSessionName

Where user1 is the login name of the first person who created the screen session.  With both of you in the terminal you can see what the other is typing. To leave the session at any time hit Ctrl^a Ctrl^d.You can reconnect with the screen session by typing:

screen -r user1/ScreenSessionName

When you want to terminate the screen hit Ctrl^a k (Thats Control and a, then release control and hit the k key).

To see what screen sessions are active on a system you can use the command:

screen -ls