~ => your home directory
~x => x’s home directory
. => current directory
.. => parent directory
Absolute path: Start with "/"
/usr/share/bin
/home1/student/stud107/s107xx
Relative path: Path relate to current directory.
If current dir is /usr
test/bin => /usr/test/bin
li/public => /usr/li/public
Basic UNIX Command
ls list files in current directory.
ls
ls -l # list files details in current directory.
ls -a # list all files (include hidden files).
ls -la # Both of listing all files with details
Basic UNIX Command
How to create/delete/copy files or directories?
mkdir test# Create a directory named "test" in current directory
cp fileX dirY/dirZ
# Copy fileX from current directory to ./dirY/dirZ
cp fileX dirY/fileZ
# Copy fileX from current directory to dirY and rename to fileZ.
cp -r dirX dirY
# Copy dirX from current directory to dirY.# If dirY doesn't exist, dirY is a copy of dirX.# If dirY is a directory then there will be a copy of dirX under dirY.
Basic UNIX Command
How to create/delete/copy files or directories?
mv fileA dirB
# Move fileA to dirB.
mv dirA dirB
# If dirB exist, then move dirA under dirB.# If dirB does not exist, dirA is rename to dirB.
rm fileA
# Remove file fileA (Only for file)
rm -r dirA
# Remove directory dirA and all its contents
Basic UNIX Command - Your Round
Please create a directory named "1091cp1" mkdir 1091cp1
Enter directory "1091cp1" cd 1091cp1
Please create a directory named "abc" mkdir abc
Please rename "abc" to "xyz" mv abc xyz
Copy "xyz" and rename it as "jqk" cp -r xyz jqk
Please delete directory "xyz" and "jqk" rm -r xyz jqk
Basic UNIX Command - Recap
Use mkdir to create a directory
Use mv to move a directory/file or rename a directory/file
Use cp to copy a file and cp -r to copy a directory
Use rm for removing file and rm -r for removing directory
Basic UNIX Command - Others
The path used on cp, mv, rm, mkdir can be absolute path or relative path.
Use pwd to see what the current directory is.
Use whoami to see your account's name.
Use logout to logout the system. (or you can press Ctrl+D either)
Type Ctrl+L to clean your screen
Remember, whenever you have problems using Unix, try "man" command.
man ls
man cp
man stands for manual.
Basic Vim
Vim is a text editor that you can write texts, codes just like 記事本
To use it, you just need to type vim with a filename folowing it, e.g. vim test.txt
If the file exists, Vim will create one. Otherwise, it will open it.
Basic Vim
Vim basically has three modes:
Normal Mode:
Navigate, Search, Replace, Copy, Paste
Insert Mode:
Typing
Command-Line Mode:
Read, Write File...
Basic Vim
Vim starts in normal mode.
Press i to change to Insert mode.
Type some words…
Press ESC back to normal mode.
Press : or / to enter command-line mode. (Save, open file, search text, indenting…etc.)
Basic Vim
In the normal mode of vim, press i to insert mode and type some texts.
When you have done our work, press ESC back to normal mode.
Then type :w xxx.txt to save our work to xxx.txt
Now type :q to exit vim.
ls your files to check if the xxx.txt exists
Basic Vim - Others
Use :q! to quit Vim forcibly no matter if you have written your files.
If you quit without saving your will get a warning
Use :x or :wq to write your file and quit Vim with only one command.
Use :! to commaand shell command in VI, e.g. :!ls
Use :xxx to move cursor to the specific line.
xxx is the line number
Basic Vim - Your Round
Please create a file named "abc.txt" vim abc.txt
Please insert “hello world” at line 3 i -> Enter Twice -> Type hello world
Please save the file :w
Please quit the file :q
How to Lock Your Directory?
Create a directory named 1091cp1 at your home directory
mkdir ~/1091cp1
cd ~
Enter chmod -R 700 1091cp1 to lock your directory.
How to Lock Your Directory?
In UNIX, There are three access levels?
Owner => You
Group => Accounts in the same group, say, stud109
Others => Other guys…
For each level, you can set it permissions:
Read (r)
Write (w)
Execute (x)
How to Lock Your Directory?
Take a look at following ls -l output:
g9803 is the owner
grad98 is the group
The first letter will show - or d which are representing a file or a directory separately.