An assortment of useful linux commands

This is a totally random post full of linux commands that I find useful but am always forgetting. I use linux at work and also on a command-line-only VM at home. I'm always battling with it, largely because I'm a noob. Usually after a couple of hours of playing with it I have a head full of really useful commands. However the next time I run into a problem I won't remember any of them.

To prevent that happening again, this is a brain dump of all the commands I really, really should remember.

Installing stuff

You want to install something:

[cc lang="bash"]sudo apt-get update
sudo apt-get install ####[/cc]

Keeping things up-to-date:

[cc lang="bash"]sudo apt-get update
sudo apt-get upgrade[/cc]

It seems that a lot of the time aptitude is actually better at this stuff?

[cc lang="bash"]sudo aptitude full-upgrade[/cc]

Cleaning up:

[cc lang="bash"]sudo apt-get autoclean
sudo apt-get clean[/cc]

(or use aptitude)

Something won't install because you've not got access to it (it's not available for your distro etc). You probably need to find a URL for a "PPA" from somewhere like http://launchpad.net (Try Googling "project-name ppa site:launchpad.net" - thanks @Keithamus) to add to:

[cc lang="bash"]sudo vim /etc/apt/sources.list[/cc]

These usually require keys which are provided with the URL. To add the key:

[cc lang="bash"]sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ###key###[/cc]

There's loads of useful information about this here: https://launchpad.net/+help/soyuz/ppa-sources-list.html

Where am I / it ?

What version of ubuntu am I on?

[cc lang="bash"]cat /etc/issue[/cc]

Where is something installed (e.g. mysql)

[cc lang="bash"]which mysql[/cc]

Where are the files located?

[cc lang="bash"]locate mysql[/cc]

You probably want to pipe that into less

[cc lang="bash"]locate mysql | less
[/cc]

To find a file with a specific file name the syntax is:

[cc lang="bash"]find PATH -name 'FILENAME'[/cc]

An example might be:
[cc lang="bash"]find / -name 'myfile.txt'[/cc]

To find text within a file the syntax is:

[cc lang="bash"]grep -r 'SEARCH' PATH[/cc]

An example might be

[cc lang="bash"]grep -r 'Hello World' /[/cc]

I always forget the -r to make it recursive and wonder why it doesn't work.

Samba

Samba broke? Go Windows stylee & restart it:

[cc lang="bash"]sudo /etc/init.d/samba restart[/cc]

Still broke? Get a more useful error message from Windows by going into the command prompt and typing

[cc lang="dos"]net use m: \ip-address\service[/cc] (Yes OK this is a Windows command not a linux one...)

Perhaps it doesn't recognise the username/password combo:

[cc lang="bash"]sudo smbpasswd –a username[/cc] (and enter a new password when prompted)

Still broke? You might need to do some reconfiguring in the config file. Remember to check that everything has the access privileges it needs

[cc lang="bash"]sudo /etc/samba/smb.conf[/cc]

Noob

Yep, I are one! Like a linux redneck. I use a dash of trial and error mixed with a pinch of brute force, but normally I win in the end :D Hope someone else finds these useful. Also, yes I pretty much sudo everything. Sudo make me a sammich and all that jazz. See something really bad here? Please enlighten me, but be gentle!