0% found this document useful (0 votes)
39 views

Starting Unix

This document provides an introduction to starting Unix and describes some of its basic components and commands. It explains that Unix is made up of the kernel, shell, and programs/files. The kernel allocates resources and handles processes and storage. The shell acts as an interface between the user and kernel, interpreting commands. Common commands covered include ls, mkdir, cd, pwd, cat, cp, mv, rm, more/less, head/tail, grep, wc, chmod, chown, ps, and kill.

Uploaded by

Sandy Gallant
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Starting Unix

This document provides an introduction to starting Unix and describes some of its basic components and commands. It explains that Unix is made up of the kernel, shell, and programs/files. The kernel allocates resources and handles processes and storage. The shell acts as an interface between the user and kernel, interpreting commands. Common commands covered include ls, mkdir, cd, pwd, cat, cp, mv, rm, more/less, head/tail, grep, wc, chmod, chown, ps, and kill.

Uploaded by

Sandy Gallant
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 30

Starting Unix

Sandy Gallant 09/10/2008


Introduction
• Unix was first built in the 1960’s and has
undergone many improvements since
then.
• It is made up of three primary parts:
The Kernal
The shell
The programs and files
The Kernal
• This is basically the brains of Unix. It
allocates time and memory for running
processes and programs. It also handles
the filestore (where the files are kept) and
also communications in response to
system calls.
The Shell
• The shell is what is called a CLI(command line interpreter) basically
it acts as a go-between between the Kernal and the User. It
interprets the commands entered in and then runs the appropriate
process. Some of the advantages of using the shell are:
• Filename completion
• History
• Tab completion of commands (only in certain shells)
• The most common shell that you will be working with is the
bash(Bourne Again Shell)
• To invoke this shell you simply need to type the pathname to the
shell (normally /usr/bin/bash) but in most cases you can just type
bash after logging in and it will change your shell type over for the
current session.
Files/Programs
• Processes are described as being programs that
have been run and assigned a Process Id(PID)
Where as files are more or less just data
collections. They can be almost anything.
• The directory structure for unix is arranged so
that the more important system directories are
located at the top of the directory tree. The “/”
(root) directory is the top of the tree, more
directories like usr, etc and so on are stored in
the first level on most systems.
Basic Commands
ls
• To show the contents of a directory in unix you would use the
command “ls” such as:
• as you can see with just using the most basic form of “ls” it will only
return the filenames in the directory with limited formatting.

• Some of the more common flags you can use with ls are follows:
• -r >> Reverses the order of how the files are displayed
• -t >> Orders the files in modification time.
• -l >> Shows you huge amounts of information (permissions,
owners, size, and when last modified.)
• -a >> Shows all files including the . , .., and all hidden files
Basic Commands
ls
• You can also list the contents of a directory that you aren’t even in
by passing the full pathname to the directory (either in relative or
absolute terms) to the ls command such as below.
Basic Commands
ls
• If you want to list all the files in the current directory that begin with
Onevu for example you can use a wildcard (*) such as
Basic Commands
mkdir
• The mkdir is the same basically in windows it makes a directory in
the current directory that you are in
• The syntax is simply “mkdir directoryName”

• This also works with absolute paths as well


Basic Commands
cd
This is pretty much the same as windows again.
To change a directory simply issue the “cd”
command followed by the directory you wish
to browse to(either in absolute or relative)
you can combine this with .. to go up one
directory or with the – to go back to the
directory you were in previously. If you just
type “cd” without any arguments then you will
be taken to the current user’s home directory,
it works the same as typing cd ~
Basic Command
pwd
• pwd stands for Print Working Directory. It
simply prints what directory you are
currently in.
Basic Commands
cat
• “cat” is used to view the entire contents of a file to your screen
from top to bottom.
• To use cat you simply type cat followed by the file name you wish to
view.
• Cat file.txt will put the entire contents of the file.txt. This isn’t a
practical way to view files, which we’ll cover after. One use of cat is
it will allow you to copy the contents of one file into a new file or
append it to the bottom of an existing one.
Basic Commands
cat
• cat file1.txt > file2.txt : what the “>” does it tells the process “if file2.txt doesn’t exist create it and if it does
overwrite it with file1.txt”

• cat file1.txt >> file2.txt: what the “>>” does it tell the process “if file2.txt doesn’t exist create it and if it does append
file1.txt to the bottom”
Basic Commands
cp
• cp is used to copy files. The basic syntax for this is:
cp file1.txt file2.txt
• This will copy file1.txt to file2.txt, now you can include a
path infront of the filenames to specify where they are if
they are not in the current working directory
• By adding the –p flag to a cp command it will cause the
new file created to retain the same permissions as the
original file
Basic Commands
mv
• mv is used for moving or renaming a file.
It is almost identical in process to cp
however it removes the original file.
Basic Commands
rm
• rm is used to remove a file or directory. The syntax would be as
follows:
rm file.txt

• The flags that you can use for this are


