●●● Basic Linux commands ●●●● ●●●●● ●●●● ●●●●● working in the shell(2 /2) ●●●● logout logout leave the systems r lpr-h f1 f2 print f1, f2 without header page man man tar displaying the manual page on-line, e.g. tar nohup nohup matlab <a& run matlab(a.m)without hang up after logout s find out all process run in the systems sort sort-r-n studio sort studno in reverse numerical order tar ar cvf abc. tar abc/ create archive file uncompress uncompress file 1.Z the opposite of compress WC WC-I f1 count the number of lines in f1 who who Who is on line whoami whoami identify yourself
Basic Linux commands – working in the shell (2/2) logout logout leave the systems lpr lpr -h f1 f2 print f1, f2 without header page man man tar displaying the manual page on-line, e.g. tar nohup nohup matlab < a & run matlab (a.m) without hang up after logout ps ps -ef find out all process run in the systems sort sort -r -n studno sort studno in reverse numerical order tar tar cvf abc.tar abc/ create archive file uncompress uncompress file1.Z the opposite of compress wc wc -l f1 count the number of lines in f1 who who who is on-line whoami whoami identify yourself
●●● ●●●● ●●●●● ●●●● ●●●●● Linux file system ●●●● o Linux is a file-oriented /(root) system In Linux, files can be regular files, directories or special lib users tmp dev‖sb files such as devices sockets null staff studentI visitor Ahierarchical directory /dev/null structure similar to an guest inverted tree can be found gog lusers/statt/guest/gu09
Linux file system ⚫ Linux is a file-oriented system. In Linux, files can be regular files, directories or special files such as devices, sockets. ⚫ A hierarchical directory structure similar to an inverted tree can be found. / (root) usr users tmp staff var student guest gu09 visitor dev bin lib sbin null /users/staff/guest/gu09 /dev/null
●●● ●●●● ●●●●● ●●●● ●●●●● File ●●●● Files are identified by their file names, File names are up to 255 character long Hidden files are files with name preceding with dot Each file in UNIX/Linux has its own ownership and permissions which can be shown by listing the directory content in long format(Is-I) owned by a user called morris which is a staff of the Dean's Office ied on 19/09/97. It is The following show a file, stafflist, 34 bytes in size, which last moo .-rw-rw-r--1 morris dean 34 Sep 19 1997 stafflist The ownership can be changed by the command chown and chgrp chown cwyeung stafflist; chgrp math stf stafflist The first field in the above example represents the permission bits of the files The first column shows its kind, d represent a directory represent a regular file The rest can be divided into 3 groups showing its user permission, group permission and other permission respectively Each group can have read(r), write(w) and/or executable(x) permission bits A-'deny the corresponding permission of the file Refer to the last example, stafflist is a regular file which can be updated w-in user bit and group bit) by morris and dean staff. It can be read by other users(r--in other bit). Unfortunately, the file cannot e executed by any body since a -is found in each executable bit. One can change the permission bit by using chmod, two methods can be used use u,g,o, a flag with +, -to add or delete their permission chmod g-w, o-r stafilist-deny rw permission for users in same group -deny r permission for other users chmod atx stafilist-add executable permission to all users Use 3 octal numbers calculated using 4 for T', 2 for w and 1 for X chmod 700 staffist-same effect as the above Use is -l to check the result
File ⚫ Files are identified by their file names, File names are up to 255 character long. ⚫ Hidden files are files with name preceding with dot (.). ⚫ Each file in UNIX/Linux has its own ownership and permissions which can be shown by listing the directory content in long format (ls -l). ⚫ The following show a file, stafflist, 34 bytes in size, which last modified on 19/09/97. It is owned by a user called morris which is a staff of the Dean's Office. ⚫ -rw-rw-r-- 1 morris dean 34 Sep 19 1997 stafflist ⚫ The ownership can be changed by the command chown and chgrp, ⚫ chown cwyeung stafflist; chgrp math_stf stafflist ⚫ The first field in the above example represents the permission bits of the files. ⚫ The first column shows its kind, `d' represent a directory, ⚫ `-' represent a regular file. ⚫ The rest can be divided into 3 groups showing its user permission, group permission and other permission respectively. Each group can have read (r), write (w) and/or executable(x) permission bits. ⚫ A `-' deny the corresponding permission of the file. ⚫ Refer to the last example, stafflist is a regular file which can be updated (rw- in user bit and group bit) by morris and dean staff. It can be read by other users (r-- in other bit). Unfortunately, the file cannot be executed by any body since a `-' is found in each executable bit. ⚫ One can change the permission bit by using chmod, two methods can be used. ⚫ use u,g,o,a flag with +, - to add or delete their permission ⚫ chmod g-rw,o-r stafflist - deny rw permission for users in same group - deny r permission for other users ⚫ chmod a+x stafflist - add executable permission to all users ⚫ Use 3 octal numbers calculated using 4 for `r', 2 for `w' and 1 for `x' ⚫ chmod 700 stafflist - same effect as the above ⚫ Use ls -l to check the result
●●● ●●●● ●●●●● ●●●● ●●●●● Path ●●●● To locate a file, one should use the absolute path or relative path Absolute path is the path describe starting from root( /users/staff/guest/gu01/sampledir/sample. txt Relative path is the path describe from the current working directory() sampledir/sample. txt refer to the same file when gu01's current working directory is /users/staff/guest/gu01 Use pwd to find the current working directory. In path definition Current directory can be described by Parent directory can be described by Home directory can be described by * or the environmental variable SHOME
Path ⚫ To locate a file, one should use the absolute path or relative path. ⚫ Absolute path is the path describe starting from root (/). ⚫ /users/staff/guest/gu01/sampledir/sample.txt ⚫ Relative path is the path describe from the current working directory(.). ⚫ sampledir/sample.txt refer to the same file when gu01's current working directory is /users/staff/guest/gu01. ⚫ Use pwd to find the current working directory. ⚫ In path definition, ⚫ Current directory can be described by `.'. ⚫ Parent directory can be described by `..'. ⚫ Home directory can be described by `~' or the environmental variable '$HOME
●●● ●●●● ●●●●● ●●●● ●●●●● Linux shell environment ●●●● Shell is the front end for users to interact with the linux kernel Commands can be typed in from the shell prompt to do file manipulation ● file copying, renaming and deleting start an text editor or compile and run a program, Different shells can be found in linux. the most common shells are Bourne Again Shell(bash), Bourne(sh, old and standard) Korn(ksh, the default) C(csh, C like command)shell These shell support both foreground and background processes, pipes, filters and other standard features in Linux. Besides handling Linux commands, these shells support the executions of batch files called shell scripts The default shell prompt for the bourne again, bourne and Korn shells are s and that for the c shell is (%) a typical command line have the following syntax command [-options] argl arg2 arg3 where argl, arg2, arg 3, etc are argument input based on the nature of the commands Built-in command are interpreted directly If the command contains a path, the shell will only search for the command in the path If no path is declared, the shell will find in the search path ($ PATh) for the command
Linux shell environment ⚫ Shell is the front end for users to interact with the Linux kernel. ⚫ Commands can be typed in from the shell prompt to do file manipulation ⚫ file copying, ⚫ renaming and deleting, ⚫ start an text editor or ⚫ compile and run a program, etc. ⚫ Different shells can be found in Linux. The most common shells are ⚫ Bourne Again Shell (bash), Bourne (sh, old and standard), ⚫ Korn (ksh, the default), ⚫ C (csh, C like command) shell. ⚫ These shell support both foreground and background processes, pipes, filters and other standard features in Linux. Besides handling Linux commands, these shells support the executions of batch files called shell scripts. ⚫ The default shell prompt for the Bourne again, Bourne and Korn shells are ($) and that for the C shell is (%). ⚫ A typical command line have the following syntax, ⚫ command [-options] arg1 arg2 arg3 ... where arg1, arg2, arg3, etc. are argument input based on the nature of the commands. ⚫ Built-in command are interpreted directly. ⚫ If the command contains a path, the shell will only search for the command in the path. ⚫ If no path is declared, the shell will find in the search path ($PATH) for the command