|
This information, along with some other useful stuff, is also
available on the web at
http://aiki.bme.duke.edu/eel
logging in Each user has a login id (usually your Duke netid) and a password. Your password is something that should never be divulged to anyone else, and should never be written down. This is very important here in CIEMAS, since we have people who are not part of our lab sharing it with us. If you want to change your password, read the man page for passwd. |
bash
When you are logged in, each window will be running a command interpreter called bash. This program is the intermediary between you and the system, accepting all user input and taking appropriate action. Each command that you type to the shell should be followed by a |
ls
ls lists the files and directories in the specified location, or in the current directory if you don't specify a location. so
ls /tmp
will show the contents of the /tmp directory. The most useful option to ls is -l (almost all options to UNIX commands start with a -); it causes ls to give a long listing, which is more verbose. Instead of typing
ls -l
I can type
ll
ll is an alias for ls -l. |
cd
cd is used to change directories. When you first log in, you will be in your home directory; this is the place that all of your personal files will reside. Most home directories are found under /aiki/us1. So my home directory is /aiki/us1/ndd. Note that you don't need to know where a user's home directory is: ~ndd is a shorthand that refers to my home directory no matter which machine it is on. On occasion, you will want to change directories before doing a command; cd allows you to do this. For example, I could list the contents of /tmp by doing either
ll /tmp
or
cd /tmp
ll
Note that there are some commands whose result depends on where you are when you execute them, so make sure you know where you are all times! |
file
It is often useful to know, given a file name, what type of file it is, since there are many commands that only work with one kind of file. The command file will tell you the type of the specified file. Since we've used ls, let's see what kind of file it is:
file /usr/bin/ls
and file's response is
/bin/ls: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, stripped
This tells me that ls is an executable, and therefore cannot be looked at with cat, more, or vi, all of which require ASCII files. file will identify ASCII files as such, or as text files. |
cat
in order to print an ASCII file to the window, I can use the program cat. First, make sure that you're in your home directory by doing
cd
and then you can use ls to find some file names. One of the files listed is called calendar: when I do
file calendar
I get
calendar: ascii text
which means that it's okay to look at. So I can do
cat calendar
and cat will print the file to the window. cat is really most useful for small files, since it just prints them to the window with no control: if the file has more lines than the window, it will scroll off the screen. |
more
more is a command that works much like cat, with the exception that it knows how big the window is, and only displays as many lines as will fit. To see the next line, you can type
ll /usr/bin
I will get several windows worth of output fairly quickly, with the result being that I will only be able to look at the last few lines. However, I can do
ll /usr/bin | more
and more will take the output of ls and let me control it. |
|
This introduces the pipe symbol, which is obtained by typing a shifted backslash (\). | takes the output from one command and routes it to another. It is important to note that | is to be used between two commands only; you cannot use it to get output into a file. Another useful example of | is to get a printout of a listing:
ll /usr/bin | lpr
will send the output of ls to lpr which will print it on the laser printer that's in 1145. |
Above I mentioned that | cannot be used to get output into a file. What can be used for that purpose is the bash redirection symbol
ll /usr/bin
and the listing produced by ls would be placed in foo. It is important to note that, if you have permission to write foo, |
There are several commands that expect you to type input to them; you can get around this by using |
command line editing
One of the most common ways to lose a file is through a typing error: you mean to type
ll
but you type
ll
and lose a day's work. In order to allow you to correct typing mistakes, bash has three types of deletion: character delete, word delete, and line delete. The default character for character delete is ctrl-h (or the backspace key); for word delete is ctrl-w, and for line delete is ctrl-u. (This introduces a new notation: ctrl-h is a shorthand for holding down the Control key and pressing the `h' key; it is pronounced `control h'.) As long as you haven't typed |
mv
Suppose that we make a file called foo, but we meant to call it goo; we can rename that file using the command mv to move it from one name to another.
mv foo goo
mv can also be used to move several files from one directory to another; if I have the files foo1, foo2, and foo3 in my home directory, and I also have a directory called keep, I could do
mv foo1 foo2 foo3 keep
and foo1 through 3 would end up in keep, with the same names. |
rm
If I decided that I didn't want to mv the foo files, but just get rid of them, I would use the command rm
rm foo1 foo2 foo3
Note that once a file has been removed, it is gone from the disk and cannot be easily resurrected; there is no trash bin! An empty directory can be removed with rmdir or you can remove a non-empty directory with
rm -r foo |
cp
If you want to make a duplicate of a file, you can use cp. For instance, if I wanted another copy of foo, I would do
cp foo goo
and goo would be an exact duplicate of foo. This is mainly useful if you want a slightly different version of foo for some purpose. You should not make copies of files for backup purposes, as there are better ways. |
mkdir
I've already mentioned the possibility of moving files into a directory, so we need to know how to make a directory. This is done with the command mkdir. To make a directory named foo, I would do
mkdir foo
I could then cd to foo and work in there. Directories are very useful for keeping common files together in an obvious place. |
shortcuts
Here are some short cuts that will make things go a little faster.
history
,
;Bash keeps a list of the last 50 commands that you have attempted to execute. If you decide that you want to repeat one of those commands, there are several ways to go about it. The character `,' is called the history character, and is used to access the history list. The command h (which is an alias for history) will give you a listing of the last 50 commands. Here is part of my history list:
39 mv foo1 foo2 foo3 foo4If you want to repeat, say, command number 40, you would do
40 mkdir tmp
41 mv foo1 foo2 foo3 tmp
42 rm -r tmp
43 h
44 latex foo.tex
45 d
46 pd
47 ls
48 latex goo.tex
49 h
,40
and bash will redo that command. Note that the command will be repeated exactly as it appears in the list; bash does not care if you have changed directories or removed a file since the original invocation. This means that repeating command 42 probably should only be done after some thought. Another method for specifying previous commands is by the first few characters in the command. So I could repeat command 48 by doing
,la
Note that bash will pick up the first match, so if I really wanted to redo 44, I couldn't use this method. If I want to repeat the very last command, I can do
,,
Now suppose I want to repeat the last command, but I want to change it slightly. The character `;' can be used in this fashion:
;oldpattern;newpattern
If I had just done
latex foo.tex
when I really meant `intro.tex', I could do
;foo;intro
and the command
latex intro.tex
would be executed. Note that it will match the first sequence of characters it can. The character `;' can be used to edit any word of the last executed command; the only thing it can't do is edit multiple words. So if I type
latex latex.tex
the only way that I could change the second latex would be to do something like
;ex la;ex las
but since `;' can't cross spaces, that won't work.
The use of `;' is a specific instance of a more general editing facility that is available with `,'. To edit any command in the history list, you first specify the command (either by number or by the first few characters) and then the edit string:
,23:s/oldpattern/newpattern/
Here, as with `;', you can not include any spaces in `oldpattern'; however, with both `,' and `;', you can include spaces in newpattern. There are two other very useful things that can be done with `,'; one is to specify the last word of the previous command, and the other is to specify all the arguments of the previous command. The first is done using `,$'. For example, I can do
file /tmp/foo
ll ,$
rm ,$
which will result in information about the type of foo, a long listing, and then removal. The second is done using `,*'. For example, I can do
file /tmp/foo ~ndd/foo
ll ,*
rm ,*
The first line gives me file information about the file foo in the directory /tmp and in my home directory, then shows the directory entries for those files and removes them.
These tricks can be handy, especially when dealing with long file names, or long command lines.
|
Tab
ctrl-d Another handy shortcut is the use of the Tab key. Bash provides a filename completion service that allows you to type the first few characters of a file name, and then press the Tab key; bash will complete the file name if possible. If it can not unambiguously complete the file name, nothing happens; pressing Tab a second time gets a list of possible matches. |
*
An additional useful shortcut is the character `*', which matches any number of any character(s). For instance, if I wanted to see all the files in /tmp that begin with `p', I can do
ll /tmp/p*
This character can be used with most UNIX commands, but it should always be used with care, especially with commands that change files, such as rm, cp, and mv. |
ctrl-C
ctrl-C is used to interrupt a command that you decided not to run. For instance, if you started to print a manuscript using latex:
latex manu.tex
and then decided that you wanted to work on it some more first, you could stop latex by pressing ctrl-C. |
ctrl-Z
ctrl-Z is used to suspend a command while you do something else in that shell. For instance, if you were in your home directory editing a file, and wanted to write a modified version to a different file name, you might want to check first to see if that file already exists. type ctrl-Z and you'll get a shell prompt; you can then do any shell command. Note that the job you suspended has not been killed; it's sitting there waiting to be restarted. There are two main options: you can type fg to return the job to the foreground (which makes it the only thing running in that shell) or bg to put the job in the background. Putting a job in the background means that it's running in the window, but you still have a shell prompt so you can do other work. Note that it doesn't make sense to put an edit job in the background, as such jobs are cut off from input.
If you try to log out of a window while a job is suspended, you'll get a message like `There are stopped jobs.'. It's advisable to bring such jobs into the foreground and exit them gracefully rather than have the shell kill them when you leave. |