Tag Archives: linux

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

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

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

Viewing Another Users’ Crontab Entries in Ubuntu, Debian or CentOS

There may be occasions where you, as the administrator of a machine, may want to see what cron entries your users have.  Maybe you have slow downs at a particular time every day, and want to see who’s running what.

All crontab’s, for all users, are stored in /var/spool/cron/crontabs on Debian and Ubuntu, as plain text files.   So, as root, you will be able to cat any of the files in there – they are stored as the username, so:

/var/spool/cron/crontabs/daz

… would be a user called “daz” for example.

In CentOS, the path is slightly different – there is no crontabs directory, so it’s simply:

/var/spool/cron/

You can also find out an individual users’ crontab by issuing (as root);

crontab -l -u username

This will show you that users crontab.  Of course, if you want to edit it, you can by doing:

crontab -e -u username