UNIX, LINUX SURVIVAL GUIDE

Unix Tutorial




Unix Tutorial

A Survival Guide By Shi Qiao Yu Copyright © November, 2001

Unix Tutorial

TABLE OF CONTENT

ACCOUNTS..........................................................................4 FILE SYSTEM.......................................................................4 SHELLS............................................................................4 BASIC FILE COMMANDS...............................................................5 ls cd mkdir cp mv rmdir rm FILE PERMISSION...................................................................8 chmod umask DIRECTORY PERMISSION..............................................................10 EXECUTABLE PERMISSION.............................................................10 USEFUL FEATURES...................................................................11 tab filenames with spaces up and down cursor arrows MAN PAGES.........................................................................12 man PIPELINING........................................................................13 more, less grep SYMBOLIC LINKS....................................................................14 LOCAL CONFIGURATION FILES.........................................................15 source USING ALIAS.......................................................................16 alias unalias PROMPT SHELL......................................................................17 USER ACCOUNT MANAGEMENT...........................................................18 du quota FILE ARCHIVES.....................................................................19 tar gzip gunzip zip unzip USER COMMANDS.....................................................................21 finger w passwd Unix Tutorial: A Survival Guide 2 Shi Qiao Yu © 2001

TABLE OF CONTENT

OTHER COMMANDS...................................................................23

echo history cal clear ifconfig whereis talk PROCESS MANAGEMENT...............................................................24 ps kill & fg % REGULAR EXPRESSIONS..............................................................25 ENVIRONMENT VARIABLES............................................................25 printenv $PATH $home $host uname LOGIN INTO YOUR ACCOUNT..........................................................26 rlogin ssh telnet ftp TEXT EDITORS.....................................................................31 pico vi emacs xemacs EMAIL READER.....................................................................31 pine WEB BROWSER......................................................................32 lynx FILE MANAGERS....................................................................32 pilot lynx EMAIL FORWARDING.................................................................33 ALCOR ACCOUNT....................................................................33 tom CS ACCOUNT.......................................................................34 mh ECE LABS.........................................................................35 How do I load a wallpaper at startup? How do I access my floppy disk? How can I exchange files with my team mates? What are the commands for printing? Using NetTerm to telnet to accounts How to open X-Window System programs from home Unix Tutorial: A Survival Guide 3 Shi Qiao Yu © 2001

OTHER COMMANDS...................................................................23

Unix Tutorial

A Survival Guide by Shi Qiao Yu Copyright © 2001 sq_yu@ieee.org This guide is intended to give Concordia students practical knowledge on how to use efficiently the Unix systems at school. The latest update to this guide is November 2001. ACCOUNTS This guide only refers to the Alcor, ECE and CS Unix systems. Every student can have an Alcor account. To apply for one, go to H-925. The ECE account is available to Electrical and Computer engineering students and to anyone else taking a COEN or ELEC course that uses the ECE account. The ECE account is given in H-907-2. The CS account is available to Computer Science and Software engineering students and anyone else taking a course that requires the CS account. The CS account is given at H-925 at the same time that you get your Alcor account. FILE SYSTEM The root, represented by /, is the highest directory level. Each directory has a '.' and a '..' file. The '.' represent the current directory. The '..' represent the parent directory. For those who have used MS-DOS or MS-Windows, the root can be regarded as the "c: drive". This is a very blunt comparison. In Unix, the whole file system can be scattered across several hard disks and network. Although the system does recognize each hard disks and the size of each partition, from the user’s point of view, it seems like it’s all inside one big hard disk. The Unix system is case sensitive. This means that every upper case letters and every lower case letters must be written properly. For example, if a command is written as 'Bye' and you want to run that command, then you must write 'Bye' but not 'bye' or 'byE' or 'bYe’. SHELLS The Alcor system uses the Bash shell. The ECE and CS systems use the C-shell. Shells define the environment of the command-line prompt. They dictate how commands can be entered and which syntax is to be used. The Bash shell is said to be the more user-friendly shell. The C-shell is said to provide a better programming environment. Each Unix system at Concordia is managed differently. A command that works in one system may not work the same way in another or even exist at all. One should be aware of these differences when experimenting in different accounts. Unix Tutorial: A Survival Guide 4 Shi Qiao Yu © 2001

Unix Tutorial

BASIC FILE COMMANDS

