2023 UNIX Lecture 1
2023 UNIX Lecture 1
Spring 5783
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
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
Regular expressions
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.
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 “>”
The shell then searches through the executable programs on the system for one
with the name you specified and runs it.
If the shell can’t find your command, it will print, “Command not found”. You
probably misspelled it!
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.
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
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
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
Example
/usr/bin/ls -l
or even
/usr/bin/ls -l /usr/u/home/danzig
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
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
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.
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
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.