Home of Rob
Menu
General Tips and Tricks
Introduction
I've been using Linux since the middle of 2006, and before that I'd spent all my computing time in front of an MS OS (hazy memories of 3.1 and DOS). Unless you count the Amstrad and BBC, but I was a bit too little to fully appreciate the inner workings of those little things. Anyway, this page will give some useful commands and insights into the Linux operating system - the sort of thing I use regularly and would have loved to have known about when I first started with Ubuntu!
Background
Windows is a much more friendly and accessible operating system. Generally, when you need to do something it's either easy to find or you can't do it at all. Implicit in this remark is that there's one way to do something or no way at all. This is different from Linux, which often has many ways to perform a task. This flexibility is great once you know how things work, but makes for a confusing environment with a steep learning curve. I've listed some commands here that I use but bear in mind that this list is a long, long way from complete and also that there will be other ways to do the things I present here. It's by no means the last word!
Getting help
Remember that in Linux if you ever need more help with something you can read the documentation by opening a console and typing
man [command]
The documentation can be quite technical but is a good place to start. Another good place to try is with
[command] --help
Most commands support this and will print out a brief usage guide.
Note that if you run commands in the console that launch a separate process, then this will tie up the current session in the console. To run the process in the background append '&' to the command and you'll regain control of the console once the process has launched. Remember that terminating the console will also terminate the process.
Useful stuff...
gnome-system-monitor
This is a graphical application much like the windows task manager.
top
This is a console based task manager. It will display current processes in a text based manner. There's help available, but the keys
du
This is a very useful command for finding out where all your disk space is being used. It searches the directory tree recursively and prints out the size of each directory. If you use the option
--max-depth-1
then it will only display directories in the current location, and the switch
-h
will display the size in human readable form (that is, kB and MB). You can append a location to the command to tell it to search a directory other than the present one.
xargs
Part of the reason that the Linux console is so powerful is the way that different commands can be 'piped' together. That is, the output of one command can be sent to the input of another. This enables long, complicated commands to be created! Anyway,
xargs
takes each line in the output of one command and passes it as an argument to the command you specify. For example:
find . -name "*.txt" | xargs grep "hello world"
will search the current directory for all files named *.txt, and will then search each file in turn for the string "hello world".
grep
This can be used to search files for a given string, as above.
alias
If you start using the same commands with the same options many times over, you can use the alias command to save yourself some time and effort. Rather predictably, it allows you to use an alias for a command. For example,
alias grep='grep --color=always'
will mean that every time you subsequently use grep the search terms will be coloured for easy spotting.
.bashrc
This is stored in your home directory and contains setup and configuration for all your logins. It's run every time you open a new console and can be used, for example, to change the colour of your prompt or display different things there. This file often contains a line something like
alias ls='ls --color=auto'
thus ensuring that all your directory listings are in glorious colour.
apropos
Use this to search all the manual pages for a particular term. Can be useful sometimes. For example, the command
apropos browser
will show you all the browsers you can use, including some console based ones for those occassions when the graphical interface fails (as happened to me once - console based web surfing is better than reading the raw html but not that much).
whereis
This command searches the paths for a given binary file.
locate
This is a good, useful little command to know. Locate uses a database of all files on a system to quickly display where things are. The database is updated regularly, but if you'd like to search through files that you've only recently installed or copied files onto your hard drive then you may need to update the database before running locate (use
man locate
for the options). Because locate uses a database it's much faster than the other methods for finding files (but won't necessarily be up to date).
dmesg
This prints out the debug log. Useful for me when I debug the embedded pxa270 device - less useful for desktop installations of Linux.
dmesg -c
will print out the content and then clear it. Note that on Ubuntu there's a GUI application for viewing all the system log files, located at System->Administration->System Logs
jobs
This lists all the processes running as children of your current console session. Creating a child process is done by using the & character after your command.
ldd
Pass this command a binary and Linux will list all the libraries upon which the file depends. It will also print the path to each one, or a message indicating that the file couldn't be found if that's the case.
/etc/fstab
This file tells Linux what to mount and where. You may want to edit this if you wish to automatically mount other filesystems automatically at boot time. For example, mounting network drivers, or a pxa2xx filesystem so that you can boot the pxa device on an NFS. This isn't always robust, though, since the mounting takes place before the networking has been initialised so network drives will often fail to mount. See below for another option if you want to do this...
/etc/rc.local
This file is run at the end of each multi-user run level. By default it is just empty but you may want to add a couple of things to it. Firstly, the line
echo 1 > /sys/module/processor/parameters/max_cstate
fixes a problem I had with Xorg in Ubuntu. Xorg would gradually use more and more CPU until it was up to about 40% after the PC had been on for a day or so. If you want to automatically mount a network filesystem then you can do that in here with the following command:
mount -t smbfs //Server1/Engineering /mnt/Engineering -o username=robgarrett,password=********
baobab
This little tool will display disk usage in a graphical manner.
Note: Since writing this page I've found another cool graphical display of disk usage that's pre-installed with Ubuntu. Find it here: Applications->Accessories->Disk Usage Anayser
sysv-rc-conf
If you ever want to customise your bootup then use this script to help. It analyses the startup folders and displays all the scripts in a console with an X next to each run level for which the script is active. It's a simple matter to turn the scripts on or off.