UNIX is an operating system (like Windows or Mac OS X, which is actually based on UNIX). It was written in the early 1970s.
In the mid-1980s, Richard Stallman and the Free Software Foundation tried to write a free (as in "free speech," not "free beer") version of UNIX that anyone would be able to use, read, modify, etc. But they were having a hard time developing the kernel (the central part of an operating system -- the part of the OS that coordinates between software and hardware).
Then, in the early 1990s, Linus Torvalds wrote an open OS kernel that he named "Linux." It behaved just like UNIX and worked with what Stallman/FSF had produced. It wasn't UNIX, exactly -- but it behaved just like UNIX and worked. It was a great boon to the open-source software community.
The shell is one way to control what an operating system does. It's an alternative to point-and-click graphical interfaces, like you probably use most of the time on your computer. Rather than moving a mouse around, you type commands. The shell looks like this:
Many people (especially programmers) like to work in the shell because it's more precise and, once you learn how to work it, faster. (Windows equivalent: cmd. Mac equivalent: Terminal)
Also, if you become a real command-line hero, strange things will start to happen a la The Matrix.
If you want to learn the shell, refer to this and read through it. It's worth your time. We'll use our own Linux box -- binx -- for problem set 00. So you should continue reading this document.
Also, you should DEFINITELY be a sysop. They are the best.
You can control your own physical computer -- that is, your Windows or Mac machine -- using a shell. On Mac, you'll open up Terminal. On Windows, Start > cmd (stands for "command line"). But we'll actually use binx to work with the shell.
We've got a server (a really heavy-duty, reliable computer connected to the internet) called binx set up on Blair's campus. That computer has a lot of stuff on it, including our website, BILL, and a Java compiler.
One thing we'll want to be able to do is use that computer, and we can do that remotely from another computer. That way we can do things like write/compile/run Java programs, check our @mbhs.edu email addresses, etc.
Open up Terminal. Then:
SSH = "secure shell." Google if you care.
Plenty of info here on how to use Terminal like a champion.
You'll need a program like PuTTy, which will let you log in (over the Internet) to binx. See the demo before for instructions on how to use PuTTY for our purposes.
Remember that Unix is case sensitive
pwd : print the working (current) directory - tells you where you are.
cd child : change directory, where 'child' is a directory below the current one. Directories are separated by "/". "cd .." takes you to the parent directory. "cd" (no arguments) takes you to the home directory for your account.
mkdir child : creates a directory below the current one.
chmod permission-codes filename : changes the permissions for a file or dir. See full list of permission codes
e.g. chmod 700 myfile.txt : set 'myfile.txt' to be readable/writable only by me.
chmod 777 stuff/ -R : set all files in 'stuff' directory to be readable/writable by everyone.
ls : lists files and directories in the current directory.
ls -l : lists files with details of size, date, etc.
rm filename : removes a file permanently.
mv filename newname : renames a file
mv filename newlocation : moves a file to a different directory
cp filename destination: copies a file to the destination
chmod options filename : changes the permissions on a file
man topic : read the help pages on a command
pico filename : starts the text editor and opens the specified file.
cat filename : displays the text in a file
pine : starts the email program
Your username is the first 2 letters of your first name followed by 6 letters of your last name.
George Washington would be gewashin
Joe Lee would be jolee
Your password is -- at the start -- the same as your school computer password. You should feel free to change it.
Open up Terminal and type
Then follow the same steps as for the PuTTy screenshots above.
tells us what files are present. In other words, it lists everything in the current directory. At first, when you do this, you won't see any files, because nothing currently exists in your home directory. We'll change that shortly.
Type mkdir folderName to make a new folder. Of course, that makes a folder named "folderName." So replace "foldername" with whatever you want. For us, let's call the folder adsa.
Then you can ls again to confirm that the new folder appeared.
Right now, anyone can see your folder and what's inside. We want to make it so only you can see that information. To modify the folder's permissions, use:
chmod 700 <directory name>
or in this case...
chmod 700 adsa
Afterward, you'll go right back to the command prompt. If that happens, it worked.
cd stands for "change directory." It's the equivalent of double-clicking a folder in Windows Expolorer to go into that folder.
(you could type cd a and then hit "tab" to autocomplete. Hit tab again if you want the next option. etc.)
ls again to see what's there. There's nothing yet. See how it shows your location next to your username? The prompt now reads:username@binx:~/adsa
If you wanted to change back up to the parent directory, type:
Just make sure to change back to /adsa before the next step!
We'll use Pico, a common command-line text editor. Here are some common commands.
Type pico and hit enter to launch the editor:
Type your code here. You'll only be able to navigate with the keyboard.
(Careful -- there's an error in this code that you'll have to fix!)
ctrl+O (written ^O in lots of documentation) saves.
You could add a filepath to the name of the file if you wanted to save it somewhere else -- /home/chen/javastuff/HelloWorld.java
We won't, though. Just save it as HelloWorld.java.
Now Pico knows that this is a Java file, so it's colored our code nicely! Thanks, Pico!
Type ^X (ctrl+X) to quit Pico.
Let's quickly see what's inside the file we just wrote:
Remember, before we can run a Java program, we have to translate it into a language that the Java Virtual Machine can understand -- that's Java bytecode.
The Java compiler is called javac, so that's the command we use to compile our code.
If you ls again, you should see HelloWorld.java. Now compile the program you just wrote:
(remember, you could type javac H and then tab-complete it, just like before! mmmm feel that SPEED)
Now, ls again. You'll see that HelloWorld.class has appeared. That's the file that the Java Virtual Machine will use.
We get to the Java Virtual Machine via a Java interpreter called java.
To run your program, type
(remember: java H TAB YEAH SON I AM LIKE A CHEETAH)
Hooray, "Hello, World!" prints!
Suppose you need to go back into HelloWorld.java and make some edits. Just type
or, for us...
That will take open up HelloWorld.java in pico. If you just type pico, it'll give you a blank document again.
Note: Make sure you remember to re-compile your code (javac) before you run it again (java) if you make any changes.
Let's rename a file. I used pico to create and save a text file named TestFile.txt
(You can do this too, in order to practice.)
The mv command both moves and renames a file. For renaming, it's in the form mv <oldname> <newname>. Let's first use it to rename:
mv TestFile.txt RenamedTestFile.txt
We use mv to move a file, too. It will be in the format
mv <filename> <newlocation>
First, let's make a place for it to go. Remember that ".." refers to the "parent directory." So let's make a new directory:
Normally, we'd trust that the folder was created in the right place (i.e. inside the current location's parent directory). But this is our first time, so let's confirm.
Type cd to go back to your home directory. In this case, we also could have typed cd .. to back to the immediate parent directory, but they happen to be the same place in this situation. Then ls again:
Look! testfolder exists now! Awesome. Now let's move that file RenamedTestFile.txt from /adsa into /testfolder.
Two ways you could do this. (Remember! Use tab complete!)
cd into testfolder to make sure it worked!
If you wanted to move the file from the testfolder to the parent directory, you could type:
mv testfolder/RenamedTestFile.txt ..
Let's now delete that useless test file.
BE CAREFUL WHEN DELETING FILES.
You could do this from the home directory by using the filepaths, but let's just navigate into testfolder.
ls again and you'll see the file is no longer there.
Hey, that folder testfolder is pretty useless. Let's get rid of it.
cd back to the home directory.
This will delete a directory...but only if there's nothing in it.
If you want to delete a directory that has stuff in it, you'll type
rmdir -rf directoryname
BUT BE CAREFUL. It's unforgiving. Don't make a mistake.
If you want to clear the screen, just type clear
Scroll around. Commands are at the bottom. Send some emails. You'll use pine to submit ps00; you can find instructions on how to do it on the ps00 page.