Difference between revisions of "UNIX Tutorial"

From PrattWiki
Jump to navigation Jump to search
 
(Other Commands)
 
(43 intermediate revisions by the same user not shown)
Line 1: Line 1:
The following tutorial has been a part of the EGR 53 lab manual for several years.  Hopefully, this new web-based version will prove to be a useful resource for students in the course as well as the rest of the Pratt family.
+
The following tutorial has been a part of the EGR 103 lab manual for several years, and its contents were predominantly organized and collected by Michael Ehrenfried, Pratt 2004.  Hopefully, this new web-based version will continue to be a useful resource for students in the course as well as the rest of the Pratt family.  In 2015, the tutorial was re-written to reflect the fact that Duke no longer has any physical Linux machines but rather provides access to a Linux environment through a virtual cluster.
  
  
Line 16: Line 16:
 
user.
 
user.
  
When using the public UNIX clusters, under the new Graphical User
+
Note that when you connect to a Linux server through ssh, you will automatically be taken to your
Interface, a terminal (command-line driven) window may not open
+
home directory.   
automatically when you log in.  Therefore, when you first log in, you
 
will merely see a desktop with some icons in the upper left corner.
 
There will also be a menu bar with graphical menus and two
 
text menus called "Applications" and "Actions." 
 
One way to open a terminal window is to drag down the "Applications"
 
menu, go into the "System Tools" submenu, and then select
 
"Terminal."  Another method is to right-click in the background and
 
select "Open Terminal" from the menu.  These two methods of opening
 
the program yield identical results.
 
 
 
If you would like for your menu bar to have an "Open Terminal" icon,
 
you can put
 
one there simply clicking to open the "Applications" menu,
 
navigating to the "Terminal" selection, and instead of letting go of
 
the mouse, drag the item off the menu and up into the bar at the top
 
of the screen.  This will work with any of the items in the
 
"Application" menu as long as you remember to click, not click-hold,
 
the word "Applications.'"
 
 
 
When you are finished and your menu bar is the way you like it (also,
 
you can leave terminal windows open if you wish for them to
 
appear automatically when you log in next time), simply select the
 
option "Save Current Setup" right before clicking "OK" to log
 
out.
 
 
 
When you open the Terminal, you will automatically be taken to your
 
home directory.  Note that a graphical representation of this
 
can be obtained by double-clicking the house icon that says
 
"YourID's Home" on the desktop; however, it is not advisable
 
that you do things this way (though it may seem easier at first).  It
 
is extremely important that you learn to use the UNIX commands in the
 
terminal for many reasons, one of which being that you cannot access
 
this graphical interface remotely (and, therefore, if you want to
 
access files on your account from your personal computer, you
 
must know the UNIX commands or you will not be able to).
 
  
 
==Structure of the Command Line - The Sentence==
 
==Structure of the Command Line - The Sentence==
Line 66: Line 31:
 
listed below.
 
listed below.
  
