Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Unix

• brief history:
 Multics (1964) for mainframes
 Unix (1969)

Lecture 1 

K&R
Linus Torvalds and Linux (1992)
• key Unix ideas:
 written in a high-level language (C)
Introduction to Linux/Unix  virtual memory
 hierarchical file system; "everything" is a file
environment  lots of small programs that work together to solve (giải quyết) larger
problems
 security, users, access, and groups
 human-readable documentation included
1 2

1 2

Linux Linux Desktop


• Linux: A kernel for a Unix-like operating system. • X-windows
 Commonly (thường) seen/used today in servers, mobile/embedded • window managers
devices, ... • desktop environments
• GNU: A "free software" implementation of many Unix-like tools  Gnome
 many GNU tools are distributed with the Linux kernel  KDE
• distribution: A pre-packaged (được đóng gói sẵn)set of Linux
software.
 examples: Ubuntu, Fedora, CentOS
• How can I try out Linux?
• key features of Linux:  CSE Virtual machine
 open source software: source can be downloaded
 CSE basement labs
 free to use
 Shared server
 constantly being improved/updated by the community

3 4

3 4

1
Things you can do in Linux Shell
• Load the course web site in a browser • shell: An interactive program that uses user input to manage the
execution of other programs.
• Install and play games  A command processor, typically runs in a text window.
 User types commands, the shell runs the commands
• Play MP3s  Several different shell programs exist:
• bash : the default shell program on most Linux/Unix systems
• We will use bash
• Edit photos • Other shells: Bourne, csh, tsch

• IM, Skype • Why should I learn to use a shell when GUIs exist?

5 6

5 6

Why use a shell? Shell commands


• Why should I learn to use a shell when GUIs exist? command description
 Faster exit logs out of the shell
 Work remotely ls lists files in a directory
 Programmable pwd print the current working directory
 Customizable (tùy chỉnh) cd changes the working directory
 Repeatable man brings up the manual for a command
$ pwd
/homes/iws/rea
$ cd CSE391
$ ls
file1.txt file2.txt
$ ls –l
-rw-r--r-- 1 rea fac_cs 0 2017-03-29 17:45 file1.txt
-rw-r--r-- 1 rea fac_cs 0 2017-03-29 17:45 file2.txt
$ cd ..
$ man ls
$ exit

7 8

7 8

2
Relative directories Directory commands
directory description
command description
. the directory you are in ("working directory")
ls list files in a directory
.. the parent of the working directory
pwd print the current working directory
(../.. is grandparent, etc.)
~ your home directory cd changes the working directory
(on many systems, this is /home/username ) mkdir create a new directory
~username username's home directory rmdir delete a directory (must be empty)
~/Desktop your desktop

• some commands (cd, exit) are part of the shell ("builtins")


• others (ls, mkdir) are separate programs the shell runs

9 10

9 10

Shell commands Command-line arguments


• many accept arguments or parameters • most options are a - followed by a letter such as -c
 example: cp (copy) accepts a source and destination file path  some are longer words preceded (đi trước) by two - signs, such as --
count
• a program uses 3 streams of information:
 stdin, stdout, stderr (standard in, out, error) • options can be combined: ls -l -a -r can be ls -lar

• input: comes from user's keyboard • many programs accept a --help or -help option to give more
• output: goes to console information about that command (in addition to man pages)
• errors can also be printed (by default, sent to console like output)  or if you run the program with no arguments, it may print help info

• parameters vs. input • for many commands that accept a file name argument, if you omit
 parameters: before Enter is pressed; sent in by shell (bỏ sót/quên) the parameter, it will read from standard input (your
 input: after Enter is pressed; sent in by user keyboard)
11 12

11 12

3
Shell/system commands File commands
command description command description
man or info get help on a command cp copy a file
clear clears out the output from the console mv move or rename a file
exit exits and logs out of the shell rm delete a file
touch create a new empty file, or
command description update its last-modified time stamp
date output the system date
• caution: the above commands do not prompt for confirmation
cal output a text calendar
 easy to overwrite/delete a file; this setting can be overridden (how?)
uname print information about the current system

• Exercise : Given several albums of .mp3 files all in one folder, move
• "man pages" are a very important way to learn new commands
them into separate folders by artist.
man ls
man man • Exercise : Modify a .java file to make it seem as though you
finished writing it on Dec 28 at 4:56am.
13 14

13 14

Exercise Solutions Basic Emacs Commands


• C- = control key M- = meta/alt key
• caution: the cp, rm, mv commands do not prompt for confirmation
• read a file into Emacs: C-x C-f
 easy to overwrite/delete a file; this setting can be overridden (how?)
• Use “-i” with the command, “interactive” to prompt before overwrite • save a file back to disk: C-x C-s
• exit Emacs permanently: C-x C-c
• Exercise : Given several albums of .mp3 files all in one folder, move
• search forward: C-s search backward: C-r
them into separate folders by artist.
• scroll to next screen: C-v scroll to previous screen: M-v
 mkdir U2
• Undo: C-x u
 mkdir PSY
 mkdir JustinBieber entity to move over backward forward
 mv GangnamStyle.mp3 PSY/ character C-b C-f
 mv Pride.mp3 U2/ word M-b M-f

• Exercise : Modify a .java file to make it seem as though you line C-p C-n
finished writing it on Dec 28 at 4:56am. go to line beginning/end C-a C-e
 touch –t "201812280456" Hello.java go to buffer beginning/end M-< M->

15 16

15 16

4
Basic Vim Commands
• :w Write the current file
• :wq Write the current file and exit.
• :q! Quit without writing
• To change into insert mode: i or a
 Use escape to exit
• search forward /, repeat the search backwards: N
• Basic movement:
 hlkj character left, right; line up, down (also arrow keys)
 bw word/token left, right
 ge e end of word/token left, right
 0$ jump to first/last character on the line
• x delete
• u undo

17

17

You might also like