This is a brief summary of some Unix concepts that will be important for this course.
man ls displays the manual page for the ls command man man displays the manual page for the man command man -k directory displays a list of manual pages about "directory"It is important to understand how to read the "synopsis" section of a man page.
[ ] are used to indicate optional agruments to the command
/export/home/r/rcapra/unc/inls760/lectures
There are several special notations you can use in paths:
~ is a shortcut for your home directory . is the current working directory .. is the parent directory of the current directory / is the "root" level directory, the top of all directoriesExamples:
on ruby, these two paths refer to the same directory: ~rcapra/unc/inls760 /export/home/r/rcapra/unc/inls760 given the following directory structure: inls760 / | \ lectures p0 p1 with present/current working directory = inls760 the following are (slightly) convoluted examples illustrating paths: lectures/./../p0/.. refers to inls760 p0/../p1/././../lectures refers to lectures p0/../p1/././../p0/p1 is not a valid directory
Example:
[rcapra@ruby lectures]$ ls lect1-bkup.ppt lect1.pdf lect1.ppt lect1.ps lect2.ppt [rcapra@ruby lectures]$ ls *.ppt lect1-bkup.ppt lect1.ppt lect2.ppt [rcapra@ruby lectures]$ ls lect1.* lect1.pdf lect1.ppt lect1.ps [rcapra@ruby lectures]$ ls * lect1-bkup.ppt lect1.pdf lect1.ppt lect1.ps lect2.ppt [rcapra@ruby lectures]$
Short listing:
[rcapra@ruby lectures]$ ls lect1-bkup.ppt lect1.pdf lect1.ppt lect1.ps lect2.pptLong listing, all files:
[rcapra@ruby lectures]$ ls -al total 656 drwx------ 2 rcapra users 4096 Jan 18 22:31 . drwx------ 7 rcapra users 4096 Jan 22 21:52 .. -rw-r--r-- 1 rcapra users 112128 Jan 16 17:24 lect1-bkup.ppt -rw------- 1 rcapra users 58914 Jan 17 00:24 lect1.pdf -rw-r--r-- 1 rcapra users 112128 Jan 16 17:24 lect1.ppt -rw-r--r-- 1 rcapra users 238437 Jan 17 00:19 lect1.ps -rw-r--r-- 1 rcapra users 112128 Jan 16 17:23 lect2.ppt
The cat command is often used to output the contents of a file to STDOUT (for more information on STDOUT, see below).
[rcapra@ruby lectures]$ cat foo This is a test. This file has two lines. [rcapra@ruby lectures]$
If you want to see the contents of a long file, you can use the "less" command to view it using the "less" pager.
When in less, you can use the space bar to page down, and the up arrow key to go up in the file.
When you are done viewing the file, press q.
[rcapra@ruby lectures]$ less foo
Example using the following directory structure:
inls760 / | \ lectures p0 p1 [rcapra@ruby lectures]$ cd .. [rcapra@ruby inls760]$ cd p0 [rcapra@ruby p0]$ cd ../lectures [rcapra@ruby lectures]$
[rcapra@ruby lectures]$ pwd /export/home/r/rcapra/unc/inls760/lectures
[rcapra@ruby lectures]$ ls lect1-bkup.ppt lect1.pdf lect1.ppt lect1.ps lect2.ppt [rcapra@ruby lectures]$ cp lect1.ps foo [rcapra@ruby lectures]$ ls foo lect1-bkup.ppt lect1.pdf lect1.ppt lect1.ps lect2.ppt
[rcapra@ruby lectures]$ ls foo lect1-bkup.ppt lect1.pdf lect1.ppt lect1.ps lect2.ppt [rcapra@ruby lectures]$ mv foo lect1-bkup.ps [rcapra@ruby lectures]$ ls lect1-bkup.ppt lect1-bkup.ps lect1.pdf lect1.ppt lect1.ps lect2.ppt [rcapra@ruby lectures]$ mv lect1-bkup.ps .. [rcapra@ruby lectures]$ cd .. [rcapra@ruby inls760]$ ls lect1-bkup.ps lectures p0 p1
rm foo.txt removes (deletes) the file foo.txt
cat foo.txt displays the contents of file foo.txt
mkdir foo creates a new subdirectory foo
rmdir foo removes the subdirectory foo (must be empty)
It is very important to understand these permissions and how to set them, or you may open your system and files up to threats.
Unix permissions involve three sets of users:
[rcapra@ruby lectures]$ ls -al total 656 drwx------ 2 rcapra users 4096 Jan 18 22:31 . drwx------ 7 rcapra users 4096 Jan 22 21:52 .. -rw-r--r-- 1 rcapra users 112128 Jan 16 17:24 lect1-bkup.ppt -rw------- 1 rcapra users 58914 Jan 17 00:24 lect1.pdf -rw-r--r-- 1 rcapra users 112128 Jan 16 17:24 lect1.ppt -rw-r--r-- 1 rcapra users 238437 Jan 17 00:19 lect1.ps -rw-r--r-- 1 rcapra users 112128 Jan 16 17:23 lect2.pptFor each item in the listing, the permissions are shown first, like this:
drwxrwxrwxSplit into sections, they are:
d rwx rwx rwx | | | | directory user group otherIf a letter appears in the listing, then that permission is granted. For example, consider the file lect1.ps:
-rw-r--r-- 1 rcapra users 238437 Jan 17 00:19 lect1.psThis line indicates that:
For directories, read permission means that you can do an "ls" in the directory.
For directories, write permission means that you can store files that you own in that directory and that you can change the contents of the directory (e.g. you can mv files in it).
For directories, execute permission means that you can use the directory in a path.
[rcapra@ruby lectures]$ ls -l lect1.ps -rw-r--r-- 1 rcapra users 238437 Jan 17 00:19 lect1.ps [rcapra@ruby lectures]$ chmod go-r lect1.ps [rcapra@ruby lectures]$ ls -l lect1.ps -rw------- 1 rcapra users 238437 Jan 17 00:19 lect1.ps [rcapra@ruby lectures]$ chmod g+w lect1.ps [rcapra@ruby lectures]$ ls -l lect1.ps -rw--w---- 1 rcapra users 238437 Jan 17 00:19 lect1.ps [rcapra@ruby lectures]$ ls -al total 656 drwx------ 2 rcapra users 4096 Jan 23 12:41 . drwx------ 7 rcapra users 4096 Jan 22 22:29 .. -rw-r--r-- 1 rcapra users 112128 Jan 16 17:24 lect1-bkup.ppt -rw------- 1 rcapra users 58914 Jan 17 00:24 lect1.pdf -rw-r--r-- 1 rcapra users 112128 Jan 16 17:24 lect1.ppt -rw--w---- 1 rcapra users 238437 Jan 17 00:19 lect1.ps -rw-r--r-- 1 rcapra users 112128 Jan 16 17:23 lect2.ppt [rcapra@ruby lectures]$ chmod go-rwx * [rcapra@ruby lectures]$ ls -al total 656 drwx------ 2 rcapra users 4096 Jan 23 12:41 . drwx------ 7 rcapra users 4096 Jan 22 22:29 .. -rw------- 1 rcapra users 112128 Jan 16 17:24 lect1-bkup.ppt -rw------- 1 rcapra users 58914 Jan 17 00:24 lect1.pdf -rw------- 1 rcapra users 112128 Jan 16 17:24 lect1.ppt -rw------- 1 rcapra users 238437 Jan 17 00:19 lect1.ps -rw------- 1 rcapra users 112128 Jan 16 17:23 lect2.ppt
As an example, try the following:
[rcapra@ruby lectures]$ cat foo charlie abel baker charlie abel [rcapra@ruby lectures]$ sort foo abel abel baker charlie charlie [rcapra@ruby lectures]$ sort foo > bar [rcapra@ruby lectures]$ cat bar abel abel baker charlie charlie [rcapra@ruby lectures]$ sort < foo abel abel baker charlie charlie [rcapra@ruby lectures]$ sort < foo | uniq > bar [rcapra@ruby lectures]$ cat bar abel baker charlie [rcapra@ruby lectures]$