UNIX study note(step1)

Source: UNIX Tutorial for Beginners http://www.ee.surrey.ac.uk/Teaching/Unix/

 

Key Point:  Don't let go...

Useful source collection for linuxLearning :http://linux.cn/article-2890-1.html

Kernel

Kernel is the hub of the operating system: itallocates time and memory to programs and handles thefilestore and communications in response tosystem calls.

 

Shell

The shell acts as an interface between theuser and the kernel. When a user logs in, the login program checks the username andpassword, and then starts another program called the shell.

The shell is a command line interpreter(CLI). Itinterprets the commands the user types in and arranges for them to be carriedout.

bash, etc.

 

files and processes

Everything in UNIX is either a file or aprocess.

A process is an executing programidentified by auniquePID (processidentifier).

A file is a collection of data. They are created by usersusing text editors, running compilers etc.

Examples of files: document,directory etc.

 

The directory Structure

       The directory structure groupsall the files together.

The file-system is arranged in ahierarchical structure, like an inverted tree. The top of the hierarchy istraditionally calledroot.

 

Basic Operation Command

 ls(list)

The ls command ( lowercase L andlowercase S ) lists the contents of your current working directory.

mkdir

Themakdir command will make a subdirectory in your current directory.

cd

The commandcddirectorymeans change the current working directory todirectory.

 The directory .& .. & ~

In UNIX, (.)means the current directory

And (..) means the parent of current directory

And (~) means the parentof currentdirectory

pwd

Thecommand pwd will print working directory.

 

Command

Meaning

ls

list files and directories

ls -a

list all files and directories

mkdir

make a directory

cd directory

change to named directory

cd

change to home-directory

cd ~

change to home-directory

cd ..

change to parent directory

pwd

display the path of the current directory

 

 

cp

cpfile1 file2is the command which makes a copy of file1in thecurrent working directory and calls it file2.

mv

mv file1 file2 moves (or renames) file1 to file2

rm & rmdir

To delete (remove) a file, use the rm command.

You can use the rmdircommand to remove a directory (make sure it is empty first).

clear

Thiscmd will clearthe terminal window of the previous commands.

cat

The command cat can be used to displaythe contents of a file on the screen.

less & head & tail

The command less writes the contents ofa file onto the screen a page at a time.

The headcommand writes the first ten lines of afile to the screen.

The tailcommand writes the last ten lines of afile to the screen.

grep

grep is one of many standard UNIX utilities. It searches files forspecified words or patterns.

-vdisplay those lines that do NOT match

-n precede each matching linewith the line number

-iignore case distinctions.

wc

A handy little utility is the wccommand, short for word count.

who  

List users currently logged in.

  

Command

Meaning

cpfile1 file2

copy file1 and call it file2

mvfile1 file2

move or rename file1 to file2

rmfile

remove a file

rmdirdirectory

remove a directory

catfile

display a file

lessfile

display a file a page at a time

headfile

display the first few lines of a file

tailfile

display the last few lines of a file

grep'keyword' file

search a file for keywords

wc file

count number of lines/words/characters in file

who

List users currently logged in

 

Redirection

Redirection:

standard output:the terminal screen

      standard input: the keyboard

standard error:processes error messages, terminal screen(by default)

Redirecting the Output:

      use the > symbol toredirect the output of a command.

The form >> appends standardoutput to a file.

Redirecting the Input:

      use the < symbol toredirect the input of a command.Using < you can redirect the input to come from a filerather than the keyboard.

Pipes:

      The symbol for a pipe is the vertical bar|’. The output of cmd1ispiped tobe the input of cmd.

 

Wildcards

*: The character*is called a wildcard, and will match againstnone or more character(s) in a file (or directory)name.

?: The character?will match exactly onecharacter.

 

File system security

Each file (and directory) has associatedaccess rights, which may be found by typingls -l.Also,ls –lggives additional information as to which group owns the file

Access rights on files:

r (or -), indicates read permission. thatis, the presence or absence of permission to read and copy the file

