0% found this document useful (0 votes)
16 views19 pages

2023 UNIX Lecture 1

UNIX is an operating system developed at Bell Labs in 1969, later rewritten in C and ported to PCs as Linux in 1991. The course covers command line usage, scripting, file manipulation, and C programming in a Linux environment, emphasizing the importance of understanding UNIX for grasping other operating systems. Key topics include the shell's command execution, directory structure, basic commands, and utilities for file management.

Uploaded by

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

2023 UNIX Lecture 1

UNIX is an operating system developed at Bell Labs in 1969, later rewritten in C and ported to PCs as Linux in 1991. The course covers command line usage, scripting, file manipulation, and C programming in a Linux environment, emphasizing the importance of understanding UNIX for grasping other operating systems. Key topics include the shell's command execution, directory structure, basic commands, and utilities for file management.

Uploaded by

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

UNIX Systems

Spring 5783

ⒸNachum Danzig 2021


What is UNIX?
Operating System for PDP-7

Developed at Bell Labs 1969 [ Ken Thompson, Dennis Ritchie ]

Intended as a development platform for

Rewritten in 1972 in the purpose created language C by Dennis Ritchie (Brian


Kernighan )

Linux: In 1991 Linus Torvalds ported UNIX to the PC, called it Linux

In this course the terms Unix and Linux will be used interchangeably

ⒸNachum Danzig 2021


Why Learn UNIX?

It is a well organized Operation System

It is stable, scalable, and safe (True for most modern OS)

the proof is, it is still widely in use. Examples: linux, macOS, iOS, Android

If you understand what services UNIX provides, you will understand the services
of other powerful OSs

Open Source

ⒸNachum Danzig 2021


What will we learn?
How to use a command line interface.

Concept of scripting and how to write scripts

File manipulation Tools [ grep, sort, find]

Regular expressions

C programming in Linux environment

Low level compiling

How to use the tools the operating system provides to the C programmer
ⒸNachum Danzig 2021
How do I communicate with the UNIX system?
You can install Linux instead of Windows on a PC and the user experience will be
similar to Windows.

When remotely accessing a UNIX or Linux server we usually use a Command


Line Interface (CLI) it is also possible to use a Graphical User Interface (GUI)

What we type on the command line is executed by a program called the “shell”.

The shell is also an interpreter, so it can run a file containing a set of commands.

When the shell finishes to execute a command, it will print a prompt, like this “>”

If the command fails, the shell will print an error message.


ⒸNachum Danzig 2021
How does the Shell find its commands?
When you type a command, the shell assumes you are specifying a program to
run.

The shell then searches through the executable programs on the system for one
with the name you specified and runs it.

It is also possible the command is something the shell itself is programmed to do


without having to run a separate program. This is a built-in command.

If the shell can’t find your command, it will print, “Command not found”. You
probably misspelled it!

ⒸNachum Danzig 2021


Example of how shell looks

ⒸNachum Danzig 2021


Does the shell search all folders for the command?
In Unix we call folders directories

Searching everywhere would be slow!

We define a PATH which lists which directories to look in for the command
(remember, the command is just a program name)

What if two different directories in the path have programs with the same name?
Which one will be executed?

First come, first serve. It depends on the order of directories in your PATH.

ⒸNachum Danzig 2021


Commands can have parameters
Just like functions in C++, commands have parameters. They are separated by
whitespace.

Standard command format:

Command -flag … operand …

This means a command can have one or more operands and multiple flags.

A command will have a standard behavior on its operands, but that behavior can
be changed by specifying one or more flags

ⒸNachum Danzig 2021


Examples of some commands
> ls myDirectory ls is the command name,
> ls -l myDirectory myDirectory is the parameter
> ls
the second line use the -l flag
> rm myFile
> cp myFile copyOfMyFile the third line has no
> cd myDirectory parameters, just the command
> cd rm is a different command
>cd ~ cp is a command that requires
two parameters
cd can be run without a
parameter or with one

ⒸNachum Danzig 2021


The Unix Directory Structure
What “Windows” calls folders, in UNIX are called directories

Every directory can contain many subdirectories and files

The top level directory is called root, designated by a slash ”/” (not by a “c:”)

Everything in the File Structure is treated as a file even if in fact it is not. For
example, these are treated like files:
Directories
Links to other Files
Device (Special) Files
Named Pipes
Sockets
ⒸNachum Danzig 2021
Graphical Representation of Directory Structure

ⒸNachum Danzig 2021


Navigating the file tree
Relative path specification: Start from whatever directory you are currently in and

specify the path based where you are. Use .. to go up or backward. Examples:
cd homework/unix
cd ../../html/danzig

Absolute path specification: Start from root and write all the path. Examples:

cd /usr/u/home/danzig

ⒸNachum Danzig 2021


You can specify the location of the command
Instead of letting the shell search the path for your command, you can tell the shell
exactly where the command you want to run is located.

Example

/usr/bin/ls -l
or even
/usr/bin/ls -l /usr/u/home/danzig

ⒸNachum Danzig 2021


Basic Commands
cp, rm, mv - copy, remove (delete) , move (rename or move file location)
rm -r * , rm -f to force deletion (be careful with these two commands)
ln - create a link to a file, default hard (copy), -s symbolic (virtual)

rmdir, mkdir - delete empty directory, make a new empty directory

ls - list files and directories : ls -l, ls -lt, ls -lrt , ls -lrt a*, ls -a (shows hidden
files: .bashrc)

touch - create a new blank file or update modified time of existing file

man - show manual pages (section 1) commands, (section 2) system calls,


(section 3) C library functions . There are 8 sections to the manual
ⒸNachum Danzig 2021
Man Page Sections
Section: Contents in BSD, Linux, macOS (System V is slightly different)

1 General commands
2 System calls
3 Library functions, covering in particular the C standard library
4 Special files (usually devices, those found in /dev) and drivers
5 File formats and conventions
6 Games and screensavers
7 Miscellanea
8 System administration commands and daemons

ⒸNachum Danzig 2021


help
help is a built in Bash feature which explains built in Bash functions

For example

“help cd” will explain what the function cd does. cd is a built-in shell command

But “help ls” will print “no help topics match `ls'” because ‘ls’ is a separate
command, not built in to Bash.

You can also write for example “help for”. This will give an explanation of the shell
“for” loop feature.

ⒸNachum Danzig 2021


Useful Commands for Viewing Files
cat - display a file’s content on the screen

more, less - display file contents in page sized increments

head, tail - display first or last part of file, use -n5 or just -5 to specify 5 lines

wc - word count - print the number of lines, words, and letters in a file
Flags : -c bytes, -w words, -l lines
sort - sort the lines by the alphabet flags: -r, -n

uniq - reports or filters out repeated lines in a file.

diff - show differences between two files


file - print type of file (binary, ascii etc.)

strings - print ascii strings contained in even a binary file ⒸNachum Danzig 2021
Some UNIX Utilities
apropos - find commands similar to or related to the given command
which
whereis
date
scp - copy a file to or from a remote system, scp file [email protected]:file2
ps ps aux
last - show listing of last logged in users
uname - print the name, version and other details about the machine and OS
-a print all information, for example kernel name and release
ⒸNachum Danzig 2021
number.

You might also like