UNIX Terminal
The UNIX terminal is a text based interface which a user can use to interact with the computer. It lets the user navigate directories, manipulate files, open files, and execute commands. Any UNIX based system, such as Linux or Macs, use this interface.
The terminal will open to the home directory. Each directory is separated with a backslash. There are many commands the user can use to navigate through the directories.
á pwd – ÒPrint working directory.Ó Outputs path you are currently in to the command line.
[eansley@cycle3 ~/Documents]$ pwd
/home/hoover/u3/eansley/Documents
á ls – ÒList.Ó Lists files in the current directory.
[eansley@cycle3 ~/Documents]$ ls
MATLAB
á cd <directory> – ÒChange directory.Ó Changes to specified directory
[eansley@cycle3 ~/Documents]$ cd MATLAB/
[eansley@cycle3 MATLAB]$
á cd .. – Goes up one directory level
[eansley@cycle3 MATLAB]$ cd ..
[eansley@cycle3 ~/Documents]$
á cd ~ – Goes to the home directory
[eansley@cycle3 ~/Documents]$ cd ~
[eansley@cycle3 ~]$ pwd
/home/hoover/u3/eansley
á mv <from> <to> – ÒMove.Ó Moves a file from one location to another and renames it in the new directory. (Removes from first location)
[eansley@cycle3 ~/Documents]$ mv ~/Documents/example.txt ~/Desktop/exampleNew.txt
á cp <from> <to> – ÒCopyÓ Copies a file to a new location. (Keeps in first location)
[eansley@cycle3 ~/Documents]$ cp ~/Downloads/example.txt ~/Desktop/exampleNew.txt
á mkdir <directory name> – ÒMake Directory.Ó Makes a new directory in the current location
[eansley@cycle3 Example]$ ls
[eansley@cycle3 Example]$ mkdir NewDir
[eansley@cycle3 Example]$ ls
NewDir
á rmdir <directory name> – ÒRemove Directory.Ó Removes an empty directory
[eansley@cycle3 Example]$ ls
NewDir
[eansley@cycle3 Example]$ rmdir NewDir/
[eansley@cycle3 Example]$ ls
[eansley@cycle3 Example]$
á touch <file> – Updates modification date to the file, or creates a new file if the file doesnÕt exist
[eansley@cycle3 Example]$ touch File1.txt
[eansley@cycle3 Example]$ ls
File1.txt
á rm <file> – ÒRemove file.Ó Removes a file from the directory.
[eansley@cycle3 Example]$ rm File1.txt
[eansley@cycle3 Example]$ ls
[eansley@cycle3 Example]$
á cat <file> – Sends file to standard output in the terminal
[eansley@cycle3 Example]$ cat File1.txt
This is a text file.
Here is text.
[eansley@cycle3 Example]$
á sudo command – ÒSuperuser do.Ó Gives the user temporary root access.
á grep keyword <file> – Searches a file for keywords
If you wish to use the current directory in a command, you can use a Ò.Ó in place of the directory.
[eansley@cycle3 ~/Documents]$ cp ~/Documents/example.txt .
The above example will copy the Òexample.txtÓ file and put it in the Documents (current) directory.
Files and directories have permissions detailing who can access them and to what extent. There are three types of permissions: read (r), write (w), and execute (e). These three permissions can be set for three different groups: the directory owner, the people in the same group as the directory owner, and the public. The command to view the current permissions of a file is
Ôls –l <file>Õ.
[eansley@cycle3 Example]$ ls -l File1.txt
-rw-r--r-- 1 eansley people 62 Feb 21 13:34 File1.txt
The permissions on the file give me (the owner) read and write access, and gives everyone else read only access. The first dash in Ô-rw-r--r--Õ denotes that these permissions are for a file. If I were checking the permissions for a directory, the Ô-Õ would be replaced by a ÔdÕ for directory. The next three spaces Ôrw-Õ are the permissions for the own. This says that I have permission to read the file and write to it, but not execute it. The next three Ôr--Õ and the last three Ôr--Õ grant read only access to people within the same group as me and the general public, respectively.
Each permissions is represented by a number. 1 is execute, 2 is write, and 4 is read. So, the command Ôchmod 444Õ grants read only permissions to all three groups. The first 4 applies to the owner, the second 4 applies to the group, and the third 4 applies to the public.
[eansley@cycle3 Example]$ chmod 444 File1.txt
[eansley@cycle3 Example]$ ls -l File1.txt
-r--r--r-- 1 eansley people 62 Feb 21 13:34 File1.txt
To grant read and write permissions to everyone, we add ÔreadÕ and ÔwriteÕ together. So, since 4+2=6, the command Ôchmod 666Õ would grant these permissions.
[eansley@cycle3 Example]$ chmod 666 File1.txt
[eansley@cycle3 Example]$ ls -l File1.txt
-rw-rw-rw- 1 eansley people 62 Feb 21 13:34 File1.txt
ItÕs a good idea to never give the public the ability to write to your files. In this case, we would want to give the owner and the groups access to read and write, but only read access to the public by using Ôchmod 664Õ as a command.
[eansley@cycle3 Example]$ ls -l File1.txt
-rw-rw-r-- 1 eansley people 62 Feb 21 13:34 File1.txt
The permissions go as follows: 7 is read/write/execute (4+2+1), 6 is read/write, 5 is read/execute (4+1), 4 is read, 3 is write/execute (2+1), 2 is write, and 1 is execute.
With any of the UNIX commands, the help file is always available by typing the Ô--helpÕ flag after the command. This will print what the command does, and any flags (and their meanings) that can be appended to the command. Here is the beginning of the help file for the list command.
[eansley@cycle3 ~]$ ls --help
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.
Mandatory arguments to long options are mandatory for short options too.
-a, --all do not ignore entries starting with .
-A, --almost-all do not list implied . and ..
--author with -l, print the author of each file
-b, --escape print C-style escapes for nongraphic characters
--block-size=SIZE scale sizes by SIZE before printing them. E.g., '--block-size=M' prints sizes in units of 1,048,576 bytes. See SIZE format below.
-B, --ignore-backups do not list implied entries ending with ~
The terminal is a powerful interface that allows users to navigate through the computerÕs directories and manipulate files. This is just a brief introduction that contains the most common commands used. There are many more commands which are outlined in many UNIX tutorials available for free online.
http://www.ee.surrey.ac.uk/Teaching/Unix/unix7.html
http://cs.colby.edu/maxwell/courses/tutorials/terminal/
http://www.linux.org/threads/file-permissions-chmod.4094/
Author: Emily Ansley
CSC 210W