[Unix] Basics from www.asic-world.com Sesson 1

Posted on Updated on

To note: all the information is distilled from http://www.asic-world.com, which is a very helpful website for whoever newbies or oldbies;).

3 main components: kernel, shell, utility programs(or commands)

Most commonly available shells:

  • Bourne shell (sh)
  • C shell (csh)
  • Korn shell (ksh)
  • TC shell (tcsh)
  • Bourne Again shell (bash)

Special Characters:

Character

Description

NEWLINE

initiates command execution

;

separates commands on same line

( )

groups commands or identifies a function

&

executes a command in the background

|

pipe

>

redirects standard output

>>

appends standard output

<

redirects standard input

*

wildcard for any number of characters in a file name

?

wildcard for a single character in a file name

\

quotes the following character

quotes a string preventing all substitutions

quotes a string allowing variable and command substitution

`

performs command substitution

[ ]

denotes a character class in a file name

$

references a variable

{ }

command grouping within a function

.

executes a command (if at beginning of line)

#

begins a comment

Control Keys:

Keys

Description

CTRL-u

erase everything you’ve typed on the command line

CTRL-c

stop/kill a command

CTRL-h

backspace (usually)

CTRL-z

suspend a command

CTRL-s

stop the screen from scrolling

CTRL-q

continue scrolling

CTRL-d

exit from an interactive program (signals end of data)

File System:

Directory

Typical Contents

/

The “root” directory

/bin

Essential low-level system utilities

/usr/bin

Higher-level system utilities and application programs

/sbin

Superuser system utilities (for performing system administration tasks)

/lib

Program libraries (collections of system calls that can be included in programs by a compiler) for low-level system utilities

/usr/lib

Program libraries for higher-level user programs

/tmp

Temporary file storage space (can be used by any user)

/home or /homes

User home directories containing personal file space for each user. Each directory is named after the login of the user.

/etc

UNIX system configuration and information files

/dev

Hardware devices

/proc

A pseudo-filesystem which is used as an interface to the kernel. Includes a sub-directory for each active program (or process).

../images/scripting/unix_file_details.gif

Field

Description

type

type is a single character which is either ‘d’ (directory), ‘-‘ (ordinary file), ‘l’ (symbolic link), ‘b’ (block-oriented device) or ‘c’ (character-oriented device).

permission

permissions is a set of characters describing access rights. There are 9 permission characters, describing 3 access types given to 3 user categories. The three access types are read (‘r’), write (‘w’) and execute (‘x’), and the three users categories are the user who owns the file, users in the group that the file belongs to and other users (the general public). An ‘r’, ‘w’ or ‘x’ character means the corresponding permission is present; a ‘-‘ means it is absent.

links

links refers to the number of filesystem links pointing to the file/directory (see the discussion on hard/soft links in the next section).

owner

owner is usually the user who created the file or directory.

group

group denotes a collection of users who are allowed to access the file according to the group access rights specified in the permissions field.

size

size is the length of a file, or the number of bytes used by the operating system to store the list of files in a directory.

date

date is the date when the file or directory was last modified (written to). The -u option display the time when the file was last accessed (read).

name

name is the name of the file or directory.

Command makeup:

info(man)

ls -l | more //make the list longer than one page

chmod permission-traids filename //change access permissions

u = user, g = group, o = other, a = all

+/- = add/remove

r/4 = read, w/2 = write, x/1 = execute (e.g. rwx is 7, rw- is 6)

Specifying multiple filenames:

  • [m-z]*[a-l] matches any filename that begins with a letter from ‘m’ to ‘z’ and ends in a letter from ‘a’ to ‘l’.
  • {/usr,}{/bin,/lib}/file expands to /usr/bin/file /usr/lib/file /bin/file and /lib/file.

Quotes (one type of characters):

  • Try insert a ‘\’ in front of the special character.
  • Use double quotes (“) around arguments to prevent most expansions.
  • Use single forward quotes (‘) around arguments to prevent all expansions.
  • (`) pass the output of one command as the input to another command, e.g.

$ hostname

asic-world

$ echo this machine is called `hostname`

this machine is called asic-world

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s