ceng151 lecture pointsapollo.humber.ca/~king/ceng151/jan18.pdfdo this once only the following sets...
TRANSCRIPT
-
CENG151 Lecture PointsWeek 1
-
Part I: Preliminary Steps
-
PUTTY TIPS
Choose a different font size & style
Port 22 means putty uses ssh. Leave this alone
Choose “System Colors”For black text, white background.
Turn off that annoying bell
Specify your login id & system
Define the settings you want, give it a name and Save for later
Select “Use Unicode line drawing code points so you can put emojis in your code
Download & install putty from: https://www.chiark.greenend.org.uk/~sgtatham/putty/
Use this to set a file to record your session
https://www.chiark.greenend.org.uk/~sgtatham/putty/
-
MAC TERMINALPREFERENCES
Choose a different font size & style
Turn off that annoying bell
-
Logging in from Mac Terminal (or connecting from one Unix system to another)
ssh yourid@location
ie: ssh [email protected]
mailto:yourid@location
-
DO THIS ONCE ONLY
The following sets up vim to use a resource file .vimrc
ln -sf ~king/.vimrc ~/.vimrc
ls -la ~ #Shows your home directory including hidden files
#You should see…
lrwxrwxrwx 1 user student 6 date .vimrc -> ~king/.vimrc
-
Part II: Navigating Unix’s Directory Tree
-
Standard Unix Directories/
/bin essential system binaries
/boot/dev -terminals, disks, devices, mice - /dev/pts/1 ....
/dev/tty - always a synonym for the current terminal/dev/null - watch for it
/etc - host specific system configuration files/home
/mnt mounted devices/opt - add on optional software/root/sbin - system binaries/tmp - temporary files/usr - NOT USER, unix systems resources
/usr/bin - most user commands/usr/include - standard C include files/usr/lib - libraries for programming and packages
/var - varying data files - account information, logs, system web pages
-
Unix Directory Commands
pwd #print working directory
cd name #change directory Also works with ~ $HOME
mkdir newDir #create a directory
rmdir oldDir #remove a directory (must be empty!)
ls –ld dirName #Show the properties of the directory, not its contentscd .. #move to the parent directorycd ../.. #move to the grandparent directory
cd /usr/bin #move to the absolute path location
cd ../include #move up a directory & down to include – relative path
cd - #switch to immediately previous directory
-
. & ..
Every directory has at least 2 files: . and ..
. represents the current directory
.. represents the parent of the current directory
-
Part III: Security/File Permissions
-
Security applies to 3 entities
This Photo by Unknown Author is licensed under CC BY-SA-NC
This Photo by Unknown Author is licensed under CC BY-SA
Users (you) Others
Groups
https://oldschool.runescape.wiki/w/Minnowhttps://creativecommons.org/licenses/by-nc-sa/3.0/https://commons.wikimedia.org/wiki/File:Crystal_Clear_kdm_user_female.svghttps://creativecommons.org/licenses/by-sa/3.0/
-
Files in Unix have 3 privileges which can be combined
ReadExecute/Navigable
Write
-
Navigable only applies to directorys
-
The ls -l command displays file permissions in symbolic form
- r w x r w - - - -
User (you) Group Others
-
The chmod command uses the symbols ugo + - = rwxto change file permissions. You can separate specifications by a comma, no spaces
chmod u=,a+rx,go-x,g+r file1 file2 file3
-
There are 8 possible combinations of r, w and x
rwx
000 0 - - -
001 1 - - x
010 2 - w -
011 3 - w x
100 4 r - -
101 5 r – x
110 6 r w -
111 7 r w x
chmod 0711 file1 file2 file3…
-
Permissions affect the visibility of your files and directories to others.
Browsers: The visibility of web pagesfinger: The visibility of the .plan and .project filesecho: The visibility of a terminal
-
Writing on someone else’s terminal:
Them: chmod g+w /dev/pts/7
You: echo “Hello, this is $USER” > /dev/pts/7
*Whenever you see “ “ or ‘ ‘ in an assignment or in documentation, do not cut and paste to Unix. These are “Microsoft Quotes” and not the same as
" " or ' ‘ which are ASCII values.
-
Access Control Lists
setfacl -m u::rwx,g::r,o:r,u:vgld0005:rw,g:sharks:r file1 file2 …
#Deleting an ACL permissionsetfacl -x g:shark file1
#Showing an ACL permissiongetfacl f1
Using an ACL permission the owner of file can grant or deny access to any individual or group. There is a limit of about 500 ACL entries to a file. If there is a need for
-
Part IV: Switching between systems
-
The ssh command can be used to log into another system.
This is what Mac and Linux users in this course use to connect to apollo and munro.
[king@apollo ~ ] ssh [email protected]
king @ munro.humber.ca’s password:
-bash-3.2$
It may also work with your version of Windows 10 command line or PowerShell if has been
updated since May 2019.
ssh #secure shell command
mailto:[email protected]
-
The ssh command can be used to run one or more commands on the remote machine or
on the same machine using a different account
Ssh [email protected] finger
ssh [email protected] “uptime;date;who”
ssh target cmd
ssh target “cmd1; cmd2”
-
The scp command can be used to copy files between two different machines, even if you
are not currently logged on to either!
scp [email protected]:hello.c . #copy from apollo to the current dir
scp [email protected]:hello.c helloX.c #copy to a new name
scp -p [email protected]:report.doc [email protected]:report.doc
scp #secure copy command
mailto:[email protected]:hello.cmailto:[email protected]:hello.cmailto:[email protected]:report.doc
-
The su command lets you switch to a different account on the same machine:
su kingtest
password:
su #substitute user command
-
vim scp://[email protected]/someFile.txt
[email protected] password: (enter your password)
If you are already in vim you can use either the :e command or the :n command
:e scp://[email protected]/someFile.txt
:n scp://[email protected]/someFile.txt
:w and :wq will save the file that you loaded
:w scp://user@machine/otherName.txt
Using scp with vim to edit remote files
mailto:[email protected]
-
The newgrp command allows you to change your current group to any other group where
you happen to be a member. Most systems will prompt you for a group password. Our
systems don’t.
newgrp sharks
id
uid=551(king) gid=2331(sharks) groups=504(staff),2331(sharks),2332(minnows)
newgrp #switch to a different group
-
Part V: More Vim
Vimtutor
Section 3
Section 4
Section 6.1-6.4
-
Topic Moved to June 3-4
-
Part VI: Aliases to FilesHard Links and Symbolic Links
-
inodesThe -i flag of the ls command shows the inode of each file.
An inode is a unique number (per hard drive), handed out in sequence that represents a file.
A directory consists of a set of inodes and file names. That’s it!
2893824 file1
2893825 file2
2893826 file3
3182611 myReport.txt
17001428 Schedule.dat
.
.
.
.
.
.
-
Each inode # points to a location in the SuperBlock, a region of the disk drive where file properties such as atime, mtime and ctime and the file’s contents are kept, but not the file name:
2893824 file1
2893825 file2
2893826 file3
3182611 myReport.txt
17001428 Schedule.dat
.
.
.
.
.
.
SUPERBLOCK HEADER
Permissions
Size
link count
atime
mtime
Ownerid
Groupid
link to content File contents
3182611
Permissions
Size
link count
atime
mtime
ownerid
Groupid
link to content
2893824
File contentsPermissions
Size
link count
atime
mtime
ownerid
Groupid
link to content
2893825
File contents
-
mv Schedule.dat newSched.dat
The mv (move) command can rename a file or move it between directories. It does not copy the data, it renames the file and reuses the same inode#.
2893824 file1
2893825 file2
2893826 file3
3182611 myReport.txt
17001428 newSched.dat
.
.
.
.
.
.
-
ln file1 fileXYZln file1 dir2/anotherNameThe ln (link) command can rename a file or move it between directories. It does not copy the data, it renames the file and reuses the same inode#.The link count of the file will increase by 1. Only the inode# and the name are affected.
2893824 file1
2893825 file2
2893826 file3
3182611 myReport.txt
17001428 newSched.dat
2893824 fileXYZ
.
.
.
.
.
.
57282 hello.c
57888 Lab1.mak
2893824 anotherName
dir2
dir1
-
rm file1unlink fileThe rm (remove) and unlink commands remove a file and its inode from a directory and reduce the link count in the SuperBlock by 1. The data and the file properties arestill kept… and only removed from the system when the link count goes to zero.
2893825 file2
2893826 file3
3182611 myReport.txt
17001428 newSched.dat
2893824 fileXYZ
.
.
.
.
.
.
57282 hello.c
57888 Lab1.mak
2893824 anotherName
dir2
dir1
-
ln -s dir1/fileXYZ dir2/symLink1The hard link idea had one problem. People would move hard disks from system to system. You couldn’t guarantee that the inode #s would be unique between disks. Hard links don’t work across different devices.
The solution: create a 2nd technique: create a new file type called symbolic link. The content of this new file would be the name of the old file.
2893824 file1
2893825 file2
2893826 file3
3182611 myReport.txt
17001428 newSched.dat
2893824 fileXYZ
57282 hello.c
57888 Lab1.mak
2893824 anotherName
3100105 symlink2
-
Setting up .vimrc (vim resource control file) using a symbolic link
Enter the following command on apollo. This is a one time only requirement and will be explained in class. The spaces are exaggerated to make sure that you use them.
ln -sf ~king/.vimrc ~/.vimrc