21 Jan 07
Linux Command Quick Reference
The biggest obstacle for new users is learning how to make the OS do what they want. It is frustrating to be an experienced computer uses who can't get around their computer because the commands are all different than you are used to. To help you out, I've provided some of the most basic commands you need to get you started.
man command– This is the most important command in Linux by far. Unlike some other popular computer products, Linux comes with a built-in manual. Use “man command” to bring up the manual for that command. The manual, or man page, will tell you what the command or file does, how to use it, what the options are for the command, and give you some related files and commands. Read the man page for any command I provide here for more detailed infromation than I provide.
“man -k keyword” will search the man pages for the keyword. Try “man ls” to prepare for the next command we'll cover.
ls – lists the contents of a directory. By default, it lists the contents of the directory you are in. Use “ls -lh” to get more information, like size and last modification, about the files listed. This is like the linux version of the Windows "dir" command.
pwd – Print working directory. Shows you the directory you are currently in
cd – Change directory. “cd /home” will take you to the /home directory. Use it without the leading / to get to a subdirectory of the directory you are in. For example, if you are in /home, then “cd magoo documents” would take you to /home/magoo/documents.
mount device folder – Mounts the listed device in the listed folder. Most of your partitions should be automatically mounted at boot time, but sometimes you want to manually mount a device like a USB flash drive. The command to mount a USB flash drive would look something like “mount /dev/sd0a /mnt/usb”. Many desktop distributions will do this for you, but it can still come in handy to know.
locate filename - searches a database of all the files on your computer looking for the location of the filename or partial filename you provide. Sometimes it will complain that you need to update your database by running the command “updatedb.” Check your man pages for the location of updatedb; each distribution is different. Red Hat puts it in /sbin/updatedb, while Ubuntu puts in in /usr/local/updatedb.
whereis file – similar to locate but not as powerful of a search. The good thing is that it doesn't require a database.
vi filename – Text editor. Opens the file in the vi text editor. Useful for changing configuration files from the command line. Vi is very powerful but a little confusing at first. You may want to read a little about vi before you get started.
Some distros also include emacs or nano text editors. They are both easier to use than vi but not as powerful or popular. Nano is the easiest. You can install any of them you want once you are up and running.
passwd – Change the password of the currently logged in user. Use “passwd username” to change the password of another user.
sudo – perform a command with the permissions of the root user. Example: "sudo updatedb" would run the updatedb script as the root user.
su username– Substitute user. Allows you to act as another user without logging in as that user. If you don't provide a username, it will default to root. Of course, you will need the root password to make it work.
rm filename - Delete a file
more filename - display the file one page at a time. "Less" performs a similar function.
grep - Powerful text search tool
ps aux - display a list of all running processes, including the amount of memory and CPU usage
top - show CPU and memory utilization, along with running processes. Press Ctl+c to exit top
kill processid - ends the process with id processid. You can find the process id with ps aux.
apt-get – The debian package manager. This only works in debian based distributions like Ubuntu, but other distributions have similar package managers. To detailed to explain here, try “man apt-get” for a good description of how it works. You will also want to look up apt-cache. Generally, typing “apt-get install programname” will install that program. Example: apt-get install mozilla-thunderbird.
Red Hat has a similar package manager called yum and a more powerful package manager called RPM that many distributions have adopted. Linspire recently open-sourced their Click-n-run package manager, so expect to hear more about that soon.
du - shows how much space the files in a directory are taking up
df - shows how much hard drive space you have left. Use df -h to make it easier to read
| - Pipe. Not actually a command, but it allows you to send the output of one command to another command. For example, you could type "ls | more" to see the contents of a directory one page at a time. Hold shift and press the key above enter to type a pipe.
28 Jan 08