ls Lists the files in your directory. > ls –alF drwx-----dr-xr-xr-x drwx-----drwxr-xr-x -rw-------rw-------rw-------rw-------rw------drwx-----drwxr-xr-x drwx------ 32 15 2 2 1 1 1 1 1 2 3 2 sq_yu root sq_yu sq_yu sq_yu sq_yu sq_yu sq_yu sq_yu sq_yu sq_yu sq_yu beng root beng beng beng beng beng beng beng beng beng beng 3072 15 512 512 2261 5598 1885 45 3642 512 512 512 Oct 6 18:00 ./ Oct 6 22:48 ../ Apr 4 2000 .AbiSuite/ Dec 9 1999 .Tgif/ Oct 6 15:27 .Xauthority Oct 28 1998 .Xdefaults Apr 7 2000 .acrorc Oct 5 11:01 .cshrc Feb 18 2000 coen412lab2 Sep 29 17:11 coen417/ Oct 6 11:45 comp346/ Oct 6 23:39 tmp/ The 'a' parameter stands for all and is used to show hidden files as well. Hidden files under the Unix convention are files that starts with a dot, such as .AbiSuite. The 'l' stands for long format; it will show file permission, owner name, size, etc. The 'F' is used to identify the type of file: a directory name will end with a /, an executable file will end with * and a symbolic link will end with @. > ls –alFR tmp tmp: total 7 drwx-----drwx------rw-r--r-drwxr-xr-x drwxr-xr-x 4 32 1 2 2 sq_yu sq_yu sq_yu sq_yu sq_yu beng beng beng beng beng 512 3072 4 512 512 Oct Oct Oct Oct Oct 7 7 6 7 7 00:41 00:08 23:39 00:41 00:41 ./ ../ Keith_Richards Who.s.That/ Dunno_go_ask_Ted/ tmp/dsa: total 3 drwxr-xr-x drwx------rw-r--r-- 2 sq_yu 4 sq_yu 1 sq_yu beng beng beng 512 Oct 512 Oct 4 Oct 7 00:41 ./ 7 00:41 ../ 7 00:41 iop tmp/gfd: total 2 drwxr-xr-x drwx------ 2 sq_yu 4 sq_yu beng beng 512 Oct 512 Oct 7 00:41 ./ 7 00:41 ../ The 'R' is used to recursively list the content inside the 'tmp' directory and all of its sub-directories. cd Change to directory > cd tmp Change to 'tmp' directory inside your current directory. Unix Tutorial: A Survival Guide 5 Shi Qiao Yu © 2001

BASIC FILE COMMANDS

> cd /tmp

Change to 'tmp' directory in the root directory. Putting a / in front of the directory name means that you are accessing a directory starting from the root / directory. This is referred to as an absolute pathname. Without the / in front of the directory, such as in the first example, you are accessing a directory name starting from the current directory. This is referred to as a relative pathname. > cd .. Change to the parent (previous) directory. > cd Change to your home directory. mkdir Create a directory. > mkdir coen311 cp Copy files. > cp lab1.txt lab1.copy Make a duplicate of lab1.txt called lab1.copy. mv Move files to directory or rename files. > mv lab1.txt lab1a.txt Rename file. > mv –f *.txt elec361 Move all .txt files to elec361 directory, overwriting files of the same name. The 'f' stands for 'force’. rmdir Remove empty directory. Directories can only be removed with this command. Only empty directories can be removed. > rmdir tmp rmdir: tmp: File exists This warns that the directory tmp is not empty. The directory must be emptied before it can be removed. Unix Tutorial: A Survival Guide 6 Shi Qiao Yu © 2001

> cd /tmp

rm

