<<

School of Information Technology, Illinois State University, Basic Commands

Basic Commands Change the password man xxxx Get on-line for xxxx List of all files in the current directory in short format ls -l List of all files in the current directory in long format xxxx a new sub directory xxxx xxxx Remove an empty directory xxxx -r xxxx Remove a directory xxxx xxxx Change the current directory to sub directory xxxx cd .. Change the current directory to the parent directory cd ∼ Change the current directory to the home directory file1 file2 Copy file1 to file2 cp xxxx Copy file into a sub directory xxxx cp -r dir1 dir2 Copy directory dir1 to directory dir2 file1 file2 Move (rename) file1 to file2 mv file xxxx Copy file into sub directory xxxx rm file Remove file 754 file Change the permission of file - rwx r-x r-- 754 means 7=1112 (you) 5=1012 (group) 4=1002 (others) chmod -+r file Change file to not-writable but readable to yourself chmod g-w+r file Change file to not-writable but readable to the group chmod o-w-r file Change file to not-writable and not-readable to others file List the contents of file file List the contents of file, one screen a file List the first 20 lines of file on the screen file List the last 20 lines of file on the screen file1 file2 List the differences between the two files file List every line of file in alphabetic order sort -n file List every line of file in numerical order file Show the numbers of lines, words, and characters in file wc -l file Show the numbers of lines in file wc -w file Show the numbers of words in file wc -m file Show the numbers characters in file lpr Show available printers lpr file Print file to the default printer compress file Compress file into file.Z uncompress file.Z Restore the compressed file file.Z back to file List the history of issued commands history 10 List the recent 10 history of issued commands !! execute the previous command in the history !65 execute the 65th command in the history !-n execute the nth command form the end of the history !text execute the previous command starting with text !!text execute the previous command with the new argument text Piping ls | more Pipe the output of ls as the input of more ls -l | lpr Pipe the output of ls -l as the input of lpr

c Chung-Chih Li P-1/2 School of Information Technology, Illinois State University, Basic Unix Commands

Redirecting output man ls > file Direct the output of man ls to file -d ’\015’ < file1 > file2 delete ’\015’ from file1 and save it to file2 ls -l > file Direct the output of ls -l to file sort file1 > file1 Direct the output of sort file1 to file2 More on chmod The general syntax of chmod is as follows: prompt% chmod [option] permissions fileDir An option parameter means that you don’t have to provide any if you don’t want to. We only consider the option, -R, means that chmod will recursively apply the permission setup to all subdirectories and its files below fileDir Permissions could be in one of the following formats: (1) Octal numeric format, e.g., 0255 or 255. (2) Text format like a+r, u=rwx", or o-w. You can use several comma separated text form permissions. We have the following parameters for the permission: Three types of permissions r sets the read permission. w sets permission. x sets execute permission.

Who receive the permissions u sets permissions for the owner. g sets permissions for the group. o sets permissions for other users. a sets permissions for all (owner, group and others).

Set permissions = assigns permissions, e.g. ”a=rw”, sets read and write permissions and disables execution for all. - remove permissions, e.g. ”a-x” disables (remove) execution permission from everyone; read and write permission will remain unchanged. + add permissions, e.g. ”a+x” add execution permission to everyone; read and write permission will remain unchanged.

More examples prompt% chmod 755 hello.java prompt% chmod u=rwx,g=rx,o=rx hello.java prompt% chmod u=rwx,go=rx hello.java prompt% chmod u+rwx,g+rx,g-w,o+rx,o-w hello.java prompt% chmod u+rwx,go+rx,go-w hello.java

c Chung-Chih Li P-2/2