0% found this document useful (0 votes)
58 views4 pages

UNIX You Need To Know: (Rev. Aug 14, 2009)

This document provides instructions on basic UNIX commands for file manipulation, navigation and permissions. It lists common commands like mkdir, rmdir, cd, cp, rm, mv, ls, man and describes how to create, delete, move and list files and directories. It also summarizes UNIX file permissions using the ls -l command and how to change permissions with chmod. Finally, it covers logging into remote machines using ssh and securely transferring files between systems with scp.

Uploaded by

Vinay Goddemme
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views4 pages

UNIX You Need To Know: (Rev. Aug 14, 2009)

This document provides instructions on basic UNIX commands for file manipulation, navigation and permissions. It lists common commands like mkdir, rmdir, cd, cp, rm, mv, ls, man and describes how to create, delete, move and list files and directories. It also summarizes UNIX file permissions using the ls -l command and how to change permissions with chmod. Finally, it covers logging into remote machines using ssh and securely transferring files between systems with scp.

Uploaded by

Vinay Goddemme
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

UNIX You Need to Know

Basic Commands
There are hundreds of commands and applications available on the departmental computers. The fol-
lowing is a list of some of the basic and frequently used commands.
mkdir dirname # Create directory called dirname
rmdir bigdir/subdir bigdir # Remove (empty) subdirectory bigdir/subdir and then bigdir
cd myjunk # Make directory myjunk the current working directory
cd # Return to your home directory
pwd # Print the current working directory
cp le1 le2 # Make a copy of le1 into le2
rm le1 le2 le3 # Remove le1, le2, le3
mv oldname newname # Rename le oldname to newname
mv le1 le2 dir1 # Move les le1 and le2 to directory dir1
ls dir1 # List les in directory dir1
ls -al # List les in current directory (long listing), including hidden les
ls -lrt # List les in current directory, reverse sorted by date
man ls # Show the UNIX manual page for command ls
man -k compress # Show list of available manpages having keyword compress
quota -v # Show disk block consumption
System commands are stored in several directories scattered around the lesystem. You may explore
more commands by looking in directories /usr/bin and /usr/local/bin. Try the following to see a
partial listing of available commands:
cd /usr/bin; ls -C | more
Password Maintenance and Etiquette
You may have been issued separate accounts on several computers: the servers huey.met.fsu.edu and
metlab, and the MetLab (LOV307) and AtmosLab (LOV364) workstations. You may change your
password at any time by typing passwd at a shell prompt while logged onto any machine. You will rst
be prompted for your current password, and then prompted for a new password twice. What you type
is not echoed to the screen. Changing your password on any of the MetLab or AtmosLab workstations
will change your password for all the workstations. Changing your password on either metlab or huey
will only change your password for that server.
Do not share your password with others. Log o before leaving the room, even if only for a short
time. Do not enable lockscreen. Should you nd a terminal logged in and unattended, log the
person out. If you nd a MetLab terminal in lock-screen mode, you may terminate the session by typing
CTRL-ALT-BACKSPACE (hold down CTRL and ALT and then type BACKSPACE).
The Shell and Metacharacters
UNIX has many features which can simplify le manipulation. For a start, you may want to keep
homework for dierent classes in separate directories (folders in Windows parlance). You may create
directories within directories to an arbitrary depth.
The shell is your command-line interface to the operating system. Most of the characters you type
letters and numbers have no special meaning to the shell. However, some characters do have special
meanings, and these characters should not be used in lenames. UNIX is case-sensitive for command
1 [Rev. Aug 14, 2009]
and lenames, i.e., MyFile and myfile are not the same. By convention and convenience, lenames are
usually lower case.
Some metacharacters modify how commands work: ; | > < &. The semi-colon (;) acts as a command-
line separator, allowing you to type sequential commands on the same line:
mkdir mydir; mv file1 file2 file3 mydir
which creates mydir and then moves les file1, file2, and file3 into the directory. The vertical
vergule | is the pipe character, routing the output of one command to the input of another:
ls -C | more
which runs the ls command with the column option, directing the output to the more command, which
pauses output at every screenful. The > character redirects stdout to a le:
ps -ef | grep $USER > myprocs
which retrieves a list of running processes (ps), lters out those that belong to the current user ID (grep
$USER), and sends the results to a le named myprocs in the current directory. The ampersand (&) runs
the command in the background, returning a system prompt right away. You might use this to start a
long-running command, such as a web browser, from the command line:
firefox &
A command prompt is returned immediately, and the browser will open on the screen.
Other metacharacters are used for creating patterns to match le names. The * matches a string of
zero or more characters, while the ? matches a single arbitrary character. The construction [abc]
matches a single character a, b, or c. Ranges of characters may also be specied, as in [a-d0-5]. The
construction {str1,str2,. . .} allows one to specify string alternatives. Some examples may help:
file* # This will match any lename beginning with file
*word* # This matches lenames containing word: word foreword swordfish
fn.* # This will match les named fn with any extension
myfile?? # This matches les starting with myfile followed by any two characters
fn0[1-5a-d] # Matches les named fn01 fn02 . . . fn05 fn0a fn0b . . . fn0d
fn{one,two,46}.dat # Matches les named fnone.dat fntwo.dat fn46.dat
fn.{tex,dvi,log} # Matches fn.tex, fn.dvi and fn.log
lab?0[1-5r]*.{pdf,tex} # Matches les labA01.pdf labx0r.tex lab-05redo.tex
You dont need to learn how to use metacharacters (so long as you learn to avoid them when creating
lenames), but if you do, they can be a great time-saver as a shorthand for typing commands:
mv lab0[1-5].ps Met3502
which will move all les named lab01.ps lab02.ps . . . lab05.ps to directory Met3502.
UNIX File Permissions
Each le or directory in the UNIX lesystem has a series of attributes which are collectively called
permissions. The permissions on a le determine whether a particular user may read, write, or execute
(or search, in the case of directories) a le or directory. The ls -l command lists le permissions on every
le and directory in the current directory. UNIX recognizes three levels of access to a le or directory
(user [owner], group, other), and three kinds of access to each le (read, write, execute/search).
A typical ls -l listing might look like this:
drwxr-x--- 1 bret staff 512 Sep 20 2001 junk
-rwxr-xr-x 1 bret staff 4312 Jan 25 2002 test
-rw-r--r-- 1 bret staff 73 Jan 25 2002 test.f
-rw-r--r-- 1 root other 93 May 31 10:48 test.ps
[Rev. Aug 14, 2009] 2
The d in the rst position indicates that junk is a directory. The next set of three elds show the
user/owner permissions, then group permissions, then other permissions. The owner is shown to be user
bret, and the group is staff. According to the listing, only the user bret can write to directory junk
(i.e., add or remove les). Other users in group staff may read or search the directory, and all other
users have no access to junks contents. The le test is a plain le with execute permissions set, which
allows anyone to run the program by typing the le name.
Changing le permissions is done through the chmod command. (This command has many avors: see
man chmod for more complete information.)
chmod o+rx junk # For other users, turn on read and search permission for directory junk
chmod go-rx test # For group and other, remove read and execute on le test
chmod u-w test.f # For user (owner), disable write access to test.f
Logging In and Moving Data
If you are logged on to a machine at home, across campus, around the world, or across the hall, youll use
the Secure Shell program ssh to log in to departmental machines. A secure shell client may be downloaded
for your home PC as part of the Cygwin project (http://cygwin.org/) or from http://openssh.org/.
From metlab (for example), you may log onto huey or any other ssh-enabled machine as follows:
metlab> ssh huey
You will be prompted for your huey password, and then youll be logged in. If this is the rst time youve
sshd into the machine, youll rst be asked if a key may be downloaded (answer yes). You can move
les between your huey and metlab accounts using scp, the secure copy command.
metlab> scp huey:a le mydir/a le copy
You will be prompted for your huey password, and then the le a le from your home directory on huey
will be copied to directory mydir with a le name of a le copy on metlab. You can also go the other
direction, e.g.,
metlab> scp mydir/a le huey:a le copy
which copies mydir/a le to a le copy under your home directory on huey. You can move multiple les
at once using metacharacters. If the multiple les are on the remote host, be sure to single-quote the
string:
metlab> scp huey:labdir/Lab[0-5].pdf .
which copies labdir/Lab0.pdf labdir/Lab1.pdf . . . from huey to the current directory on the current
machine (metlab, in this case). Whole directories may be copied at once by using the -r (recurse) ag:
metlab> scp -r huey:hw dir .
will copy the directory hw dir and all its contents to the current directory on metlab.
Editing Files
There are several text editors available on our systems. Which one you use may depend on familiarity
or application. On the atmos desktop, there is a basic text editor available from the control panel
under the note icon. The MetLab workstations have an editor with MS-Wordlike features under the
Applications/Oce/OpenOce.org Writer menu. Editors available from the command line include
vi
pico, type CTRL-G for help
emacs, type CTRL-H t for tutorial
Printing
Departmental printers will only render PostScript les (typically, these are les with extensions *.ps or
*.eps). Printing PostScript les is easy:
3 [Rev. Aug 14, 2009]
lp TheFile.ps
will send PostScript le TheFile.ps to the default printer. You may direct a le to a dierent printer
using the -d option:
lp -d jet407 TheFile.ps
which sends the le to the laser printer in LOV407. Other options are jet or jet364, which send les
to printers in LOV307 or LOV364, respectively. (Option jet364 is not available to the machines in
MetLab.) Plain text les (such as program source code) should rst be converted to PostScript before
being printed:
a2ps -d myprogram.f90
which converts myprogram.f90 to PostScript and then forwards the le to the default printer for the
current computer. Images need special attention before they can be printed. On the MetLab and
AtmosLab terminals, use gimp, a Photoshop-like program, to print images. You may re up gimp from
a shell command line, or you may start it from the Applications/Graphics/GNU Image Manipulation
Program menu item.
Printer status can be determined by running lpstat, which will list the currently active jobs. Cancel a
job using the job ID shown in the rst column of lpstat output:
cancel jet307-16801
Should the printer appear to be misbehaving, press the Cancel Job button on the printer after running
the cancel command.
For More Information
www.met.fsu.edu/computing Basic info on services, data and rudimentary help
sl.us.fsu.edu Download Eudora and SSH here
www.us.fsu.edu FSU User Services: info on FSU accounts and help
Send problems or questions to [email protected].
[Rev. Aug 14, 2009] 4

You might also like