Sie sind auf Seite 1von 24

Learning UNIX

2010
FSG

Accenture
Email: Subrat.Rout@accenture.com

Copyright 2008 Accenture All Rights Reserved.

Outline

Introduction to UNIX
Text Editor - NANO
Basic Commands
File Manipulation
Permissions
Processes
Important Utilities
Running a Program
Remote Login Procedures
Copyright 2008 Accenture All
Rights Reserved.

Introduction to UNIX
What is UNIX?
UNIX is an operating system (OS) and
set of related utility programs
It is the manager of everything going on in your computer

Advantages of UNIX:
Many Users can use the same computer at the same time
Can run many different things simultaneously

Copyright 2008 Accenture All


Rights Reserved.

How Things Work in UNIX


A Few Terms to Know:

Shell:
The program you use to interact with the computer
File:
Stored info and all your devices (like disk drives and printers)
Processes:
All Programs that running
Rules for Names:
Case Sensitive (ie. Happy.txt is different than happy.txt)
Extensions Irrelevant (for now)
Copyright 2008 Accenture All
Rights Reserved.

Using the Shell


Login Procedure:
login:
password:

Changing your Password:


After logged in, type:
passwd
(you will type in the old password once, and the new one
twice)

Copyright 2008 Accenture All


Rights Reserved.

Using Text Editor - NANO


Start with:
nano
nano filename

- to start the editor with a new file


- to start editing filename
(creates if doesnt exist)

The commands are listed at the bottom of the window


Delete character: ^d
Ctrl-d
Save:
^o
Ctrl-o
Exit:
^x
Ctrl-x (also saves if desired)

Copyright 2008 Accenture All


Rights Reserved.

Exercise: Writing Files


Type nano and create a file called - unix.notes
Include in it answers to the following:
A Shell is
A Process is
Devices in UNIX are stored as
Commands in UNIX are case-sensitive (T/F)

Save your file.

Copyright 2008 Accenture All


Rights Reserved.

Format of Commands
General Format of Commands:
The command line:
[cswug@machine1 cswug]$
The command structure:
[ ]$ command options arguments

Can have multiple options (-l -a) and arguments (file1.txt


file2.txt), etc

Copyright 2008 Accenture All


Rights Reserved.

Dealing with Files


ls
- lists files
ls
ls -a
(lists all hidden system files too)
mv - moves (and renames) file
mv oldfile newfile
cp - copies (renames) file
cp oldfile newfile
rm - deletes a file
rm oldfile

Copyright 2008 Accenture All


Rights Reserved.

Exercise: Files
Make 2 copies of your unix.notes with cp (call the copies
unix2.notes and unix3.notes)
Rename the unix2.notes to unix4.notes with mv
Make sure you have 3 files with ls
Remove the unix4.notes copy with rm

Update your notes (in unix.notes)

Copyright 2008 Accenture All


Rights Reserved.

Better Search Tactics


Wild Cards: ? and * and [ ]
Wild cards allow search for range of files
? = any 1 character here
file?.txt
- selects file1.txt, but not file11.txt
* = any # of characters
file*.txt
- selects file1.txt and file11.txt
[ ] = allows selection of certain characters
file[1-3].txt
- selects file1.txt, file2.txt, file3.txt only

Copyright 2008 Accenture All


Rights Reserved.

File Contents
less - displays file contents
less file1
head - displays first 10 lines of file
head file1
tail - displays last 10 lines of file
tail file1
grep - search file for given pattern
grep pattern file1
diff - compares 2 files and tells if different
diff file1 file2
Copyright 2008 Accenture All
Rights Reserved.

Other Commands
man - short manual on command
man command
learn - tutorial on how to use certain topics
learn
df
df

- shows how much disk space is used

date - shows current date and time


date
shutdown -shuts machine down
shutdown
Copyright 2008 Accenture All
Rights Reserved.

Intro to Directories

Above is the tree structure


relative vs absolute pathway
Special Directories:
/ = the root directory
~ = the home directory

. = the current directory


.. = the parent directory

Copyright 2008 Accenture All


Rights Reserved.

Using Directories
cd - changes directories
cd directoryname
pwd - display current path
pwd

mkdir
- make new directory
mkdir newdirectory
rmdir - delete directory (requires that dir is empty)
rmdir olddirectory

Copyright 2008 Accenture All


Rights Reserved.

Exercise: Directories
Check current path with pwd
Make a new directory with mkdir called unix/
Change into that directory (cd) and make another directory
called notes/
Delete the notes/ directory with rmdir
Go back to home directory with cd ~ or cd ..
Move (mv) your unix.notes from here to your new folder
unix/
Copyright 2008 Accenture All
Rights Reserved.

Permissions and Other Users


Permissions describe who is allowed to read, write, or use your files.

To check permissions of files in your directory, type:


ls l
-displays permissions to all files in directory
ls l file1
-displays permission to file1
Results in form:
d-rwx-rwx-rwx # owner size updated filename
The first rwx is the permission for the owner
the next is for those in your group
the last is permission for everyone else
Each: rwx = read write execute permissions
If one of three is a -, then that user does not have permission
to do that action
Copyright 2008 Accenture All
Rights Reserved.

Changing Permissions
Chmod
-changes the permissions on a file
chmod [options] who [operation][permission] file-list
who
operation
permission
Examples:
chmod a +r file1
chmod g -wx file2

= u (user), g (group), o (other), a (all)


= + (add permission), - (take away), = (set)
= r (read), w (write), x (execute)

- gives the read option to everyone for file1


-takes away the write and execute options
from group on file2

chown
-changes owner of a file
chown newowner file
Copyright 2008 Accenture All
Rights Reserved.

User Accounts
su
-switch user (or super-user)
su newperson
useradd
-adds new user
useradd newperson
userdel
-deletes user account
userdel oldaccount

Copyright 2008 Accenture All


Rights Reserved.

Processes
top
- lists processes currently running (and get IDs)
top
(type q to get out of listing)
ps
- lists status of a process
ps idnumber
kill
- kills a process
kill idnumber
killall
killall

- kills all processes

Copyright 2008 Accenture All


Rights Reserved.

Important Utilities
gzip
gzip file1

- zips a number of files (adds gz to extension)

gunzip
- unzips a file
gunzip file1.gz

tar
- clumps all files into archive
tar -cvf archivename filelist
-creates an archive
tar -xvf archivename
-extracts files from archive

Copyright 2008 Accenture All


Rights Reserved.

Running Programs

Compiling a Program:
Note: For the compiler, the extension (.c or .f90) DOES matter!
gcc
- C compiler
gcc mainfile.c
ifort
- Fortran compiler
ifort file.f90
(The default name of a created program is a.out)
Executing a Program
./
- Runs a compiled program
./a.out

Copyright 2008 Accenture All


Rights Reserved.

Remote Login

To login and work on a remote computer:


ssh
- secure shell program
ssh user@host
-opens a shell (interface) to the other computer. Use this shell just as
you would your first computer. Type exit to close the connection.

To copy a file to a remote computer:


scp
- secure copy program
scp file user@host : path
scp file1 myname@cswug1.usc.edu : ~/somedirectory/

Copyright 2008 Accenture All


Rights Reserved.

Thanks!
References:
Sobell, Mark G. A Practical Guide to Unix
System V - 2nd ed.
Nomura, Ken-ichi. Tutorial of UNIX/LINUX
@ CSWUG 2004
Sharma, Ashish. General Reference

Questions?

Copyright 2008 Accenture All


Rights Reserved.

Das könnte Ihnen auch gefallen