Latest Updates: linux

  • Kill a GNU Screen Session from the Command Line

    17:48 on January 4, 2010 | 1 Comments Tweet This! | Digg This!
    Tags: , linux,

    This article is about GNU Screen – you can read about GNU Screen here: http://www.gnu.org/software/screen/

    There may be times when you have multiple, or even a single, screen session which you want to kill without attaching to it and ending it as you normally would.

    You can kill a screen session using the session ID or the name (if the name is unique enough).

    Warning: Both ways end all processes within the screen session, so if you have any open files/applications, make sure you don’t need/want them – they’ll be kill’d along with the session.

    Killing by session ID

    First, run screen -list to get the id of the current sessions (we use the id to kill the screen session)

    daz@scampi:~$ screen -list
    There are screens on:
    11493.irssi     (04/01/10 16:25:44)     (Detached)
    30784.newapps   (01/01/10 19:42:38)     (Detached)

    As you can see in this example, I have two sessions, a session called “irssi” with id 11493, and a session called “newapps”, with an id of 30784.

    So, to kill the “newapps” session, I’d run:

    daz@scampi:~$ screen -X -S 30784 kill
    daz@scampi:~$

    .. and the session will now be gone.  You can verify that by running screen -list again.

    Killing by session name

    If your screen session name is unique enough (for example, if you have one called “newapps” and another called “irssi” as per my example) you can kill by name:

    daz@scampi:~$ screen -X -S newapps kill
    daz@scampi:~$

    The reason I say unique enough –  if you have a session called “newapps” and one called “newapps1″, you will need to use the ID to end “newapps” before “newapps1″ – you’ll simply be asked to specify the session again otherwise.

     
  • Removing packages only installed as dependancies and no longer needed (Ubuntu, Debian)

    20:00 on January 3, 2010 | 0 Comments Tweet This! | Digg This!
    Tags: linux,

    We’ve all installed packages, using apt-get, where it’s installed a lot of other packages to satisfy dependancies.

    But what if you remove that package at a later date that needed all of those dependancies?  You’ll probably find it’s left the dependancies installed.. and if you’ve not installed any other packages which also need those dependacies, they’re just taking up hard drive space.

    It’s easy to remove them, though – after all, you no longer need them so why keep them?

    The command is simple (and needs to be run as root):

    apt-get autoremove

    … and that’s it.  The man page entry for this command:

    “autoremove is used to remove packages that were automatically installed  to satisfy dependencies for some package and that are no more needed.”

    So the next time you install a package which needs lots of dependancies, and you decide you want to remove it for whatever reason, remember to run apt-get autoremove afterwards!

    Warning: You do need to be careful when running this – always check which packages it’s proposing to uninstall before confirming.  I have seen reports of random packages being removed, breaking the entire system – even though it is an officially supported feature of apt-get, and it can be very useful, use it with caution.

     
  • Finding out when (and where from) a user last logged into a Linux/BSD machine

    00:21 on January 2, 2010 | 0 Comments Tweet This! | Digg This!
    Tags: , linux,

    There may be times when you want to find out when and where from a user last logged into a Linux or BSD machine.

    Of course, you could trawl through auth logs, but there is a quicker way by using “lastlog“.

    lastlog is a command which shows you the last login time and also from where (if it was a remote session, it’ll show you the IP/Hostname) a user logged in.

    If you log into the machine and at a terminal run, you’ll get the information:

    droptips@server:~$ lastlog
    Username         Port     From             Latest
    root                                       **Never logged in**

    (I’ve removed all of my information for security reasons)

    There is a man page available for “lastlog” accessible via:

    droptips@server:~$  man lastlog

    You can also read the Ubuntu 9.10 man page for lastlog here: http://manpages.ubuntu.com/manpages/karmic/man8/lastlog.8.html
    The Wikipedia page is here:  http://en.wikipedia.org/wiki/Lastlog