Introduction to UNIX Commands

Waseda UniversityBasic UNIX commands

manpwdcdlsmkdir
rmdir
history
cpmvrmlesschmod

display the manual page of each command
display the working directory namechange the working directory
list directory contents
make directories
remove directories
display the history commands
copy ﬁlesmove ﬁles, rename the ﬁleremove directory entries
display ﬁle contentschange ﬁle modes

UNIX command 【man】
man: (manual) display the manual page of each commanddisplay the manual page of the command$ man 【command】
The 【man】 command uses the 【less】 command by default
Commands↑ or ↓fb/
qMeaning
Forward or backward one line
Forward one window
Backward one window
Search forward
QuitUNIX command 【man】

UNIX command 【man】

UNIX command 【pwd】
pwd: (print working directory) display the working directory namedisplay the working directory name[∼]$ pwd
【ツリー構造】

Directory has a tree structure.
Each directory contains ﬁles.
When the terminal is started, it
starts in the home directory.

UNIX command -pwd-

directory : absolute path vs. relative pathabsolute path
An absolute path is the location of a ﬁleor a directory from the root directory(/)/home/w508696/work/waseda.txt

relative path
A relative path is the location of a ﬁleor a directory from the current directory./work/waseda.txt※ The single dot(.) means the current
directory. The double dot(..) means theparent directory.

UNIX command 【ls】

ls: (list) list contents of the current directorydisplay contents of the directory[∼] $ ls※ Display contents of your current directory: lsUNIX command 【ls】
The following commands are available:display details of the content

[∼] $ ls -alinclude all directory entries[∼] $ ls -alist contents of “Desktop” directory[∼] $ ls Desktop※ Look up other options by the command: man ls

UNIX command 【ls】

UNIX command 【ls】

UNIX command 【mkdir】

mkdir: (make directory) make directoriesmake the directory named “work”

[∼] $ mkdir work

※ Check by the command ls that the directory work was successfully
createdUNIX command 【mkdir】

UNIX command 【mkdir】

UNIX command 【rmdir】

rmdir: (remove directory) remove directories
remove the work directory[∼] $ rmdir work

※ Check by the command ls that the directory work was removed.

UNIX command 【rmdir】

UNIX command 【rmdir】

UNIX command 【history】 and 【!】history：Display the command historyDisplay the command history with line numbers[∼] $ history!n：Refer to command line nRefer to command line 20[∼] $ !20


UNIX command 【!!】 and 【!string】!!：Refer to the previous commandRefer to the previous command[∼] $ !!
!string：Refer to the most recent command starting with string
Refer to the most recent command starting with m[∼] $ !m

※ 【’ !m】’ will recall 【mkdir work】

UNIX command -history-

UNIX command 【history】

UNIX command 【history】

UNIX command 【history】

UNIX command 【↑】【↑】: input previous commands
recall the history command[∼] $ 【↑】(“history” is also available.)※ Display a history of commands: historyUNIX command 【Tab】【Tab】：auto completion of a file name or a directory namedisplay the contents on Desktop[∼] $ ls De【Tab】


If you press the【Tab】key when you type the directory name, there isno need to type all.
The ﬁle name, directory name is case-sensitive.

UNIX command 【cd】

cd: (change directory) change the working directorychange the current directory to the work directory[∼] $ cd work[∼/work] $※ Display the working directory name by the command: pwdUNIX command 【cd】

change the current directory to the parent directory[∼/work] $ cd ..
【..】denotes the parent directory.
【 ˜ 】denotes the home directory.

A space is needed after the cd command.

UNIX command 【cd】

UNIX command 【cd】

UNIX command 【cd】

EmacsRunning Emacs on the terminal[∼/work] $ emacs &Emacs is an editor to create and modify text ﬁles.
In this class we create a text ﬁle by using Emacs.
(The “vi”, “gedit” etc. are also acceptable.)
We will create all ﬁles in the “work” directory.
Type “&” at the end of the command.
Quit Emacs by typing 【Ctrl】+【x】，【Ctrl】+【c】.

