Boot your computer if it’s not running.
When it arrives at the login prompt, log in as studenth.
Use the password I supply.
Boot, login, Remote Desktop as necessary, and start Secure Telnet/Secure Shell (SSH).
Log in with your UNM user name and password.
Check Your Shell
Your answer may be:
/bin/sh # the Bourne shell
/bin/csh # the C shell
/bin/bash # the Bourne Again shell
/bin/ksh # the Korn shell
About the C shell (csh): see Fermilab’s Features of Available Shells at http://www.fnal.gov/docs/UNIX/unix_at_fermilab/htmldoc/rev1997/uatf-27.html#MARKER-9-310
And CSH PROGRAMMING CONSIDERED HARMFUL at http://www.ooblick.com/text/CshProgrammingConsideredHarmful.html.
About the POSIX and Korn shells (found on HP-UX, for example): http://docs.hp.com/en/B2355-90046/ch15s03.html
Point to Remember: Korn is a superset of bash; bash is a superset of Bourne; C shell is very different.
Windowing System | Shell
Both windowing systems (and this term predates Microsoft Windows) and command-line shells give you, the user, a way actually to do things on your computer.
They spare us the misery of saying things like, “Go to memory location 0101010001010001001010100101010, retrieve a string eight bytes long, and copy it to location 101011001010010101010001010110….”
Instead we can just say,
cp ~/myfile.txt newfile.txt
to copy myfile from my home directory (~/ means “my home directory”).
Commands: the instructions you give to the system
Files: globs of data that have been given filenames. These could contain graphics, music, text or programs.
Directories: in Windows we call these Folders. Think of something like a file cabinet drawer that can contain many files. Directories can contain other directories.
|Directories are files. A directory file is a list of other files.|
Environment: the collection of items that describe your unique computing session. These describe what programs you use, which printers, where you documents are stored by default, the email program you prefer to use, and a LOT more.
Process: a command or application running on the computer. You might want to call this a “program,” but actually an application may contain several programs, each of which may spawn many processes. Processes run in the “user space.”
Thread: an application running in “kernel space.”
Job: this is closer to what you’d think of as a “program.” It’s the sequence of instructions that’s given to the computer to perform a task. When the task is done, the job concludes.
When you sit down at a Linux workstation or make a connection to a Unix server, you start out at a login prompt. If you only see a flashing cursor, press the Enter key and you’ll be given the prompt:
To get any further, you have to have a user name (“username”). If you are registered with UNM, you have one; usually it’s the same as your email address. (This becomes an important issue we’ll explore later.)
Unix is case-sensitive, meaning that “A” is different than “a.” You have to enter your username correctly or this won’t work. Press the Enter key when you’re done:
Now you’ll get a password prompt:
Enter your password, which is likely to be a horrifying string like Ab78bsG. You may find this just dandy if your grandma Abby is 78 years old and she’s married to Bob S. Green. Or you may not.
A Password You Can Remember
You can, however, change this password, and in fact you may be forced to on your first login. Choose something you can remember:
All She Wants 2 Do Is Dance
To change your password once you’re logged in, type the command:
Depending on the version of Unix, you may be shown your current password. Actually this is a terrible idea, because someone could easily look over your shoulder. Some systems will ask you to enter your old password at this point. Either way, you’ll then be prompted to enter a new password, then repeat it. Finally you’ll get a “password changed” message.
You will, that is, if your password meets the security requirements of that particular system. Typically, a university-sized domain will have several, for instance:
- You may have to use at least eight characters,
- At least one may have to be a capital letter,
- At least one may have to be a number,
- And no part of the password may be allowed to resemble a real word.
If you try to change your password to “password,” for instance, you will likely experience a rejection.
Now that you’ve finally logged in and taken care of any password change, you’re operating in your shell. One of the first things you can check is your own user information:
id whoami who w finger username groups
These will show your userid number and name, your main group affiliation, and a list of all the groups of which you are a member, among other things.
Another term for a shell is “command interpreter.” Remember Dennis Richie, inventor of the C programming language? The first thing he needed, once he got his PDP7 “Unics” computer working, was a command interpreter to actually run commands. Thus was born the “C Shell,” csh, one of hundreds of program-name jokes in the Unix world.
Other shells include:
- the Korn shell (ksh or the Posix shell),
- the Bourne shell (sh),
- the Perl shell (perl),
- csh/tcsh (C shells),
- The Bourne Again SHell (bash),
- rsh (remote shell),
- ssh (secure shell)
- and more.
Some shells can connect to remote computers.
Some shells encrypt their traffic for security.
Some pass traffic as plain text, like Telnet.
The closely-related Bourne, bash and Korn shells offer lots of nice features like completion, which means if you type the beginning of a file name, for instance, bash will try to complete it for you.
Other programmers needed different features in their shells, so they wrote their own command interpreters. Evolution occurred, survival of the fittest kicked in, and eventually the Bourne shell became the standard.
When this shell made the transition to the Linux world, if became the Bourne Again Shell, or bash. This is the default shell in most Linux distributions, but you can still choose to use a different shell.
On a Unix server, the default login shell will often be the C shell, /bin/csh. This is, unfortunately, a very “old school” choice, but one that’s easy to fix in the short term. Simply command:
bash # on a Linux box or sh # on an AIX box or ksh # on an HP-UX box
For now, just be aware that we are studying bash under Linux and Bourne or Korn under Unix, and that this choice of shell is one of your environment variables.
When you are any user but root, Bourne/bash/Korn will give you this prompt:
with a flashing cursor where your text will be entered. If you use csh (or tcsh) your prompt will be:
Even more important is the visual cue the shell will give you to let you know you’re logged in as root:
You’re ready to enter commands. You should know that:
- Unix commands are case-sensitive.
- Most are lower-case.
- These commands are only going to work at a shell prompt.
- You have to press the Enter key to make the command run.
Commands often have options after the main command, and these options usually begin with a dash, for instance:
You can add more than one option at a time:
These “single-dash” options are formally called “System V” options. You will also see “no-dash” options (“BSD” options) with some commands, such as:
Then there are the so-called POSIX options that are supposed to be common (at least to some degree of compliance) to any POSIX-compliant shell. They’re distinguished by double-dashes:
ls = List of objects in the current working directory.
will bring up a list of files and subdirectories. It may also be flagged to provide some different ways of looking at the list of files, such as
which will provide a long directory listing (similar to a DOS dir), and
which will show all of the files in the directory, including hidden ones and
ls | more
which will provide a directory listing one screen at a time. The ‘|’ is called a ‘pipe’, and passes data from one command to another.
gives you a list of files with special notation of their type:
* means “executable”
/ means “directory”
= means “socket”
| means “pipe”
man ls dir
Columns in the ls –la listing:
number of hard links
size (in bytes)
The permissions column:
directory, link or file?
r = read
w = write
x = execute
The hard links column:
What the heck is a hard link?
man linkinfo coreutils link
The Owner column:
The owner and the author are the same in most *nix, but not in all *nix.The owner is referenced in the owner triad of the permissions. Generally, files under your ownership are in your home directory, but not necessarily (see /var/mail/username).
The Group column:
When you are created as a user, a group with the same name is created, with you as its only member. You may be assigned to other groups, for instance, the wheel group. Your file permissions are set upon file creation. These defaults can be changed.
The Size column:
Size is displayed in bytes, though there are options for showing it in blocks (often 4096 byte blocks).
The Last-Modified column:
Month, Day, Year (if not current year)
Time in “military” format
The File Name column:
Regular files can be named almost anything within this keyspace:
a-z A-Z 0-9 _ – ~ .
You will run into certain special characters that you can’t use. Unix does NOT use file extensions to identify file type; Gnome and KDE however DO. Hidden files start with a dot: . Backup files end with a tilde: ~ Some programs like emacs create backups automatically.
Start with a dot
Contain system configuration
Usually text files
Can be directly modified
To move up one directory: cd ..
To move up two directories: cd ../..
To go back to your home, from anywhere: cd or cd ~
Note that the tilde ( ~ ) means “home,” and is relative for every user.
Of course, you can always specify your destination: cd /home/studenth/
Or go back to the immediately previous directory:
Now is a good time to become familiar with another useful web site: LinuxCommand.org:
http://linuxcommand.org/man_pages/ls1.html. Take a look at some other useful options. Do you notice if any of them are set by default?
|Some Common Options to ls|
|List all files, even hidden||la -a|
|List all files, except the . and .. usually listed at the top||ls -A|
|-C||List in columns||ls -C|
|–color=always||Controls whether color is used to distinguish file types: ‘never’, ‘always’, or ‘auto’.||ls –color=never|
|List directory names, rather than their contents||ls -d|
|-f||List without sorting||ls -f|
|List filenames with markers to indicate type: executable* directory/ socket= or pipe|||ls -F|
|–full-time||Gets a long listing with full modification time||ls –full-time|
|-l||Long listing||ls -l|
|Long listing with human-readable (simple) file sizes||ls -lh|
|Long listing omitting group information||ls -lG|
|Lists files in reverse ASCII-betic order||ls -r|
|List files in directory, and in subdirectories||ls -R|
|-s||List files and size in kilobytes (KB)||ls -s|
|-S||List files sorted by size||ls -S|
|-t||List files sorted by modification time||ls -t|
|-U||Lists files without sorting||ls -U|
|-x||List files in rows rather than columns||ls -x|
Mix and match! Any of the above may be used together.
|You can use an initial capital letter to name your directories. Because files are listed “ASCII-betically,” capital letters come before lower-case letters.|
|The command ll is an alias, on many systems, for ls -l.|
Research the file command. What does it do? How does it compare to ls?
The man Command
You can always get information about a command by calling for a “manual page:”
will get you a detailed page of information on using the ls command.
The more Command
more = Show the contents of a text file one screen at a time.
will allow you to view, one page at a time, the contents of the file file.txt.
When viewing the text file, hitting <enter> advances the screen one line, while hitting <spacebar> advances the screen a page.
For help, type the letter h at the prompt while you’re in more.
When you’ve seen the whole file more will dump you to a command prompt.
The less Command
more may be nice for paging down through text files, but just try paging back up!
less, ironically enough, gives you “more.”
Use the same syntax as more:
Use the arrow keys or page up/page down to traverse the file in either direction.
When you want to leave less, type
The cat Command
There’s another way to view the contents of a text file (yes, really), and this one comes with a bonus.
will display a file’s text and dump you to a command prompt.
One very useful option to cat is -n, for line numbering. Try this:
cat -n /etc/passwd
And, oddly, there is a tac command to read files in reverse order. This is especially handy for log files:
But here’s the bonus: you can concatenate two or more text files with this command:
cat filename1 filename2 filename3
and you’ll see the contents of all three files, chained together (concatenated).
Remember this: this can be very handy later.