These are the commands which you have to know in order to be basically functional with a shell (command line).
| ls | List directory contents. ls -l long listing with dates and permissions ls -a list all, including hidden files (hidden files start with a period) |
| cd | Change directory. cd - change to previous directory cd ~ change to home directory cd .. change to parent directory |
| pwd | Print current (working) directory. |
| cp | Copy file(s). cp -r somedir somedest Copy recursively (directory and all contents) |
| mv | Move (or rename) a file (or directory) |
| rm | Delete (remove) a file. rm -r somedir Delete recursively (directory and all contents) rm -ri somedir Delete recursively, but prompt before each removal rm -rf somedir Delete recursively, never prompt |
| mkdir | Create directory. |
| rmdir | Remove (empty) directory. |
| cat | Print file contents (to console). |
| less | Scroll through file contents, one page at a time. SPACEBAR to advance a page, B to go back a page, Q to quit, /pattern to search for pattern |
| exit | Close shell. If this is your login shell, you will log out. |
To get detailed help on a particular command or program, you can try the following.
If you want help on a specific command (ls for example), type man ls. You move around in man as you do with less: SPACEBAR is forward a page, B is back a page, Q is quit.
Info pages are similar to man pages, but contain links and other complex structures. There are many key-strokes for navigating info; if you call info without any arguments, then hit H, you'll get some help on using info.
This Applies only if it's KDE or Gnome program. In either case, you can launch the help browser from the Start menu on the Panel, or choose from the program menu, or press F1.
Every package must install at least some minimal help into a subdirectory in /usr/share/doc. Sometimes it's in html format (read with a browser), sometimes it's plain text (read with less), sometimes it's compressed text (has an ending like .gz, read with zless).
Every command or program belongs to some project (or company). Usually they have a home page which provides copious, up-to-date and indexed information (well at least you can hope that they do.) Can't find the project home page? Try www.google.net .
You can read man and info pages with Konqueror (the KDE web browser) or Galeon, which is nice because then they are nicely formatted and have links and such like. For example, to read the man page on the tar command, enter man:/tar in the address bar; to read the info page on tar enter info:/tar. To get the list of info topics, just enter info:/.
Spaces on the command line separate arguments. Therefore file names containing spaces require special treatment to avoid being interpreted as two separate files. There are a couple of methods. You can use quotes:
cp "file name with spaces" file_name_without_spaces
You can also use the backslash, which indicates that any special significance is to be removed from the following character. Thus a space, instead of being the delimiter for arguments on a command line, is to be interpreted as a regular character.
cp file\ name\ with\ spaces file_name_without_spaces
Copying and pasting in Linux is really easy (yes, easier than Windows). Just mark the text you want to copy with the mouse, holding down the left mouse button in the usual way. Then click the middle mouse button (on a wheel mouse the middle button is the wheel) where you want to insert the marked text. Voila! You didn't even need to touch the keyboard! (CTRL-C and CTRL-V also work like you expect them to most of the time.)
For example, suppose you just typed a command, and you want to type a another similar command. If you can still see your original command in the console, just mark it with the mouse, then click the middle mouse button anywhere in the terminal window to insert the marked command at the prompt. You can now edit this command with the left and right arrow keys before hitting enter to execute it. There's another way to recover and edit previous commands, which I'll cover in the next section.
You can double-click to mark a whole work, or triple-click to mark a whole phrase. Remember - you haven't only marked it, you've put it in the clipboard.
You can scroll though your previous commands (command history) by using the UP and DOWN arrow keys.
A more advanced trick is to use CTRL-R, which is particularly useful when you want to recall a command you used some time ago. Hit CTRL-R and then start typing some fragment of the command you're searching for. The prompt will automatically update to show you the most recent match to the fragment you've typed so far. If you want the matching command previous to the one shown, hit CTRL-R again. Once you've got the previous command you're looking for, hit ENTER to run it again, or start editing it.
Some commands and especially some file names can be pretty long. Don't want to type it all? Type the first few letters, then hit TAB. The shell will fill in the rest, as far as there is a unique completion (either command or filename). If there is not a unique completion to the end, you might have to type another character or two and then hit TAB again.
Since Linux is a multi-user system, file permissions are important. In Linux, there are separate read, write and execute permissions for the owner of the file ("user"), the "group", and everyone else ("other"). You can find out what permissions a file has with ls -l . Here's an example:
-rw-rw-r-- 1 nodwell mbelab 45570 Jul 9 13:10 kate.png |
As an example of changing permissions, let's assume I have a file called foo which I want others in the "mbelab" group to be able to read and write. To do this I change the group to mbelab and set the group read and write permissions:
chgrp mbelab foo
chmod g+rw foo
I should also make sure that the directory that this is in, and all the higher (lower?) directories are actually readable by the group. For example:
chmod g+rx /home/nodwell/shared_stuff
chmod g+rx /home/nodwell
Notice that I also set the executable bit for the directories, which allows someone in the group to actually switch into that directory. (Not very logical I admit):
To change the group and permissions on a directory and everything in it, including subdirectories and their contents, use the -R (recursive) flag:
chgrp -R mbelab /home/nodwell/shared_stuff
chmod -R g+rw /home/nodwell/shared_stuff
Now suppose that we want all files which are created in /home/nodwell/shared_stuff to automatically have the group mbelab. Assuming you've already changed the group of this directory to mbelab, you can do this by setting the group sticky bit:
chmod g+s /home/nodwell/shared_stuff