session 1 introduction of the courseokaweb.ec.kyushu-u.ac.jp/lectures/in-ng/2017/pdf/unix-en.pdfunix...
TRANSCRIPT
UNIX
情報ネットワーク特論資料
1
UNIX commands for manipulating files and directories
2
Command Description
mkdir / rmdir create and remove directories
cd change current directory
pwd show current directory
ls list files and directories
cp copy
mv move or change name
rm remove
cat show text file
less show text file page by page
Operations for editing commands
3
Operation Function
→ Move cursor right
← Move cursor left
C-a Go to the left-end
C-e Go to the right-end
C-u Cut entire line
C-k Cut from here to the left-end
C-y Paste
↑ Go to the older commands in the history
↓ Go to the newer commands in the history
TAB key Complete file name or command name
Hierarchical structure of file system on UNIX
File system on UNIX is hierarchically constructed with"directories" and "files"
directory= "folder" of Windows and Mac
Store files and other directories
4
unix memo.txtmemo.txt
test1.txttest1.txt
sample.csample.c
fortran
programming
directory
file
prog1.f90prog1.f90
prog2.f90prog2.f90
prog3.f90prog3.f90
Special directories
root directory: "root" of the entire hierarchy
home directory: Your "home" place
You can create or delete files and directoriesunder this directory
current directory: Directory you are working at
You can change "current directory" by cd command of UNIX
5
/
usrtmphomeetc
00nen
1234567890
unix
test1.txttest1.txt
01nen students
1000000000
rootdirectory
homedirectory
currentdirectory
"Path" of files and directories
Path= location of a file or a directory Path to reach to the file or directory
"xx/" means "under xx directory"
xx/yy/zz = zz under yy under xx
Used to specify files and directories for UNIX commands
Relative path: path from "current directory"
Absolute path path from "root directory"
6
/home/students/1234567890/unix/test1.txt
unix/test1.txt
relative path from /home/students/1234567890
absolute path
Example:path to this file
test1.txt
relative path from/home/students/1234567890/unix
mkdir / rmdir
mkdir: MaKe DIRectory create one or more directories
rmdir: ReMove DIRectory only "empty" directory can be
removed
to remove non-empty directory, use "rm" command
Examples) make a directory test in work
directory in the current directory
make multiple directories in the current directory
remove directory work in test directory in the current directory
7
$ mkdir work/test
$ mkdir test1 test2 test3
$ rmdir test/work
cd
cd: Change current Directory Why do we change the current
directory?=> To shorten the UNIX commands
For example: make three directories in "work" directory
from /home/students/1234567890
after moving to unix directory
Examples) Go back to your home directory
Go to directory test in the current directory
Go to directory work in the testdirectory in the current directory
8
$ mkdir unix/dir0 unix/dir1 unix/dir2
$ cd unix$ mkdir dir0 dir1 dir2
$ cd test
$ cd test/work
$ cd
pwd
pwd: Print Working Directory "working directory"
= current directory
Execute this command frequently to check where you are now.
Since does not make any change on filesor directories
Avoid miss operation
9
ls
ls: LiSt files and directories See names of files and directories in
current directory, or other directories UNIX does not show files even in the current
directory, automatically. => You need to do it by yourself.
Options: -l
Show detailed information of each file
-R
Show hierarchy of files and directories
-a
Show files whose name starts with "."
Usually those files are hidden
Examples) list files and directories in the current
directory
list files in the directories test1 and test2 (if they are directories)
list files test1 and test2(if they are files)
list detailed information of "test1"
list hierarchy of files in the current directory with information
10
$ ls
$ ls test1 test2
$ ls test1 test2
$ ls -l test1
$ ls -lR$ ls -l test1-rw-r--r-- 1 z6nt03in students 193 Apr 22 22:35 test1
owner last update timesize
cp
cp: CoPy Copy files and/or directories
Copy 1 filecp original_file new_file
Copy 1 directorycp -R original_directory new_directory
Copy multiple files and/or directories to a directorycp file1 file2 file3 existing_directorycp -R file1 file2 dir1 dir2 existing_directory
Options:
-R
Copy directory with all files and directories in it.
-i
Confirm before overwriting existing files
Examples) Make a copy of the file "test1" as file
"test2"
Copy the file "test1" to the existing directory "test2"
Make a copy of the directory "test1" as "test2"
Copy the directory "test1" to the existing directory "test2"
Copy multiple files and directoriesto the existing directory "test4"
11
$ cp test1 test2
$ cp -R test1 test2
$ cp test1 test2
$ cp -R test1 test2
$ cp -R test1 test2 test3 test4
test1test1
test1test1 test2
test2test2
test1test1
mv
mv: MoVe Move files (and/or directories)
or Change name of a file (or directory)
Move files and/or directories to directorymv file1 file2 dir1 dir2 existing_directry
Change name of a file (or directory)mv old_name new_name
Options:
-i
Confirm before overwriting existing files
Note:mv does not require "-R" option to move
directories
Examples) Change name of the file (or directory)
"test1" to "test2"
Move the file (or directory) "test1" to the existing directory "test2"
Move multiple files and directories to the existing directory "test4"
12
$ mv test1 test2
$ mv test1 test2
$ mv test1 test2 test3 test4
test1test1
test1test1 test2
test2test2
test1test1
rm
rm: ReMove Remove files.
Note: UNIX does not have "Trash Box"= Removed files cannot be resumed.
Options:
-R
Remove entire directory
-i
Confirm before removing each file or directory
Examples) Remove files "test1" and "test2"
Remove directories "test1" and "test2"
Remove a directory "test" with confirmation
13
$ rm test1 test2
$ rm -R test1 test2
$ rm -iR test
cat / less
cat: Show text file(s) at once
less: Show a text file page-by-page
use following keys in this command:
j or down cursor : down 1 line
k or up cursor : up 1 line
space : down 1 page
b : up 1 page
g : go to the top
G : go to the bottom
/ : search forward for a keyword
? : search backward for a keyword
q : quit
14
Special symbols in path
/ (in the beginning of a path) root directory
.. 1-level upper directory
Ex) (from /home/students/1234567890)
. current directory
Ex)
~ home directory
15
Example:(from /home/students/1234567890 )
/tmp
..
.
unix
unix/test1.txt
../1000000000~
absolute path
absolute path
relative path
relative path
relative path
relative path
relative path
/
absolute path
$ ls -l ../../00nen
$ cp unix/test1.txt .
Change Language
Login to ah.s.kyushu-u.ac.jp
Type the following commandand press Enter.
This will change your default language.
It take effects from next login.
Exit, and login again.
16
$ echo export LANG=C >> ~/.bashrc
Create or modify programs:emacs
• Start text editer Emacs
• Usage:emacs filename
– If that file does not exist, create a new file– If that file exists, open it.
• Example: Create or start editing the file test.f90
17
--uu:--F1 test.f90 (F90)--L1--All
$ emacs test.f90
View of Emacs
18
--uu:--F1 test.f90 (F90)--L1--All
Text window: edit texts
Mode line:Displays the file name, current line number, etc.
Mini buffer:Displays commands or messagesFile name
Line numberwhere the cursor is.
Operations in EmacsOperation Function
C-f or → Move forward
C-b or ← Move backward
C-n or ↓ Move to the next line
C-p or ↑ Move to the previous line
C-d Delete the character at the cursor
delete Delete the character before the cursor
C-g Stop command
C-x C-s Save file
C-x C-c Exit Emacs
19
C- means "Press the key with pressing Ctrl key"Ex. C-x Press x key with pressing Ctrl key
When the Emacs behaves unexpectedly
Press C-g for some times If Emacs returned to normal status, continue editing
If it didn't return, exit Emacs with C-x C-c Press y for "Save file .... ?"
Then restart Emacs by
emacs the_file_name_you_were_editing
20
For more understanding
Read "UNIX Operating System" by Yukun Liu, et al Available from
http://www.springerlink.com
Specially, sections 3.1 and 3.8
21