w (or -), indicates write permission. thatis, the permission (or otherwise) to change a file

x (or -), indicates execution permission,that is, the permission to execute a file.

 

Accessrights on directories:

r allows users to list files in the directory

w means that users may delete files from thedirectory or move files into it

x means the right to access files in thedirectory. This implies that you may read files in the directory provided youhave read permission on the individual files.

 

Changing accessrights

      Only the owner of a file can use chmod to change thepermissions of a file. The options of chmod are as follows:

Symbol

Meaning

u

user

g

group

o

other

a

all

r

read

w

write (and delete)

x

execute (and access directory)

+

add permission

-

take away permission

 

Processes and Jobs

A process may bein the foreground, in thebackground, or be suspended.

ps cmd

To background a process, type an&at the end of the commandline.(sleep 10&)

bg :To restart (foreground) asuspended processes

fg:resume a job in the foreground, and make it the current job.

 ^Z: (control+ Z)suspend the job running in the foreground

 

Killing a process

To kill a job running in theforeground, type^C(control c).

To kill a suspended or background process,(kill%jobnumber)or(kill PID)

Note:It is not possible to kill off other users' processes !!!

 

Other useful UNIX commands

df

Thedfcommand reports on the spaceleft on the file system.

du

Theducommand outputs the number of kilobyes used by eachsubdirectory.

gzip

This reduces the size of a file, thusfreeing valuable disk space.

%gzip science.txt

This will compress the file and place itin a file calledscience.txt.gz

To expand the file, use thegunzipcommand.

zcat

zcatwill read gzipped fileswithout needing to uncompress them first.

%zcat science.txt.gz

 file

fileclassifies the named filesaccording to the type of data they contain, for example ascii (text), pictures,compressed data, etc.

diff

This command compares the contents oftwo files and displays the differences. Suppose you have a file calledfile1and you edit some part of itand save it asfile2.

To see the differences type: % difffile1 file2

find

This searches through the directoriesfor files and directorieswith a given name, date, size, or any other attribute youcare to specify. It is a simple command but with many options.

history

The C shell keeps an ordered list of allthe commands that you have entered. Each command is given a number according tothe order it was entered.

If you are using the C shell, you canuse the exclamation character (!)(!!,!3, !grep) torecall commands easily.

 

 

Compiling UNIX software packages

Thereare a number of steps needed to install the software:

  • Locate and download the source code (which is usually compressed)
  • Unpack the source code
  • Compile the code
  • Install the resulting executable
  • Set paths to the installation directory

make andthe Makefile:

      Themakecommand allows programmers to manage large programs or groupsof programs.

Themakeprogram gets its set of compile rules from a text file calledMakefilewhich resides in the same directory as the source files.

 

configure:

The simplest way to compile a package is:

  1. cd to the directory containing the package's source code.
  2. Type ./configure to configure the package for your system.
  3. Type make to compile the package.
  4. Optionally, type make check to run any self-tests that come with the package.
  5. Type make install to install the programs and any data files and documentation.
  6. Optionally, type make clean to remove the program binaries and object files from the source code director

 

UNIX Variables

Environment variables:

Environment variables have a farther reaching significance,and those set at login are valid for the duration of the session.

% echo $PATH

ENVIRONMENT variables are set using thesetenvcommand, displayed using theprintenvorenvcommands, and unset using theunsetenvcommand.

% printenv | less

 

Shell variables:

In broad terms, shell variables applyonly to the current instance of the shell and are used to set short-termworking conditions;

% echo $history

SHELL variables are both set anddisplayed using the set command. They can be unset by using theunset command.

      % set | less

Settingvariables:

      Each time you login to a UNIX host, the system looks in yourhome directory for initialisation files. “.cshrcor .bashrc”

Other notification:

Filename convention:

In naming files, characters with specialmeanings such as/ * %& space, should be avoided. The safest way to name a file is to useonly alphanumeric characters.

 

Helps:

On-lineManuals:

      man, whatis

Apropos:

      When you are not sure of the exact name of a command, you can use ‘propos (keyword)’.



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值