• -r >> which creates a recursive remove. For example if you wanted
to remove an empty folder that contained another empty folder (as
rm can only remove empty directories in its default syntax)
• -F>> cause rm to force the remove. This is good for removing
directories as if used in conjunction with –r it will remove the
directory and anything underneath it.
Basic Commands
more/less
• less and more are simple text viewers.
• Using less will display the file on the screen and
you can scroll through it line for line. Also when
using less you can search through the file using
the “/” followed by your search parameter
• The syntax for this is less filename or more
filename
• When using more, you scroll through the file
using the enter key and it scrolls one full page at
a time.
• To exit either you simply need to hit “q”
Basic Commands
head/tail
• head and tail are pretty much used for what they
sound like they are for. The view the top and
bottom of a file respectively.
• tail is good for viewing logs as it will
automatically take you the very last line in the
log.
• If you use the –f flag with tail it automatically
refreshes when there has been any lines
appended to the file.
• With head and tail you can specify how many
line by using a – followed by the number of lines
to read.
Basic Commands
grep
• grep is used as a search tool. You can search through
files directories, even the results of a command.
• Using grep to search a file for a string you would use the
following syntax”
grep searchstring filename
• If you want to search the contents of a directory for a
particular string you can “pipe” the output of the ls
command to the grep command:
ls –l | grep searchstring.
• Wildcards in unix are used in search strings. The most
common wildcards are * (match any character any
number of times), ? (match any character once), and []
(which will match the given range.
Basic Commands
wc
• wc is a word/line/character count tool.
• Using wc –l will count the number of lines
in a file. You can also pipe output to this
command as well. This is usefull if you
wanted to count the number of files in a
directory such as
• ls –l | wc –l
Basic Commands
chmod
• chmod is used to change the permissions on a
file or directory. The basic permissions are rwx,
(read, write, execute) and the three groups for
each file are u, g,o (user,group,other) in that
order.
• You can change the permissions using chmod
by either specifying which permissions to give
which users such as
• chmod u+x (which adds the execute for the
user)
Basic Commands
chmod
• Assigning numerically is the easiest but you need to understand
how to convert the permission string to a number
• For full access you’ll see rwxrwxrwx what this mean is the
user,group, and other permissions all allow read,write, and execute
permissions.
• Now in numerical terms the read permission has a value of 4, the
write a value 1 and the execute a value of 2.
• To assign via chmod numerically you just need to add the value for
each section and then pass it to chmod as a 3 digit number.
chmod 755 file
Would assign read(4)-write(1)-execute(2)=7 to the user
assign read(4)-write(1)-execute(2)=7 to the group
assign read(4)-write(1)=5 to other
Basic Commands
chown
• chown will change the ownership of a file
from one user/group to anothers
• the syntax is:
chown user:group filename
• this will change file’s ownership to the
user/group specified
Basis Commands
ps
• ps is used to view processes that are running and
provides the process id (pid) for them. Somme of the
common flags used are:
• -e >> List information about every process now running
• -f >> Generate a full listing
• -a >> List information about all processes most
frequently requested: all those except process group
leaders and processes not associated with a terminal
• You can search for a process running by a specific user
by using the syntax
ps –ef | grep user
Basic Commands
kill
• kill is just what it sounds like. It will kill a process that its given via
process id (PID).
• There are many different kill flags
• kill on its own with do a graceful kill, which means it will wait for the
current process to finish what its doing before killing it.
• kill -3 <PID> will take a thread dump
• kill -9 <PID> will force a kill regardless what is happening to the
process.
Basic Commands
gzip/gunzip
• gzip and gunzip are used for zipping and
unzipping files respectively
• the syntax for gzip in its basic form is :
gzip filename
• This will create a compressed file with a .gz
extension.
• To decompress these files you can use gunzip.
It works in the same way as gzip does:
gunzip filename.gz
Basic Commands
find
• find is used to search through directories for files/folders that match
the search criteria given. The syntax is
find <starting directory> <options> <arguments>
• For example if you wanted to search the /etc directory for the
passwd file you would use
find /etc –name “passwd”
• You can also use –size (specify the size of a file), -mtime (specify
the modification time of a file)
Basic Commands
Running processes in the background and foreground

• When normally running a process it is


automatically run in the foreground. Because of
the way it was designed the shell can only run
one process at a time in the foreground.
• To run a process in the foreground it’s a simple
as typing in the pathname and process name.
• To run in the background you need to add an
ampersand(&) to the end of the command like:
./testapp.sh &
Basic Commands
Running processes in the background and foreground

• In the event that you run a process in the foreground that you need
to run in the background, what you can do is hit ctrl+z to temporarily
stop the process. From there you will be given an ID for the job:

• With this job ID (in this example 1) type


bg %1 to run it in the background

To bring it back into the foreground simply type fg %<JobID>


If you are unsure of the job id, you can type jobs at the command
prompt to get a list of the jobs running in the background.
Basic Commands
prstat
• prstat will give you a list of running
processes and the resources being taken
up by it.

• By running this with the –t flag you can get


the totals for each user on the system

You might also like