Linux Commands Quick Reference Guide



Getting Help

man command
Type: man ls to read the manual for the ls command.

whatis command
Gives short description of command, eg; whatis ls

apropos keyword
Search for all Linux commands that match keyword, eg; apropos file




Working With Directories

List a directory


ls -l path
Long listing, with date, size and permisions.

ls -a path
Show all files, including important .dot files that don't otherwise show.

ls path | more
Show listing one screen at a time.


Change Directory

cd {dirname}
There must be a space between.

cd ~
Go back to home directory, useful if you're lost.

cd ..
Go back one directory.

Print working directory

pwd
Show where you are as full path. Useful if you're lost or exploring.


Make new directory


mkdir {dirname}
Creates a directory


Remove Directory

rmdir dirname
Only works if {dirname} is empty.

rm -rf dirname
Remove all files and subdirs. Careful!





Working With Files

Copy a file or directory

cp oldfile newfile

cp -r old-directory new-directory
Recursive, copy directory and all subdirs.


Move (or rename) a file

mv oldname newname
Moving a file and renaming it are the same thing.


Find files on system

find filename
Works with wildcards.

slocate filename
This searches a database, rather than the actual directory tree, which makes it much faster than find.

Make an Alias

alias name='command'
For example: alias cdrom='mount -t iso9660 /dev/cdrom /cdrom', now you can mount your cdrom by just typing cdrom (put the command in 'single quotes').


File Permissions


chmod 600 filename
You can read and write; the world can't. Good for files.

chmod 700 filename
You can read, write, and execute; the world can't. Good for scripts.

chmod 644 filename
You can read and write; the world can only read. Good for web pages.

chmod 755 filename
You can read, write, and execute; the world can read and execute. Good for programs you want to share.


Change file permissions with letters:


u = user (you)
g = group
a = everyone

r = read
w = write
x = execute

chmod u+rw filename   

Give yourself read and write permission

chmod u+x filename

Give yourself execute permission.

chmod a+rw filename

Give read and write permission to everyone.





Working With Text Files


View a text file



more filename
View file one screen at a time.

less filename
Like more, with extra features, less is more the more.

cat filename
View file, but it scrolls.

cat filename | more

View file one screen at a time.


Create or Edit files with vi

vi filename
Creates or edits an existing file with the vi text editor.

vi commands:

i = insert text at cursor
:e = edit file
:w = write buffer
:q = quit
:wq = write and quit (save)





System Commands



System info

date
Show date and time.

df
Check system disk capacity.

du

Check your disk usage and show bytes in each directory.

uptime
Find out system load.


uname -r
Type this in a console to find out the version of the running kernel.


ifconfig
Use this command to see what your current IP addresses are.

netstat
Print  network  connections, routing tables, interface statistics, masquerade connections, and multicast memberships


demesg
This command in a console to list all of the devices loaded at bootup and their names
(cdrom = /dev/hdx, floppy= /dev/fd0, network cards etc...)


Assume Root Privelidges

su
To get root (super user) access while logged in as a user just type su in a console and supply the root password. Now you are 'root'. You can return to your user account by hitting CTRL-d.


Kill A Process

Let's say for example, Netscape has locked up (no way) and you want to kill it. You can type in a console:

ps -aux | grep netscape

This will give you the pid number (process id number) on the left. To kill the pid, type:

kill -9 pid#


Turn on/off Startup Services (daemons)

To see what services are running do: chkconfig --list
To turn off a service for example; kudzu, from the console type: chkconfig kudzu off
To turn it back on do: chkconfig kudzu on


Loading Modules(drivers)

To get a list of currently loaded modules type: lsmod
To load for example, the tulip module (necessary for my Lynksys nic card) type: insmod tulip
To unload the tulip module, type: modprobe -r tulip


Tweak your video settings with xvidtune

I typed: xvidtune in a console to adjust my video display settings, I was also able to find out the exact horizontal and vertical refresh rates listed in the lower right corner of the xvidtune application. I then entered those spec's in the /etc/X11/XF86Config-4 file.


Shutting Down and Rebooting

Shutting down and restarting properly will prevent your filesystem from being damaged.

To shut down (halt) your system, type: shutdown -h 0 or init 0
To reboot, you can type: shutdown -r 0 or init 6


X-iting from X

To exit from X, you can use the Ctrl-Alt-Backspace combination.

Make sure to have any running programs closed so that they don't get killed when you log out of the X server.




Miscellaneous  Tips

Console Filename Completion Tip

Tab filename completion in a console allows you to type in portions of a filename or program, and then press [TAB], and it will complete the filename for you. If there's more than one file or program that starts with what you already typed in, it will beep, press [TAB] again and it lists all the files that start with what you initially typed.

Specifying Memory Size in LILO

Linux not correctly seeing all your Ram?

LILO uses the /etc/lilo.conf file to store its configuration. Edit this file (as root), and add a line *after* the "label=" line which looks like append = "mem=128M", change 128 to the amount of megabytes of RAM installed on your machine. After adding this line, issue the command: lilo as root from a console and reboot.