Remove files. In Unix, files that are deleted CANNOT be undeleted afterwards! There exists no utility to help you recover the files! > rm –i * rm: remove the_c_ess_u? y rm: remove my_pants.txt? y Prompts you before deleting a file. Press 'y' for yes and 'n' for no. The 'i' stands for 'interactive’. > rm coen412/ rm: coen412/ directory Failed attempt directories. to delete a directory. Only rmdir can be used to delete > rm –rf * Recursively remove all files and sub-directories in your current directory, without prompting to delete files. Be careful when using this command! People have been known to have deleted all their files in their home directory by accident using this command! Examples: > ls –alF drwx-----drwx--x--x -rw-------rw-------rw------- 2 11 1 1 1 sq_yu sq_yu sq_yu sq_yu sq_yu students students students students students 8192 8192 4 3 5 Oct Oct Oct Oct Oct 2 sq_yu 11 sq_yu 1 sq_yu students students students 8192 Oct 8192 Oct 4 Oct 7 6 7 7 7 00:13 23:55 00:13 00:13 00:13 ./ ../ .dsa dsa dsa.dsa > rm * > ls –alF drwx-----drwx--x--x -rw------- 7 00:14 ./ 6 23:55 ../ 7 00:13 .dsa > rm *.* rm: *.*: No such file or directory > rm .* rm: cannot remove '.' or '..' rm: cannot remove '.' or '..' > ls –alF > Unix Tutorial: A Survival Guide 7 Shi Qiao Yu © 2001

rm

This example illustrates how 3 different files can be deleted. The .dsa file

has no prefix ( no name before the dot ), the dsa file has no suffix ( no name after the dot ) and the dsa.dsa has both suffix and prefix. The first attempt to delete is to use rm * . Both dsa and dsa.dsa were removed but not .dsa. The second attempt is to use rm *.*. This doesn’t work. Lastly, rm .* is used to successfully delete the .dsa file. > ls –alF drwx-----drwx--x--x -rw------- 2 sq_yu 11 sq_yu 1 sq_yu students students students 8192 Oct 8192 Oct 3 Oct 7 00:13 ./ 6 23:55 ../ 7 00:13 dsa > rm *.* rm: *.*: No such file or directory Note that attempting to delete the dsa file with rm *.* will also fail. FILE PERMISSION Unix being a multi-user system, it allows files to be accessed by some users and to be refused by others. -rw-r--r-- 1 sq_yu beng drwxrwxrwx 5 sq_yu beng lrwxrwxrwx 1 sq_yu students file directory symbolic link ----x -w-wx r-r-x rwrwx 000 001 010 011 100 101 110 111 0 1 2 3 4 5 6 7 type d l user rwx rwx rwx 1031 Sep 1 18:14 typescript 512 Nov 16 group rwx rwx rwx 24 Jul 10 1999 synopsys_cache_1998.08-1/ 1999 www@ -> /public/home/ugrad/sq_yu/ other rwx rwx rwx no permission execute permission write permission write and execute permission read permission read and execute permission read and write permission read, write and execute permission The user field is the set of file permissions granted to the owner of the file. The group field sets the file permissions given to people of the same group. Only the system administrator can decide which group the user belongs to. The other field determines the file permissions for all users. A read permission enables you to read the content of the file but not modify it. A write permission enables you to modify and delete a file. An execute permission enables you to run the file as a program. Unix Tutorial: A Survival Guide 8 Shi Qiao Yu © 2001

This example illustrates how 3 different files can be deleted. The .dsa file

chmod

Change the file permission. There are two syntaxes that can be used: -rw------- 1 sq_yu students 580456 Oct 7 00:26 Cubic_Player.exe 580456 Oct 7 00:26 Cubic_Player.exe > chmod go+r notes.txt -rw-r--r-- u user 1 sq_yu g group students o other a user+group+other A + means to give permission, a – means to remove permission. In the example above, the file notes.txt has been given read permission for group and others. The user field has been left unchanged. The other syntax form is: > chmod 644 notes.txt user rw110 6 group r-100 4 other r-100 4 The 644 is the binary representation of rw-r--r-- . All permission fields, including the user field must be set as well. Refer to the file permission table in FILE PERMISSION for a list of all the binary representations used. umask This is the command that sets the default file permissions of freshly created files. umask 177 This gives read and write permission for user and no permission for group and others. The bit settings are the complement (opposite) of the bit settings used by chmod. ----x -w-wx r-r-x rwrwx chmod 000 001 010 011 100 101 110 111 0 1 2 3 4 5 6 7 umask 7 6 5 4 3 2 1 0 This should be placed or is already placed in the local configuration file (see LOCAL CONFIGURATION FILES). Unix Tutorial: A Survival Guide 9 Shi Qiao Yu © 2001

chmod



Flipbook Gallery

Magazines Gallery

Catalogs Gallery

Reports Gallery

Flyers Gallery

Portfolios Gallery

Art Gallery

Home


Fleepit Digital © 2021