Here are some basic instructions for popular commands needed to get around in UNIX and Linux.
See What Programs You Are Running: ps
The command ps stands for process.
In UNIX, everything you do, every command you type, is considered a "process". This command will list all the jobs you have running in your account, which includes the login shell (-csh) and the program ps itself, any other programs you might be running, and extra logins (see example below).
If you have accidentally left yourself logged in somewhere, you can cancel that login by logging in again (from wherever else) and typing ps at your prompt. It will result in a listing that looks something like this:
PID TT STAT TIME COMMAND
16818 p8 S 0:00 -csh (csh)
16834 p8 R 0:00 ps
15342 q7 IW 0:00 -csh (csh)
The first column is the Process ID Number (PID#), the second is the number of the line you logged into (TTY). The other column in the display that we need to worry about is the last one, COMMAND, which tells you what the names of the programs are that are running. In this example there are two -csh processes, or login shells, running. The one with the lower PID# is the old login. To log yourself out of that extra login, use the kill command below.
Force Quit Programs or Excess Logins: kill
The kill command will force quit any process.
"Kill" will terminate any "processes" you have running. A process is anything you do on stout: when you log in, a "csh" process is created; when you use mail, another process is created; when you edit a file (using an editor like Pico), a process is created, etc. To force quit a process that can't be exited any other way, you can "kill" it. First, find the process id using the "ps" command (above).
Once you know the process id, you can terminate it by typing:
stout.hampshire.edu% kill -9 15342
This command is frequently useful when you have a mail drop box locked message from Eudora. If this happens to you, log into your stout account, and look for a popper process with your login/username.
Cancel a Command: ^C
The command ^C (control and C simultaneiously) will cancel another command or program. ^C works in almost every screen, in PINE and in your home directory (at the prompt). This is especially good for quitting out of a message you really do not want to send, or if you accidentally hit some random key you don't know the function of.
List Everyone Currently Logged In and Last Login and Personal Profile of a Specific User: finger
To finger stout in general, at the prompt type: finger and a list of everyone logged in to stout will be displayed.
If you want to see when the last time a specific person was logged in, or to see if s/he is still logged in, or read her/his .plan, type: finger abc01
You can also finger an alias, or just a first name; however, if you type finger amy it will spit out everyone on stout who has the letters "amy" in his/her fingername or login name or alias. It works better if you use the person's username.
Get Help With Other Commands: man
man used in conjunction with the -k option is another way of finding out about unix commands. man -k [keyword] will print the manual section headings containing [keyword].
Files and Directories
IMPORTANT INFO: Filenames can have no spaces or "/" but can have underscores (_) or dots to separate words. They can have capital letters, but remember UNIX is case sensitive. A filename with a "." at the beginning indicates it is a hidden file. A filename with a "/" at the end indicates it is a directory.
Print a List of Files & Directories: ls
The command ls stands for list, and gives you a list of files and directories in the current directory. This command has many options. For all the options, you can look at the manual pages by typing man ls at the prompt. But here are some of the most important ones:
ls prints a list of the titles of non-hidden files and directories in your home directory.
ls -l This command will print out a list of non-hidden files and directories with all their access privileges and sizes (in bytes) along with the date created. like this:
stout.hampshire.edu% ls -l
drwxr-xr-x 3 abcF70 student 512 Mar 28 20:38 Mail/
drwxr-xr-x 3 abcF70 student 512 Mar 28 20:39 News/
-rw-r--r-- 1 abcF70 student 4275 Jun 16 15:56 bionotes
-rw-r--r-- 1 abcF70 student 3432 Jun 8 12:21 job_letter
drwx------ 3 abcF70 student 1024 Jun 19 11:12 mail/
-rw-r--r-- 1 abcF70 student 6992 Jun 6 17:14 neato.html
drwxr-xr-x 4 abcF70 student 1024 Apr 28 15:33 public_html/
-rw------- 1 abcF70 student 1895 Mar 2 20:42 private.1
-rw------- 1 abcF70 student 1692 Mar 2 20:42 private.2
drwxr--r-- 3 abcF70 student 512 Jun 19 09:38 quotes/
The 1st column is the permissions, the 2nd and 3rd are the owner and type of account, the 4th the size of the file in bytes, the 5th the date created/last modified and the 6th is the name of the file or directory.
This command will print a list of all files, directories and hidden files (the ones that start with "." like .plan and .forward) in the same format as ls -l
Delete Files: rm
The command rm stands for remove
This will permanently delete files. To delete a file, type rm filename at your prompt. To delete a directory use rmdir filename (see below.)
Create or Edit New Files: pico
Pico is the default text editor of PINE. It uses almost all of the same commands and can be used to create and edit any sort of text-only document.
It is a basic editing program - like a really primitive word processor. You can create new files or edit pre-existing files.
To begin editing an existing file, at your main prompt type:
To create a new file, you have to give it a name before you start typing. You do this by typing:
File names can have any extension you want (.txt, .doc, .html), but they are not necessary. File names can have NO SPACES. Use an underscore instead ( pico new_filename or pico new_filename.html).
The basic commands used in pico are listed at the bottom of the screen, just as in PINE. When seen next to a letter, the caret symbol (^) means control as in PINE and all other UNIX commands. While you are typing, you have these options:
^G Get Help ^O WriteOut ^R Read File ^Y Prev Pg ^K Cut Text ^C Cur Pos
^X Exit ^J Justify ^W Where is ^V Next Pg ^U UnCut Text ^T To Spell
Here are the most relevant commands:
^O will save the document and let you keep editing; you can also use this to rename the document.
^X will save the document and quit pico. If you want to change the name of the document, you can do it here also.
^Y Page Up
^V Page Down
^K (Cut) will delete the entire line the cursor is on.
^U (Paste) will undelete the line you ^K-ed and re-insert it wherever the cursor is.
^G will put you into a help screen that is very useful if you need more info than this.
Copy Files: cp
The command cp stands for copy.
Use it to make changes to a file under a new name and keep the original, to put extra copies of files in other directories, to move files from one place to another or rename files.
To copy a file from the current directory to a new directory: cp filename /newdirectory/filename
To rename a file in the same directory, type: cp filename newfilename (Using this, you can then make changes to the newly-named file & keep the original.)
To move a file to a new directory with a new name, type: cp /originaldirectory/filename /newdirectory/newfilename and delete the file in the original directory using "rm" (see above) For more information on cp, type man cp at your prompt.
See What Directory You Are In: pwd
The command pwd stands for print working directory.
Directories on servers are like folders on a Mac or in Windows. They can contain files and other directories, and to view the contents of a directory you have to be in that directory. To see what directory you are in, type pwd at your prompt.
As soon as you login you are automatically in a directory that is organized by the type of account you have (student, faculty, staff, alumn or guest), year of entry (for students), and username. This is also known as your home directory. Here are examples of each type of directory:
You can change directories within your home directory, which is similar to opening folders on your hard drive on a Mac or Windows computer.
Change Directory: cd
The command cd stands for change directory.
Within your home directory, you can create new directories and put other directories in those, just as you can create folders on your hard drive and put stuff in there. However, in UNIX you cannot just double click to get in or out of them. For example: If the fictitious student Alex Corbie (96F) had a directory called "pics/" in the directory public_html/, it would look like this when she typed pwd from within that folder:
To move to public_html/ she would type cd public_html/ at the prompt.
To move to pics/ from there, she would type: cd pics/
If she wanted to get directly to pics/ from her home directory, she would type: cd public_html/pics/
To move back one level, type cd .. and to get back to her home directory, type only cd.
Make Directories and Remove Them: mkdir and rmdir
The command mkdir stands for make directory. The command rmdir stands for remove directory.
The correct syntax is:
mkdir directoryname and rmdir directoryname
Once you have made a new directory you can copy files into it or move it into another directory (cp) or create new files from within it (cd then pico).
Change the Permissions on Files and Directories: chmod
The command chmod stands for change mode.
This allows you to change the read/write access privileges people have to your files (including yourself). This is most often used in the context of webpages, but can be useful in many other ways.
When you do an ls -l (explained above), the first column on the left is a weird looking row of dashes and letters, something like this:
-rw-r--r-- or maybe something like drwxr-xr-x
Believe it or not, this actually means something! The line is divided into 4 sections like this: d|rwx|r-x|r-x
Section 1 is the first symbol, either a letter (d) or a dash (-). "-" indicates a file, "d" indicates a directory.
Section 2 is the next 3 symbols, which correspond to your access privileges.
Section 3 is the next 3 symbols, which correspond to the access privileges of other people who share your group on stout (student, fac/staff, guest, etc).
Section 4 is the next 3 symbols which correspond to everyone else in the world's access.
We are only concerned with the last 3 sections, each of which consists of 3 symbols, either a dash or a letter; and each letter always appears in the same position in the section.
- no permission/access.
r means Readable (1st position)
w means Writable (2nd position)
x means Executable (3rd position - for programs, webpages with java, etc.)
So, when we look at each section we know who has what permissions based on what section we are looking at.
r-- means read only
-w- means write only
--x means execute only
rwx means read/write/execute
rw- means read/write
Now how do you go about changing these permissions? It is easier than you'd think. You have to decide 3 things for each file you want to change:
1. what you want your access to be
2. what you want other stout-users' access to be
3. what you want the rest of the world to see
Each of these 3 things corresponds to a number (0-7) in a 3-digit code. When you change the permissions on a file, all you do is change the code. You do this by typing chmod [###] [filename], where [###] is the 3-digit code and [filename] is the name of the file whose permissions you are changing.
Here is how you figure out what the code should be for each file or directory:
1st # you
2nd # people on stout
3rd # everyone in world
0 = no access (---)
1 = execute (--x)
2 = write (-w-)
3 = write execute (-wx)
4 = read (r--)
5 = read execute (r-x)
6 = read write (rw-)
7 = read write execute (rwx)
If you want to be able to have full access to a file, the first number should be 7. If you do not want anyone else to be able to read or change a file, the second two numbers should be 0. If you want a file to be read-only to just stout people, the second number should be 4 and the third should be 0. Etc.
To make a file read/writable by only you, the command is: chmod 600 [filename]
When you type ls -l [filename] you will see this:
-rw------- 1 abc96 student 12 Nov 30 13:40 filename
To make a file read/writable by you, but read only to stout and the rest of the world:
chmod 644 myhomepage.html
and your listing would be:
-rw-r--r-- 1 abc96 student 12 Nov 30 13:40 filename
(If you need more information on how to use chmod look at the man pages by typing man chmod at the prompt.)
© 2014 Hampshire College 893 West Street Amherst, MA 01002 . 413.549.4600