<center>
+
{|class="wikitable"
<math>
+
| '''Command''' || '''What it does''' || '''Graphical Users Equivalent'''
\begin{tabular}{|c|c|c|} \hline
+
|-
\textbf{Command} & \textbf{What it does}& \textbf{Graphical Users
+
| [[#Print_Working_Directory_-_pwd|pwd]] || prints the name of the working directory || path given in window  
Equivalent } \\ \hline
+
|-
{\tt pwd} & prints the name of the working directory & path
+
| [[#List_Contents_-_ls|ls]] || lists files in a directory || viewing a folder's contents  
given in window \\
+
|-
{\tt ls} & lists files in a directory & viewing a folder's contents \\
+
| [[#Change_Directory_-_cd|cd]] || changes a directory || double clicking on a folder
{\tt cd} & changes a directory & double clicking on a folder \\
+
|-
{\tt cp} & copies a file or folder & copying the contents of a file or
+
| [[#Copy_-_cp|cp]] || copies a file or folder || copying the contents of a file or folder
folder\\
+
|-
{\tt mv} & moves/renames a file or directory & dragging an item to a new
+
| [[#Move_(or_Rename)_-_mv|mv]] || moves/renames a file or directory || dragging an item to a new place/renaming it
place/renaming it\\
+
|-
{\tt rm} & removes a file & dragging a file to the trash {\it and}
+
| [[#Remove_a_File_(Delete)_-_rm|rm]] || removes a file || dragging a file to the trash ''and'' emptying it
emptying it\\
+
|-
{\tt mkdir} & creates a new directory & creating a new folder \\
+
| [[#Make_a_Directory_-_mkdir|mkdir]] || creates a new directory || creating a new folder
{\tt rmdir} & removes an {\it{empty}} directory & dragging folder to the trash and
+
|-
emptying it\\ 
+
| [[#Remove_a_Directory_-_rmdir|rmdir]] || removes an ''empty'' directory || dragging folder to the trash and
{\tt man} & pulls up manual pages & opening help files\\\hline
+
emptying it
\end{tabular}
+
|-
</math>
+
| [[#Help_Manual_-_man|man]] || pulls up manual pages || opening help files
</center>
+
|}
  
 
===Files and Directories - The Objects===
 
===Files and Directories - The Objects===
Line 150: Line 115:
 
tasks are:
 
tasks are:
  
<center>
+
{|class="wikitable"
<math>
+
| '''Symbol''' || '''What it means'''
\begin{tabular}{|c|c|} \hline
+
|-
\textbf{Symbol} & \textbf{What it means} \\ \hline
+
| . || Current directory
{\tt{.}}  & Current directory \\
+
|-
{\tt{..}} & Parent directory (the directory above the current
+
| .. || Parent directory (the directory above the current one)
one)\\
+
|-
{\tt $\sim$ } & Current user's home directory \\
+
| ~ || Current user's home directory
{\tt $\sim$ID} & ID's home directory\\ \hline
+
|-
\end{tabular}
+
| ~ID || ID's home directory
</math>
+
|}
</center>
+
 
  
 
Note that these shortcuts can be used as parts of relative or absolute
 
Note that these shortcuts can be used as parts of relative or absolute
 
paths and can be strung together.  For example,  
 
paths and can be strung together.  For example,  
<sourse lang="bash">
+
<source lang="bash">
 
cd ../../../a/b
 
cd ../../../a/b
 
</source>
 
</source>
Line 172: Line 137:
 
then going up a level, going up another level, going up another level,
 
then going up a level, going up another level, going up another level,
 
then from there entering the <code>a</code> directory, and from the <code>a</code>
 
then from there entering the <code>a</code> directory, and from the <code>a</code>
directory going into the <code>b</code> directory.  As another example,
+
directory going into the <code>b</code> directory.   
<source lang="bash">
 
cd ~mrg/public/EGR53
 
</source>
 
is an ''absolute'' path - the <code>~mrg</code> is a shortcut for the
 
absolute path <code>/afs/acpub/users/m/r/mrg</code>  - that will get into
 
Dr. G's home directory, from there the <code>public</code> directory, and
 
from there the <code>EGR53</code> directory.  Unlike the previous example,
 
this command will work the same from anywhere in UNIX, because it is
 
an absolute path.
 
  
 
===Wildcards===
 
===Wildcards===
 +
{|class="wikitable"
 +
|'''Symbol''' || '''What It Does'''
 +
|-
 +
| ? || one character wildcard
 +
|-
 +
| [LIST] || one character restricted wildcard
 +
|-
 +
| * || multi-character wildcard
 +
|}
 +
 
Wildcards are a powerful tool when you want to deal with multiple
 
Wildcards are a powerful tool when you want to deal with multiple
 
files or directories at once. The first of the wildcard characters is
 
files or directories at once. The first of the wildcard characters is
Line 215: Line 181:
 
include {''careerist'' and ''ct''.  It would ''not'' include
 
include {''careerist'' and ''ct''.  It would ''not'' include
 
''crate'', however, since nothing in the pattern replaces anything
 
''crate'', however, since nothing in the pattern replaces anything
after the <code>t</code>.
+
after the <code>t</code>. The command
 +
<source lang="bash">
 +
ls ~mrg/public/a*ing
 +
</source>
 +
will list all files in Dr. G's <code>public</code> directory that start with the letter <code>a</code>, end with the letters <code>ing</code>, and have any number of characters in between.  Note that as of 2013, however, users are not allowed access to any part of any other user's directory, and so on the Duke system, the command above will return either "Permission Denied" or "No such file or directory."
  
 
The <code>?</code> and <code>*</code> are the most used wildcards, and are often  
 
The <code>?</code> and <code>*</code> are the most used wildcards, and are often  
Line 221: Line 191:
 
beginning and end of patterns.  For example, <code>EGR*</code> would include all files
 
beginning and end of patterns.  For example, <code>EGR*</code> would include all files
 
beginning with ''EGR'', while <code>*.m</code> would include all files
 
beginning with ''EGR'', while <code>*.m</code> would include all files
that end in '.m'.  In summary:
+
that end in ''.m''.  The wildcards can also be used together:
 +
<source lang="bash">
 +
ls [a-z]???.dat
 +
</source>
 +
will list all files that begin with a lower case letter, have three characters after that letter, followed by a dot and the extension <code>dat</code>. 
 +
<source lang="bash">
 +
ls ~mrg/public/???*
 +
</source>
 +
will list all files that contain ''at least'' three characters.
  
<center>
 
<math>
 
\begin{tabular}{|c|c|c|} \hline
 
\textbf{Symbol} & \textbf{What It Does} \\ \hline
 
{\tt{?}}  & one character wildcard \\
 
{\tt [LIST]} & one character restricted wildcard\\
 
{\tt{*}} & multi-character wildcard\\ \hline
 
</math>
 
</center>
 
 
===Options - The Adverbs===
 
===Options - The Adverbs===
 
Commands often have options that are associated with them that allow
 
Commands often have options that are associated with them that allow
Line 251: Line 220:
 
This is usually represented by a dot (.) followed by an
 
This is usually represented by a dot (.) followed by an
 
identification tag.  Each program, or type of file will generally have
 
identification tag.  Each program, or type of file will generally have
a file extension traditionally associated with them (eg. Microsoft
+
a file extension traditionally associated with them (e.g. Microsoft
 
Word uses <code>.doc</code>).  In this course we will be using primarily [[MATLAB]] and
 
Word uses <code>.doc</code>).  In this course we will be using primarily [[MATLAB]] and
 
[[LaTeX]].  The table below identifies the extensions with which you
 
[[LaTeX]].  The table below identifies the extensions with which you
 
should become familiar.  
 
should become familiar.  
 
   
 
   
<center>
+
{|class="wikitable"
<math>
+
| '''Extension''' || '''Program Association''' || '''Type of File'''
\begin{tabular}{|c|c|c|} \hline
+
|-
\textbf{Extension} & \textbf{Program Association} & \textbf{Type of File} \\ \hline
+
| .py || Python ||  Python script
{\tt{.m}} & MATLAB & MATLAB script or function \\
+
|-
{\tt{.tex}} & \LaTeX & the uncompiled \LaTeX ~formatted document \\
+
| .m || MATLAB || MATLAB script or function  
{\tt{.dvi}} & kdvi & compiled \LaTeX ~document, which can be viewed \\
+
|-
{\tt{.ps}} & kghostview & a postscript file used for printing\\
+
| .mat || MATLAB || MATLAB-encoded data file
{\tt{.eps}} & Graphics & MATLAB graphs and other pictures \\ \hline
+
|-
\end{tabular}
+
| .tex || LaTeX || the uncompiled LaTeX formatted document
</math>
+
|-
</center>
+
| .dvi || evince || compiled LaTeX document, which can be viewed
 +
|-
 +
| .ps || evince || a postscript file used for printing
 +
|-
 +
| .eps || evince || encapsulated postscript (e.g. MATLAB graphs and other pictures)
 +
|-
 +
| .pdf || evince || a PDF file used for viewing and printing
 +
|}
  
 
Note, however, that UNIX is not nearly as dependent on extensions as
 
Note, however, that UNIX is not nearly as dependent on extensions as
Line 278: Line 254:
 
==Basic Commands==
 
==Basic Commands==
 
This section describes some of the essential UNIX commands that we
 
This section describes some of the essential UNIX commands that we
will be using in this course.  The <code>[ ]</code> are meant to be replaced
+
will be using in this course.  They are listed in the table above in the
by the type of objects that are described inside of them. Note that only select options
+
[[#The Command - The Action Verb|The Command - The Action Verb]] section.
are shown; browsing
+
 
 +
In the examples below, the <code>[ ]</code> and <code>< ></code> are meant to be replaced
 +
by the type of objects that are described inside of them. The square brackets represent required
 +
arguments while the angle brackets represent optional ones.  The symbol {{Vs}} in the example listings
 +
represents a space.
 +
 
 +
Note that only select options are shown; browsing
 
the <code>man</code> pages yourself will show you a complete list of
 
the <code>man</code> pages yourself will show you a complete list of
 
options.  Much of the information below is either copied from or
 
options.  Much of the information below is either copied from or
Line 289: Line 271:
 
This command prints the absolute path of the current directory.   
 
This command prints the absolute path of the current directory.   
  
===List contents - <code>ls</code>===
+
===List Contents - <code>ls</code>===
 
<source lang="bash">
 
<source lang="bash">
ls [options] [directory path to list]
+
ls <options> <directory path to list>
 
</source>
 
</source>
 
This command will list the directory contents.  
 
This command will list the directory contents.  
<center>
+
{| class="wikitable"
<math>
+
| '''Option''' || '''What it does'''
\begin{center} \begin{tabular}{|c|c|} \hline
+
|-
\bf{Option} & \bf{What it does} \\ \hline
+
| -a || lists all files and directories (including hidden ones)
{\tt -a}  & lists all files and directories (including hidden ones)\\
+
|-
{\tt -l} & lists in long format giving more information \\
+
| -l || lists in long format giving more information
{\tt -p} & puts a slash (/) after each name if the entry is a directory \\
+
|-
{\tt -r} & reverses (alphabetical or date) order of display of the files \\
+
| -p || puts a slash (/) after each name if the entry is a directory
{\tt -R} & recursively lists subdirectories encountered \\
+
|-
{\tt -t} & orders the files according to time rather than alphabetic order\\ \hline
+
| -r || reverses (alphabetical or date) order of display of the files
\end{tabular}
+
|-
</math>
+
| -R || recursively lists subdirectories encountered  
</center>
+
|-
 
+
| -t || orders the files according to time rather than alphabetical order
 +
|}
 
Note: These options can be combined.  For example,  
 
Note: These options can be combined.  For example,  
 
<source lang="bash">
 
<source lang="bash">
Line 316: Line 299:
 
===Change Directory - <code>cd</code>===
 
===Change Directory - <code>cd</code>===
 
<source lang="bash">
 
<source lang="bash">
cd [directory path]
+
cd <directory path>
 
</source>
 
</source>
 
This command changes the directory to the directory defined by the path.
 
This command changes the directory to the directory defined by the path.
<center>
+
{| class="wikitable"
<math>
+
| '''Example''' || '''Outcome'''
\begin{tabular}{l|l}
+
|-
{\bf Example} & {\bf What it does} \\ \hline
+
|cd{{Vs}}EGR103 || changes to the directory called EGR103 (if present) in your current directory
{\tt cd EGR53} & changes to the directory called EGR53 (if present) in your current directory \\
+
|-
{\tt cd ..} & changes to the parent directory (directory above the current one) \\
+
|cd{{Vs}}.. || changes to the parent directory (directory above the current one)
{\tt cd $\sim$} & changes to your root directory \\
+
|-
{\tt cd $\sim$/EGR53} & changes to the directory called EGR53 (if
+
|cd{{Vs}}~ || changes to your root directory
present) in your root directory \\
+
|-  style=white-space:nowrap
{\tt cd} & changes to your home directory
+
|cd{{Vs}}~/EGR103 || changes to the directory called EGR103 (if present) in your root directory
\end{tabular}
+
|-
</math>
+
|cd || changes to your home directory
</center>
+
|}
  
 
===Copy - <code>cp</code>===
 
===Copy - <code>cp</code>===
 
<source lang="bash">
 
<source lang="bash">
cp [options] [source directories/files] [destination directory/file]
+
cp <options> [source directories/files] [destination directory/file]
 
</source>
 
</source>
  
<center>
+
{|class="wikitable"
<math>
+
|'''Option''' || '''What it does'''
\begin{tabular}{|c|c|} \hline
+
|-
\textbf{Option} & \textbf{What it does} \\ \hline
+
| -i || copies interactively - asks before overwriting
{\tt -i} & copies interactively - asks before overwriting\\
+
|-
{\tt{-r}}  & copies recursively - must use when copying a directory\\ \hline
+
| -r || copies recursively - must use when copying a directory
\end{tabular}  
+
|}
</math>
+
 
</center>
 
  
<center>
+
{|class="wikitable"
<math>
+
|'''Example''' || '''Outcome'''
\begin{tabular}{l|p{10cm}}
+
|-
{\bf Example} & {\bf What it does} \\ \hline
+
| cp{{Vs}}File1{{Vs}}File2 || Copies the file <code>File1</code> and makes a new file called <code>File2</code> in the same directory.
{\tt{cp -r $\sim$mje7/public/lab1/ .}} & Copies the directory
+
|-
{\it{lab1}} and all its contents from {\it{$\sim$mje7/public/}} into
+
| cp{{Vs}}MyFile{{Vs}}FolderThatExists || Takes the file <code>MyFile</code> and makes a copy of it in a file also called <code>MyFile</code> which is inside the directory <code>FolderThatExists</code>. Note that if the folder does not, in fact, exist, then there will be a new ''file'' called <code>FolderThatExists</code> which is a duplicate of <code>MyFile</code>.  To avoid that mistake, use:
the current directory; the new copy is called {\tt lab1} \\ \hline
+
|-
{\tt{cp $\sim$mje7/public/lab1/* .}} & Copies all the files from {\it{$\sim$mje7/public/lab1}} into the current directory.  Note the subtle difference from the previous example.  Above, the directory and the files were copied together. Here, only the files are copied meaning the files would be in the current directory. \\ \hline
+
| cp{{Vs}}MyFile{{Vs}}FolderThatExists/ || Takes the file <code>MyFile</code> and makes a copy of it in a file also called <code>MyFile</code> which is inside the directory <code>FolderThatExists</code>. Note that if the folder does not, in fact, exist, then there be an error
{\tt{cp $\sim$mje7/public/intro* EGR53}} & Copies all the files
+
|-
beginning with {\tt intro} from mje7's {\tt{public}} directory to an {\tt{EGR53}} directory that is inside the current directory. \\
+
| cp{{Vs}}-r{{Vs}}~mje7/public/lab1/{{Vs}}. || Copies the directory <code>lab1</code> and all its contents from <code>~mje7/public/</code> into the current directory; the new copy is called <code>lab1</code>.
\end{tabular}
+
|-
</math>
+
|cp{{Vs}}~mje7/public/lab1/*{{Vs}}. || Copies all the files from <code>~mje7/public/lab1</code> into the current directory.  Note the subtle difference from the previous example.  Above, the directory and the files were copied together. Here, only the files are copied meaning the files would be in the current directory.  
</center>
+
|-  style=white-space:nowrap
 +
|cp{{Vs}}~mje7/public/intro*{{Vs}}EGR53 || Copies all the files beginning with <code>intro</code> from mje7's <code>public</code> directory to an <code>EGR53</code> directory that is inside the current directory.
 +
|}
  
 
===Move (or Rename) - <code>mv</code>===
 
===Move (or Rename) - <code>mv</code>===
 
<source lang="bash">
 
<source lang="bash">
mv [options] [source directories/files] [destination directory/file]
+
mv <options> [source directories/files] [destination directory/file]
 
</source>
 
</source>
<center>
+
{|class="wikitable"
<math>
+
|'''Option''' || '''What it does'''
\begin{tabular}{|c|c|} \hline
+
|-
\textbf{Option} & \textbf{What it does} \\ \hline
+
| -f  || move the file(s) without prompting even if it overwrites a file (default for file input)
{\tt{-f}} & move the file(s) without prompting even if it overwrites
+
|-
a \\
+
| -i || will prompt for conformation whenever the move would overwrite a file (default for console input)
& file (default for file input) \\ \hline
+
|}
{\tt{-i}} & will prompt for conformation whenever the move would
+
 
overwrite \\
+
 
& a file (default for console input)\\ \hline
+
{|class="wikitable"
\end{tabular}
+
|'''Example''' || '''Outcome'''
</math>
+
|-
</center>
+
| mv{{Vs}}foo.m{{Vs}}lab1/ || Moves a file <code>foo.m</code> into the <code>lab1</code> directory, which is found in the current directory.
<center>
+
|-
<math>
+
| mv{{Vs}}../lab1/*.tex{{Vs}}. || Move all files with the file extension <code>.tex</code> from the lab1 directory (which is found in the parent of the current directory) into the current directory.  
\begin{tabular} {l|p{12.5cm}}
+
|-  style=white-space:nowrap
{\bf Example} & {\bf What it does} \\ \hline
+
| mv{{Vs}}-f{{Vs}}foo.m{{Vs}}bar.m || Moves the file <code>foo.m</code> to a file <code>bar.m</code>. This is similar to renaming the file. If <code>bar.m</code> already exists the <code>-f</code> will cause this file to be overwritten automatically.
{\tt{mv foo.m lab1/}} & Moves a file {\it{foo.m}} into the {\tt{lab1}} directory, which is found in the current directory.\\ \hline
+
|}
{\tt{mv ../lab1/*.tex .}} & Move all files with the file extension {\tt{.tex}} from the lab1 directory (which is found in the parent of the current directory) into the current directory. \\ \hline
 
{\tt mv -f foo.m bar.m} & Moves the file {\tt{foo.m}} to a file {\tt{bar.m}}. This is similar to renaming the file. If {\tt{bar.m}} already exists the {\tt{-f}} will cause this file to be overwritten automatically. \\
 
\end{tabular}
 
</math>
 
</center>
 
  
===Remove a file (Delete) - <code>rm</code>===
+
===Remove a File (Delete) - <code>rm</code>===
 
<source lang="bash">
 
<source lang="bash">
rm [options] [directories/files]
+
rm <options> [directories/files]
 
</source>
 
</source>
 
'''Warning:''' These options are powerful and permanent.  
 
'''Warning:''' These options are powerful and permanent.  
<center>
+
{|class="wikitable"
<math>
+
|'''Option''' || '''What it does'''
\begin{center}
+
|-
\begin{tabular}{|c|c|} \hline
+
| -r || removes recursively all directories and subdirectories in
\textbf{Option} & \textbf{What it does} \\ \hline
+
the argument list
{\tt{-r}}  & removes recursively all directories and subdirectories in
+
|-
the argument list\\
+
| -i || prompts the user before removing any files (interactive)
{\tt{-i}}  & prompts the user before removing any files (interactive)\\
+
|-
{\tt{-f}} & remove all files without prompting the user (default setting)\\ \hline
+
| -f || remove all files without prompting the user (default setting)
\end{tabular}
+
|}
</math>
 
</center>
 
<center>
 
<math>
 
\begin{tabular}{l|p{12.5cm}}
 
{\bf Example} & {\bf What it does} \\ \hline
 
{\tt{rm foo.m}} & Removes (deletes) {\it{foo.m}} from the current directory \\ \hline
 
{\tt{rm -i *.m ../bar.m}} & Removes all files ending in {\it{.m}} from
 
the current directory, as well as {\it{bar.m}} from the parent
 
directory. The {\it{-i}} will cause UNIX to prompt the
 
user for permission to remove these files. \\ \hline
 
{\tt{rm -ir lab1/}} & Removes all of the contents of the the current
 
directory's {\it{lab1/}} including all subdirectories and their files.
 
It will also prompt the user for permission to remove these
 
files. \\
 
\end{tabular}
 
</math>
 
</center>
 
  
 +
{|class="wikitable"
 +
|'''Example''' || '''Outcome'''
 +
|-
 +
| rm{{Vs}}foo.m || Removes (deletes) <code>foo.m</code> from the current directory
 +
|-  style=white-space:nowrap
 +
| rm{{Vs}}-i{{Vs}}*.m{{Vs}}../bar.m || Removes all files ending in <code>.m</code> from the current directory, as well as <code>bar.m</code> from the parent directory. The <code>-i</code> will cause UNIX to prompt the user for permission to remove these files.
 +
|-
 +
| rm{{Vs}}-ir{{Vs}}lab1/ || Removes all of the contents of the the current directory's <code>lab1/</code> including all subdirectories and their files. It will also prompt the user for permission to remove these files.
 +
|}
  
 
===Make a Directory - <code>mkdir</code>===
 
===Make a Directory - <code>mkdir</code>===
Line 430: Line 400:
 
</source>
 
</source>
  
<center>
+
{|class="wikitable"
<math>
+
|'''Example''' || '''Outcome'''
\begin{center} \begin{tabular}{l|l}
+
|-
{\bf Example} & {\bf What it does}\\ \hline
+
| mkdir{{Vs}}lab1 || Makes a directory called <code>lab1</code> in the current directory.
{\tt{mkdir lab1}} & Makes a directory called {\it{lab1}} in the current directory. \\
+
|-
{\tt{mkdir ../junk}} & Makes a directory called {\it{junk}} in the parent of the current directory. \\
+
| mkdir{{Vs}}../junk || Makes a directory called <code>junk</code> in the parent of the current directory.
{\tt{mkdir $\sim$/foobar}} & Makes a directory called {\it{foobar}} in the user's home directory.\\
+
|-  style=white-space:nowrap
\end{tabular}
+
| mkdir{{Vs}}~/foobar || Makes a directory called <code>foobar</code> in the user's home directory.
</math>
+
|}
</center>
 
  
===Remove a Directory - <code>rmdir</code>===
+
===Remove a Directory - <code>rmdir</code>===
 
<source lang="bash">
 
<source lang="bash">
 
rmdir [directories]
 
rmdir [directories]
Line 449: Line 418:
 
===Help Manual - <code>man</code>===
 
===Help Manual - <code>man</code>===
 
<source lang="bash">
 
<source lang="bash">
man [options] [command name/keyword]
+
man <options> [command name/keyword]
 
</source>
 
</source>
This command brings up the manual pages for UNIX commands.
 
<center>
 
<math>
 
\begin{tabular}{|c|c|} \hline
 
\textbf{Option} & \textbf{What it does} \\ \hline
 
{\tt{-k [keyword]}}  & brings up descriptions of all manual pages
 
containing the {\tt keyword}\\ \hline
 
\end{tabular}
 
</math>
 
</center>
 
 
 
This command is the key to learning more about UNIX. To exit out of
 
This command is the key to learning more about UNIX. To exit out of
 
the manual without toggling to the end, just press <code>q</code>.  To move down
 
the manual without toggling to the end, just press <code>q</code>.  To move down
 
the various pages, press the spacebar.  
 
the various pages, press the spacebar.  
  
<center>
+
{|class="wikitable"
<math>
+
|'''Option''' || '''What it does'''
\begin{tabular}{l|l}
+
|-
{\bf Example} & {\bf What it does} \\ \hline
+
| -k [keyword] || brings up descriptions of all manual pages containing the <code>keyword</code>
{\tt man latex} & Brings up the manual pages for the {\tt latex} command\\
+
|}
{\tt man -k latex} & Brings up the summary descriptions of manual
+
 
pages containing the word {\tt latex}
+
{|class="wikitable"
\end{tabular}
+
|'''Example''' || '''Outcome'''
</math>
+
|-
</center>
+
| man{{Vs}}latex ||  Brings up the manual pages for the <code>latex</code> command
 +
|-  style=white-space:nowrap
 +
| man{{Vs}}-k{{Vs}}latex ||  Brings up the summary descriptions of manual pages containing the word <code>latex</code>
 +
|}
  
 
==Intermediate Commands==
 
==Intermediate Commands==
  
 
A summary of commonly-used commands are included in the table below.  In the long run, these commands will be relatively often-used by the average user.
 
A summary of commonly-used commands are included in the table below.  In the long run, these commands will be relatively often-used by the average user.
<center>
+
{|class="wikitable"
<math>
+
|'''Command''' || '''What it does'''
\begin{tabular}{|l|l|} \hline
+
|-
{\bf Command} & {\bf What it does} \\ \hline
+
| CTRL&nbsp;+&nbsp;Z ||  Suspends the most recently executed program  
{\tt CTRL + Z} & Suspends the most recently executed program \\ \hline
+
|-
{\tt bg} & runs the most recently executed program in the background \\ \hline
+
| bg ||  runs the most recently executed program in the background
{\tt fg} & runs the most recently executed program in the foreground. \\ \hline
+
|-
{\tt ps -u ID} & lists running processes for user ID\\ \hline
+
| fg ||  runs the most recently executed program in the foreground
{\tt kill [Job number]} & terminates the program with the job number entered. \\
+
|-
& {\footnotesize Note: The job number is on the line following the one
+
| ps&nbsp;-u&nbsp;ID ||  lists running processes for user ID
where the command was given} \\ \hline
+
|-
{\tt logout} & logs out of the computer that you have remotely logged into.\\ \hline
+
| kill&nbsp;[Job&nbsp;number] ||  terminates the program with the job number entered. The job number is on the line following the one where the command was given or can be found with the <code>ps</code> command above.
{\tt lpr [filename]} & Prints the file to the ePrint queue\\ \hline
+
|-
{\tt passwd} & Changes the user's password \\ \hline
+
| kill&nbsp;-KILL&nbsp;[Job&nbsp;number] ||  kill jobs that resist the <code>kill</code> command alone.
{\tt [program name] \&} & Runs the program in the background, so it
+
|-
does not lock up the xterm window \\ \hline
+
| logout ||  logs out of the computer that you have remotely logged into
{\tt du -ks [file/directory]} & Lists how much space a particular file
+
|-
or directory takes\\ \hline
+
| lpr&nbsp;[filename] ||  Prints the file to the ePrint queue
{\tt quota} & Shows how much disk space you have used of your quota \\ \hline
+
|-
{\tt ssh [IP address]} & logs into another computer \\
+
| passwd ||  Changes the user's password  
& {\footnotesize (eg. {\tt ssh teer14.oit.duke.edu} logs into the teer 14 computer)} \\ \hline
+
|-
{\tt w} & Lists the users logged into the same computer and the programs they are running \\ \hline
+
| [program&nbsp;name] & ||  Runs the program in the background, so it does not lock up the xterm window
{\tt who} & Lists of users logged into the same computer and their IP addresses \\ \hline
+
|-
{\tt xterm \&} & Call up an additional xterm window without locking
+
| du&nbsp;-ks&nbsp;[file/directory] ||  Lists how much space a particular file or directory takes
the current one\\ \hline
+
|-
\end{tabular}  
+
| quota ||  Shows how much disk space you have used of your quota
</math>
+
|-
</center>
+
ssh&nbsp;[IP&nbsp;address] ||  logs into another computer (e.g. <code>ssh teer14.oit.duke.edu</code> logs into the teer 14 computer)
 
+
|-
 +
| w ||  Lists the users logged into the same computer and the programs they are running
 +
|-
 +
| who ||  Lists of users logged into the same computer and their IP addresses
 +
|-
 +
| xterm&nbsp;& ||  Call up an additional xterm window without locking the current one
 +
|}
  
 
==Advanced Commands==
 
==Advanced Commands==
Line 519: Line 486:
 
commands.
 
commands.
  
 +
<!-- no more AFS  :(
 
===Set Permissions - <code>fs setacl</code>===
 
===Set Permissions - <code>fs setacl</code>===
 
<source lang="bash">
 
<source lang="bash">
 
fs setacl [directory path] [user] [permission type]
 
fs setacl [directory path] [user] [permission type]
 +
fs setacl -dir [directory path] -acl [user] [permission type]
 
</source>
 
</source>
 +
The latter case must be used if the directory path portion includes multiple paths (for example, with a wildcard).
 
====Users====
 
====Users====
<center>
+
{|class="wikitable"
<math>
+
| '''User''' || '''Who is given rights'''
\begin{tabular}{|c|c|} \hline
+
|-
\textbf{User} &\textbf{Who is given rights} \\ \hline
+
| [any login id] || the user associated with the login ID
{\it{[any login id]}}  & the user associated with the login ID \\
+
|-
{\tt{system:anyuser}}  & any Duke user \\
+
| system:anyuser || any Duke user
{\tt{system:administrators}}  & system administrators \\
+
|-
{\tt{mrg:egr53ta}}  & EGR53 TAs and professors \\\hline
+
| system:administrators || system administrators
\end{tabular}
+
|-
</math>
+
| mrg:egr53ta || EGR53 TAs and professors
</center>
+
|}
 +
 
  
 
====Permission Types====
 
====Permission Types====
<center>
+
'''NOTE''' As of Spring, 2013, user's home spaces are on CIFS, not AFS, and therefore the following commands will not work on folders in the home spaces.  Folders created specifically for course work on the AFS system will live in /afs/acpub.duke.edu/courses/ and these commands will still work there.  For now...
<math>
+
{|class="wikitable"
\begin{center} \begin{tabular}{|c|c|c|} \hline
+
| '''Code''' || ''Meaning'' || '''What right is given'''
\textbf{Permission} &\textbf{What It Stands For} & \textbf{What It Allows} \\ \hline
+
|-
{\tt{r}}  & read & ability to read files \\
+
| r || read || ability to read files
{\tt{l}}  & lookup & ability to lookup directory information \\
+
|-
{\tt{i}}  & insert & ability to add a file \\
+
| l || lookup || ability to list files
{\tt{d}}  & delete & ability to delete a file \\
+
|-
{\tt{w}} & write & ability to write to files \\
+
| i || insert || ability to add a file
{\tt{k}} & lock & ability to have processes lock files \\
+
|-
{\tt{a}} & administer & ability to change permissions \\
+
| d || delete || ability to delete a file
{\tt{none}} &  & no rights given \\
+
|-
{\tt{read}} & & {\tt{rl}} rights given\\
+
| w || write || ability to write to files
{\tt{write}} &  & {\tt{rlidwk}} rights given \\
+
|-
{\tt{all}} & & all rights given ({\tt{rlidwka}})\\ \hline
+
| k || loc'''k''' || ability to have processes lock files
\end{tabular}
+
|-
</math>
+
| a || administer || ability to change permissions
</center>
+
|-
 +
| none || none || no rights given
 +
|-
 +
| read || read || <code>rl</code> rights given
 +
|-
 +
| write || write || <code>rlidwk</code> rights given (all but administer)
 +
|-
 +
| all || all || all <code>rlidwka</code> rights given  
 +
|}
 +
 
 +
{|class="wikitable"
 +
| '''Example''' || '''Outcome'''
 +
|-
 +
| fs&nbsp;setacl&nbsp;.&nbsp;mfs7&nbsp;rl ||  Gives the user <code>mfs7</code> read and lookup permissions to the current directory.  Using the permission <code>read</code> instead of <code>rl</code> would have accomplished the same task.
 +
|-
 +
| fs&nbsp;setacl&nbsp;~/EGR53/&nbsp;mrg:egr53ta&nbsp;all ||  Gives EGR53 TAs and professors all access rights to an EGR53 directory, which is located in the current user's home directory.
 +
|-
 +
| fs&nbsp;setacl&nbsp;..&nbsp;system:anyuser&nbsp;w ||  Gives any user on the system write access  to the parent of the current directory.
 +
|-
 +
| fs&nbsp;setacl&nbsp;-dir&nbsp;~/public/*&nbsp;-acl&nbsp;mrg&nbsp;read ||  Gives mrg read and lookup rights on all directories inside the current user's <code>public</code> directory.
 +
|}
  
<center>
 
<math>
 
\begin{tabular}{l|p{9.5cm}}
 
{\bf Example} & {\bf What it Does} \\ \hline
 
{\tt{fs setacl . mfs7 rl}} & Gives the user {\it{mfs7}} read and lookup permissions \\
 
& to the current directory.  Using the permission {\it{read}} \\
 
& instead of {\it{rl}} would have accomplished the same task.\\ \hline
 
{\tt{fs setacl $\sim$/EGR53/ mrg:egr53ta all}} & Gives EGR53 TAs and professors all access rights \\
 
& to an EGR53 directory, which is located in the \\
 
& current user's home directory. \\ \hline
 
{\tt{fs setacl .. system:anyuser w}} & Gives any user on the system write access \\
 
& to the parent of the current directory.\\
 
\end{tabular}
 
</math>
 
</center>
 
 
 
 
===View Permissions - <code>fs listacl</code>===
 
===View Permissions - <code>fs listacl</code>===
 
<source lang="bash">
 
<source lang="bash">
Line 577: Line 552:
 
</source>
 
</source>
  
<center>
+
{|class="wikitable"
<math>
+
| '''Example''' || '''Outcome'''
\begin{tabular}{l|l}
+
|-
{\bf Example} & {\bf What it Does} \\ \hline
+
| fs&nbsp;listacl&nbsp;. ||  Lists who has access to the current directory.  The <code>.</code> is optional in this case, as typing <code>fs listacl</code> defaults to the current directory.  
{\tt{fs listacl .}} & Lists who has access to the current directory.  The
+
|-
{\tt{.}} is optional in this case, as typing\\
+
| fs&nbsp;listacl&nbsp;lab1/ ||  Lists who has access to a directory called <code>lab1</code> which is inside the current directory.
& {\tt{fs listacl}} defaults to the current directory. \\ \hline
+
|}
{\tt{fs listacl lab1/}} & Lists who has access to a directory called {\it{lab1}}
+
end AFS -->
which is inside the current directory.\\
+
 
\end{tabular}
 
</math>
 
</center>
 
  
 
==Commonly Used Programs in UNIX==
 
==Commonly Used Programs in UNIX==
Line 597: Line 569:
 
===[[LaTeX]] Commands===
 
===[[LaTeX]] Commands===
  
<center>
+
{|class="wikitable"
<math>
+
| '''Command''' || '''What it does'''
\begin{tabular}{|l|l|} \hline
+
|-
{\bf Command} & {\bf What it Does} \\ \hline
+
| emacs <filename> ||  Opens basic word processing program; if a filename is given, it will open that file if it exists or create it if it does not
{\tt emacs {\it [filename]}} & Basic word processing software. \\
+
|-
\hline
+
| latex [filename] ||  Converts a LaTeX file into a device independent (<code>.dvi</code>) file - files opened with this program generally end in <code>.tex</code>
{\tt latex [filename]} & Converts a .tex file into a .dvi file \\ \hline
+
|-
{\tt kdvi {\it [filename]}} & Opens a DVI viewer (to view .dvi files) \\ \hline
+
| dvipdf [filename.dvi] || Converts a DVI file into a PDF file; uses letter size
{\tt dvips [filename]} & Prints a .dvi file \\
+
<!-- | dvips -t letter [filename.dvi] || Converts a DVI file into a PostScript file; uses letter size -->
& {\footnotesize ~ {\tt dvips -o [outputfile] [inputfile]}
+
|-
  $\rightarrow$ Converts a .dvi file into a PostScript file without
+
| evince [filename.pdf] || Views the PDF file; you can also print from here.
  printing}\\ \hline
+
|}
{\tt kghostview {\it [filename]}} & Opens a PostScript file reader. \\ \hline
 
\end{tabular}  
 
</math>
 
</center>
 
  
 
===Other Commands===
 
===Other Commands===
<center>
+
{|class="wikitable"
<math>
+
| '''Command''' || '''What it does'''
\begin{tabular}{|l|l|} \hline
+
|-
{\bf Command} & {\bf What it Does} \\ \hline
+
| firefox || Opens a web browser
{\tt acroread {\it [filename]}} & Opens an Adobe Acrobat viewer. \\
+
|-
\hline
+
| gimp <filename> || Opens a graphics viewer
{\tt firefox} & Opens a web browser\\ \hline
+
|-
{\tt gimp {\it [filename]}} & Opens a graphics viewer. \\ \hline
+
| mathematica || Starts symbolic math package [[Mathematica]]
{\tt mathematica} & Starts symbolic math package Mathematica\\ \hline
+
|-
{\tt matlab} & Starts MATLAB program \\ \hline
+
| matlab || Starts MATLAB program
{\tt ooffice {\it [filename]}} & Starts OpenOffice\\ \hline
+
|-
{\tt more [filename]} & Types the contents of the file to the screen\\ \hline
+
| ooffice <filename> || Starts LibreOffice
{\tt xeyes} & Initiates 1984 protocol\\ \hline
+
|-
{\tt xlogo} & Initiates shameless self-promotion\\ \hline
+
| more [filename] || Types the contents of the file to the screen
{\tt xmaple} & Starts symbolic math package Maple\\ \hline
+
|-
\end{tabular}
+
| xeyes || Initiates 1984 protocol
</math>
+
|-
</center>
+
| xlogo || Initiates shameless self-promotion
 +
|-
 +
| xmaple || Starts symbolic math package [[Maple]]
 +
|}
 +
 
 +
== Questions ==
 +
{{Questions}}
 +
 
 +
== External Links ==
 +
 
 +
== References ==
 +
<references />
 +
 
 +
{{Protected Class Document}}
 +
[[Category:ECE 110]]
 +
[[Category:ECE 382]]
 +
[[Category:EGR 103]]
 +
[[Category:ME 344]]

Latest revision as of 00:01, 27 August 2019

The following tutorial has been a part of the EGR 103 lab manual for several years, and its contents were predominantly organized and collected by Michael Ehrenfried, Pratt 2004. Hopefully, this new web-based version will continue to be a useful resource for students in the course as well as the rest of the Pratt family. In 2015, the tutorial was re-written to reflect the fact that Duke no longer has any physical Linux machines but rather provides access to a Linux environment through a virtual cluster.


UNIX

Unlike Windows or Mac OS, UNIX is a command-line based operating system. In essence, it means that instructions have to be typed in as commands instead of using the mouse to point, click, and drag. As such, some commands will have to be memorized in order to use the UNIX system.

The following commands - specific to the Linux brand of UNIX deployed on Duke's public clusters - have been divided into Basic, Intermediate and Advanced commands. Basic commands are essential to use the system, and should be memorized as quickly as possible. Intermediate commands will be commonly used by average users, and are recommended to be memorized. Advanced commands will be seldom used by an average user.

Note that when you connect to a Linux server through ssh, you will automatically be taken to your home directory.

Structure of the Command Line - The Sentence

Each command line can be broken down into several parts. There are three primary "parts of speech" to issuing commands - the verb, the object, and the adverb. Not every command will require all parts, but it is important to know when they will and what they are.

The Command - The Action Verb

The first word of the prompt is the specific command of the line, equivalent to an action verb in English. This tells the computer what to do. A few of the commands we will use are listed below.

Command What it does Graphical Users Equivalent
pwd prints the name of the working directory path given in window
ls lists files in a directory viewing a folder's contents
cd changes a directory double clicking on a folder
cp copies a file or folder copying the contents of a file or folder
mv moves/renames a file or directory dragging an item to a new place/renaming it
rm removes a file dragging a file to the trash and emptying it
mkdir creates a new directory creating a new folder
rmdir removes an empty directory dragging folder to the trash and

emptying it

man pulls up manual pages opening help files

Files and Directories - The Objects

Many commands need specific objects in order to carry out their function. If you ask the computer to remove (rm) it also needs to know which files and/or directories it is that you would like to remove. In many graphical interfaces the computer is told to do this by clicking on an item or slick-dragging to select multiple items. In a text based interface, the information is provided by giving a path to the elements to be removed or by providing a pattern.

Paths

A path is where the directory or file is located in relation to other files and folders. On a Windows machine the hard drive can be thought of as the root directory - it is the directory from which all other parts of the file tree flow. If you wanted to open Starcraft, you might first have to open the hard drive, then double click on a Programs folder, followed by a Games folder, then a Starcraft folder, and then finally get to Starcraft.exe. This is the path you took to open Starcraft.

Note that there are two primary types of paths - absolute paths and relative paths. Absolute paths always start from the root directory; their main advantage is an absolute path uniquely identifies a particular element, regardless of where you are in the file tree. The major disadvantage is that absolute paths can get very long. The absolute path represented above, for example, might be:

C:\Programs\Games\Starcraft\Starcraft.exe

In a UNIX system, the root is represented by a single slash - the / symbol. Absolute paths therefore always start with / and go from there. For example, the absolute path to the UNIX command xeyes is

/usr/bin/xeyes

If you use this as an object of a UNIX command, no matter where you sit in the file tree, UNIX will be able to find that program.

On the other hand, relative paths are just that - the path required to get where you are going based upon where you are in the system. For example, if you were currently in the /usr directory in UNIX, you could access the xeyes program with the path bin/xeyes. NOTE: relative paths do not start with the / because you do not want the path to go back to the root; you want to start where you are and move from there.


Other Ways to Represent Locations

Now that we have a basic understanding of what a path is we can throw in a few shortcuts to make defining to the computer which objects we mean simpler. Sometimes you wish to perform a command on the current directory. Or perhaps you would like to back up a level in the hierarchy to reach another folder. Or finally, you may want to use something in your home directory or another user's home directory. The shortcuts for these tasks are:

Symbol What it means
. Current directory
.. Parent directory (the directory above the current one)
~ Current user's home directory
~ID ID's home directory


Note that these shortcuts can be used as parts of relative or absolute paths and can be strung together. For example,

cd ../../../a/b

is a relative path - it does not start with a slash - that tells UNIX to change directories by starting wherever the user currently is, then going up a level, going up another level, going up another level, then from there entering the a directory, and from the a directory going into the b directory.

Wildcards

Symbol What It Does
? one character wildcard
[LIST] one character restricted wildcard
* multi-character wildcard

Wildcards are a powerful tool when you want to deal with multiple files or directories at once. The first of the wildcard characters is the ?. This will replace any one character. Using the pattern c?t would thus include both the word cat and cot, but not the word cast, because in cast there are two characters between the c and the t. Likewise cots would not be included because there is a letter after the t.

A modified version of the ? involves putting particular characters inside square brackets. This wildcard is allowed to replace any of the characters contained within the brackets and no other. It is still a single-character replacement, but it is restricted. For example,

ls p[aeiou]t

will list all files with three-letter long names that start with p, end in t, and have a, e, i, o, or u in the middle.

ls [a-m, 3-6]?

will list all files with two-letter long names that start with either a through m or the numbers 3 through 6.

This brings us to the * wildcard. The * wildcard replaces as many characters as necessary - including no character. Therefore typing c*t would still represent cat and cot, but it would also include {careerist and ct. It would not include crate, however, since nothing in the pattern replaces anything after the t. The command

ls ~mrg/public/a*ing

will list all files in Dr. G's public directory that start with the letter a, end with the letters ing, and have any number of characters in between. Note that as of 2013, however, users are not allowed access to any part of any other user's directory, and so on the Duke system, the command above will return either "Permission Denied" or "No such file or directory."

The ? and * are the most used wildcards, and are often seen at the beginning and end of patterns. For example, EGR* would include all files beginning with EGR, while *.m would include all files that end in .m. The wildcards can also be used together:

ls [a-z]???.dat

will list all files that begin with a lower case letter, have three characters after that letter, followed by a dot and the extension dat.

ls ~mrg/public/???*

will list all files that contain at least three characters.

Options - The Adverbs

Commands often have options that are associated with them that allow them to change their functionality based on user preference. Usually they are represented by a character or a word that is preceded by a dash. A list of options can almost always be found by typing man [name of command] where [name of command] is the command whose list of options is desired. A few of these options are mentioned as each command is described in the Basic Commands section below.

Arguments - Everything Else

Sometimes other information that the computer needs to know to perform the command successfully will be required of the user. As with the options the man pages explain all needed arguments.

File Extensions

Often times attached to the end of a file name is a file extension. This is usually represented by a dot (.) followed by an identification tag. Each program, or type of file will generally have a file extension traditionally associated with them (e.g. Microsoft Word uses .doc). In this course we will be using primarily MATLAB and LaTeX. The table below identifies the extensions with which you should become familiar.

Extension Program Association Type of File
.py Python Python script
.m MATLAB MATLAB script or function
.mat MATLAB MATLAB-encoded data file
.tex LaTeX the uncompiled LaTeX formatted document
.dvi evince compiled LaTeX document, which can be viewed
.ps evince a postscript file used for printing
.eps evince encapsulated postscript (e.g. MATLAB graphs and other pictures)
.pdf evince a PDF file used for viewing and printing

Note, however, that UNIX is not nearly as dependent on extensions as other operating systems. UNIX will allow you to change extensions without warning, to use extensions of more than three characters, and to use extensions of extensions. Some programs - MATLAB in particular - do depend on having the correct extensions to translate the purpose of a file.

Basic Commands

This section describes some of the essential UNIX commands that we will be using in this course. They are listed in the table above in the The Command - The Action Verb section.

In the examples below, the [ ] and < > are meant to be replaced by the type of objects that are described inside of them. The square brackets represent required arguments while the angle brackets represent optional ones. The symbol in the example listings represents a space.

Note that only select options are shown; browsing the man pages yourself will show you a complete list of options. Much of the information below is either copied from or adapted from the man pages for the particular command.

Print Working Directory - pwd

pwd

This command prints the absolute path of the current directory.

List Contents - ls

ls <options> <directory path to list>

This command will list the directory contents.

Option What it does
-a lists all files and directories (including hidden ones)
-l lists in long format giving more information
-p puts a slash (/) after each name if the entry is a directory
-r reverses (alphabetical or date) order of display of the files
-R recursively lists subdirectories encountered
-t orders the files according to time rather than alphabetical order

Note: These options can be combined. For example,

ls -lart EGR53

will use the long format to list all files in reverse order sorted by time.

Change Directory - cd

cd <directory path>

This command changes the directory to the directory defined by the path.

Example Outcome
cdEGR103 changes to the directory called EGR103 (if present) in your current directory
cd.. changes to the parent directory (directory above the current one)
cd~ changes to your root directory
cd~/EGR103 changes to the directory called EGR103 (if present) in your root directory
cd changes to your home directory

Copy - cp

cp <options> [source directories/files] [destination directory/file]
Option What it does
-i copies interactively - asks before overwriting
-r copies recursively - must use when copying a directory


Example Outcome
cpFile1File2 Copies the file File1 and makes a new file called File2 in the same directory.
cpMyFileFolderThatExists Takes the file MyFile and makes a copy of it in a file also called MyFile which is inside the directory FolderThatExists. Note that if the folder does not, in fact, exist, then there will be a new file called FolderThatExists which is a duplicate of MyFile. To avoid that mistake, use:
cpMyFileFolderThatExists/ Takes the file MyFile and makes a copy of it in a file also called MyFile which is inside the directory FolderThatExists. Note that if the folder does not, in fact, exist, then there be an error
cp-r~mje7/public/lab1/. Copies the directory lab1 and all its contents from ~mje7/public/ into the current directory; the new copy is called lab1.
cp~mje7/public/lab1/*. Copies all the files from ~mje7/public/lab1 into the current directory. Note the subtle difference from the previous example. Above, the directory and the files were copied together. Here, only the files are copied meaning the files would be in the current directory.
cp~mje7/public/intro*EGR53 Copies all the files beginning with intro from mje7's public directory to an EGR53 directory that is inside the current directory.

Move (or Rename) - mv

mv <options> [source directories/files] [destination directory/file]
Option What it does
-f move the file(s) without prompting even if it overwrites a file (default for file input)
-i will prompt for conformation whenever the move would overwrite a file (default for console input)


Example Outcome
mvfoo.mlab1/ Moves a file foo.m into the lab1 directory, which is found in the current directory.
mv../lab1/*.tex. Move all files with the file extension .tex from the lab1 directory (which is found in the parent of the current directory) into the current directory.
mv-ffoo.mbar.m Moves the file foo.m to a file bar.m. This is similar to renaming the file. If bar.m already exists the -f will cause this file to be overwritten automatically.

Remove a File (Delete) - rm

rm <options> [directories/files]

Warning: These options are powerful and permanent.

Option What it does
-r removes recursively all directories and subdirectories in

the argument list

-i prompts the user before removing any files (interactive)
-f remove all files without prompting the user (default setting)
Example Outcome
rmfoo.m Removes (deletes) foo.m from the current directory
rm-i*.m../bar.m Removes all files ending in .m from the current directory, as well as bar.m from the parent directory. The -i will cause UNIX to prompt the user for permission to remove these files.
rm-irlab1/ Removes all of the contents of the the current directory's lab1/ including all subdirectories and their files. It will also prompt the user for permission to remove these files.

Make a Directory - mkdir

mkdir [new directory paths]
Example Outcome
mkdirlab1 Makes a directory called lab1 in the current directory.
mkdir../junk Makes a directory called junk in the parent of the current directory.
mkdir~/foobar Makes a directory called foobar in the user's home directory.

Remove a Directory - rmdir

rmdir [directories]

Note: In order for this command to work the directories must first be empty.

Help Manual - man

man <options> [command name/keyword]

This command is the key to learning more about UNIX. To exit out of the manual without toggling to the end, just press q. To move down the various pages, press the spacebar.

Option What it does
-k [keyword] brings up descriptions of all manual pages containing the keyword
Example Outcome
manlatex Brings up the manual pages for the latex command
man-klatex Brings up the summary descriptions of manual pages containing the word latex

Intermediate Commands

A summary of commonly-used commands are included in the table below. In the long run, these commands will be relatively often-used by the average user.

Command What it does
CTRL + Z Suspends the most recently executed program
bg runs the most recently executed program in the background
fg runs the most recently executed program in the foreground
ps -u ID lists running processes for user ID
kill [Job number] terminates the program with the job number entered. The job number is on the line following the one where the command was given or can be found with the ps command above.
kill -KILL [Job number] kill jobs that resist the kill command alone.
logout logs out of the computer that you have remotely logged into
lpr [filename] Prints the file to the ePrint queue
passwd Changes the user's password
[program name] & Runs the program in the background, so it does not lock up the xterm window
du -ks [file/directory] Lists how much space a particular file or directory takes
quota Shows how much disk space you have used of your quota
ssh [IP address] logs into another computer (e.g. ssh teer14.oit.duke.edu logs into the teer 14 computer)
w Lists the users logged into the same computer and the programs they are running
who Lists of users logged into the same computer and their IP addresses
xterm & Call up an additional xterm window without locking the current one

Advanced Commands

For more information, check the online manual within the UNIX system using the

man [command name]
man -k [keyword]

commands.


Commonly Used Programs in UNIX

These commands are broken up into two groups. The first is the group most closely associated with processing LaTeX documents while the second group is more generic.

LaTeX Commands

Command What it does
emacs <filename> Opens basic word processing program; if a filename is given, it will open that file if it exists or create it if it does not
latex [filename] Converts a LaTeX file into a device independent (.dvi) file - files opened with this program generally end in .tex
dvipdf [filename.dvi] Converts a DVI file into a PDF file; uses letter size
evince [filename.pdf] Views the PDF file; you can also print from here.

Other Commands

Command What it does
firefox Opens a web browser
gimp <filename> Opens a graphics viewer
mathematica Starts symbolic math package Mathematica
matlab Starts MATLAB program
ooffice <filename> Starts LibreOffice
more [filename] Types the contents of the file to the screen
xeyes Initiates 1984 protocol
xlogo Initiates shameless self-promotion
xmaple Starts symbolic math package Maple

Questions

Post your questions by editing the discussion page of this article. Edit the page, then scroll to the bottom and add a question by putting in the characters *{{Q}}, followed by your question and finally your signature (with four tildes, i.e. ~~~~). Using the {{Q}} will automatically put the page in the category of pages with questions - other editors hoping to help out can then go to that category page to see where the questions are. See the page for Template:Q for details and examples.

External Links

References


Class Document Protection