A TEXT POST

Unix Basics

Intro

UNIX is an operating system which was first developed in the 1960s, and has been under constant development. Originally UNIX was a command-line based operating system, like DOS.

Terminal

Each UNIX desktop comes with a Terminal program similar to the Command Prompt in Microsoft Windows operating system.

Using the Terminal - Working with directories

Listing files and directories

ls list the content (files and folders) of the current working directory

ls –a list all the files and directories including hidden files in the current working directory

Making Directories

mkdir myFolder create a new empty directory into the current working directory named myFolder

Changing to a different directory

cd myFolder change the current working directory to the specified directory which resides in the current working directory (in this case)

cd changes the current working directory to the home directory

The directories . and ..

cd . the current directory (does not change directory)

cd .. go to the parent directory

Pathnames

pwd print the full path of the current working directory

Using the Terminal - Working with files

Creating Files

Many people create files using a text editor, but you can use the command cat to create files without learning a text editor. To create a practice file (named firstfile) and enter one line of text in it, type the following at the % prompt:

cat > firstfile (Press the Enter/Return key.)

This is just a test.(Press the Enter/Return key.)

Stop file entry by typing Control-d on a line by itself. (Hold down the Control key and type d.) On your screen you will see:

% cat > firstfile
This is just a test.
^D

One way to examine the contents of the file you’ve just created is to enter this at the % prompt:

cat firstfile

Copying a File

To make a duplicate copy of a file, use the command cp. For example, to create an exact copy of the file called firstfile, you would type:

cp firstfile secondfile

The result is two files with different names, each containing the same information. The cp command works by overwriting information. If you create a different file called thirdfile and then type the following command:

cp thirdfile firstfile

you will find that the original contents of firstfile are gone, replaced by the contents of thirdfile.

Renaming a File

Unix does not have a command specifically for renaming files. Instead, the mv command is used both to change the name of a file and to move a file into a different directory.

To change the name of a file, use the following command format (where thirdfile and file3 are sample file names):

mv thirdfile file3

The result of this command is that there is no longer a file called thirdfile, but a new file called file3 contains what was previously in thirdfile.

Like cp, the mv command also overwrites existing files. For example, if you have two files, fourthfile and secondfile, and you type the command

mv fourthfile secondfile

mv will remove the original contents of secondfile and replace them with the contents of fourthfile. The effect is that fourthfile is renamed secondfile, but in the process secondfile is deleted.