Emacs
Start Emacs by specifying the ﬁle name[∼/work] $emacs hello.txt &

If the speciﬁed ﬁle does not exist, it is newly created. The ﬁle isopened if it already exists.

Emacs
Start Emacs by specifying the ﬁle name[∼/work] $emacs hello.txt &The ﬁles is saved by 【Ctrl】+【x】，【Ctrl】+【s】.
To quit Emacs type 【Ctrl】+【x】，【Ctrl】+【c】.
You should learn some key operations by yourself.
※ Check if hello.txt has been created by the command: ls

EmacsEmacsUNIX command 【less】
less: display a filedisplay waseda.txt

[∼/work] $ less waseda.txt
Commandsh↑ or ↓fb/q.

MeaningDisplay this help
Forward or backward one line
Forward one window
Backward one window
Search forwardQuit

UNIX command 【less】

UNIX command 【less】

UNIX command 【cp】

cp: (copy) copy files

create a copy of waseda.txt as sample.txt

[∼/work] $ cp waseda.txt sample.txt
※ Check that sample.txt has been created by the command: ls※ Check if the ﬁle is copied: less sample.txt

UNIX command 【cp】

create a copy of a ﬁle in a diﬀerent directory[∼/work] $ cp waseda.txt ../temp.txt
Create a copy of waseda.txt as temp.txt in the parent directory※ Change the current directory to the parent directory: cd ..
※ Check that temp.txt has been created: less temp.txt※ Change the current directory to work directory: cd work

UNIX command -cp-

UNIX command 【cp】

UNIX command 【mv】

mv：(move) move files, rename the filerename sample.txt temp2.txt

[∼/work] $ mv sample.txt temp2.txt
※ Check if sample.txt is renamed: lsUNIX command 【mv】

move temp2.txt to temp3.txt in the parent directory[∼/work] $ mv temp2.txt ../temp3.txt
※ Check if temp2.txt has been moved: ls※ Change the current directory to the parent directory and check if
temp3.txt exists: cd .. , lsUNIX command 【mv】

UNIX command 【mv】

UNIX command 【rm】

rm：(remove) remove files or directories
remove temp.txt

[∼] $ rm temp.txt


Please be careful when removing ﬁles because the deleted ﬁle cannot
be recovered.
※ Check if temp.txt has been deleted: ls

UNIX command 【rm】

remove temp3.txt with options

[∼] $ rm -i temp3.txt
rm: ’temp3.txt’ (yes/no)? yThe option -i requests conﬁrmation before attempting to remove eachﬁle.
Type y to remove or n to cancel.
Please be careful because many ﬁles may be deleted without
possibility to recover.
※ Changing the current directory to work directory: cd work

UNIX command 【rm】

UNIX command 【rm】

UNIX command 【chmod】
chmod: (change mode) change Access Control Listsdisplay detail information of waseda.txt[∼/work] $ ls -l-rw-r–r– 1 1W120000student

89 Apr 23 19:02 waseda.txt

Others can read your created ﬁle.
Detail information of waseda.txt says:

First two digits rw in「-rw-r–r–」shows that the user can read (r) andwrite (w) this ﬁle.
Next r in the middle represents a right to access of a group member.
The last r represents a right to access of others.

UNIX command -chmod-remove the read permission from group and others[∼/work] $ chmod go-r waseda.txt
※ Check if the permission has been changed into「-rw——-」: ls -lUNIX command -chmod-
add the read permission to group and others[∼/work] $ chmod go+r waseda.txt

※ Check if the permission has been changed into「-rw-r–r–」: ls -lUNIX command -chmod-

UNIX command -chmod-Summary

Learning basic UNIX commands
man, pwd, ls, cd, mkdir, rmdir, cp, mv, rm, less, chmod
Operations in Emacs