Unix tutor

一,Concept(概念)

1, The UNIX operating system is made up of three parts; the kernel, the shell and the programs.

(Unix操作系统由三部分构成:内核,shell,程序)

2, Everything in UNIX is either a file or a process.(Unix非文件即进程)

A process is an executing program identified by a unique PID (process identifier).

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

二,文件目录结构

1,The Directory Structure

Unix tutor_第1张图片
unix-tree.png

三,基本命令

1, command tips

% ls unixstuff (在父目录下列出子目录下文件)

% ls unixstuff/backups (在父目录下列出父目录下文件)

**~ **(home 目录)
**. ** (当前目录)
.. (父级目录)

% clear (clear screen)

% cat 输出文件中的内容到当前屏幕 eg, cat mytext.txt

% less 分页输出当前文件中的内容
q:退出
h:显示帮助
空格:下一页
b:上一页
g:到第一行
G:到结尾

% head mytext.txt (默认输出文本的前10行内容)
% -5 head mytext.txt (输出文本的前5行内容)

% tail mytext.txt (默认输出文本的后10行内容)

四,how to search(如何检索)

1, 搜索文本中的关键字

      % less mytext.txt
      % /text

2, grep

     % grep mytext mytext.txt  (检索文件中的关键字)
     % grep -i science science.txt  (检索文件中的关键字,忽略大小写)
     % grep -i 'spinning top' science.txt (检索文件中的字符串,忽略大小写)

     其他命令:
     **-i ** To ignore upper/lower case distinctions
     **-v **display those lines that do NOT match  (展示不匹配的内容)
     **-n** precede each matching line with the line number  (展示出匹配的行号)
     **-c **print only the total count of matched lines  (打印出匹配的总行数)

     这几个命令可以组合,例如 % grep -ivc mytext mytext.txt

      Note:当过滤数字时,需要这么搜索  '10'

3, 计数

       % wc -w mytext.txt (总词数)
       % wc -l mytext.txt (总行数)

4,模糊搜索

 *代表多个省略 eg, % ls *text*
?代表一个省略

5,获得命令的帮助

 % man ls    (获取ls命令的解释)
 % whatis ls (获取ls命令的解释,简洁的显示一行)

% apropos copy (获取相关功能,例如copy的相关命令)

8,文件信息
Each file (and directory) has associated access rights, which may be found by typing ls -l. Also, ls -lg gives additional information as to which group owns the file (beng95 in the following example):

-rwxrw-r-- 1 ee51ab beng95 2450 Sept29 11:52 file1

Unix tutor_第2张图片
unix_file_info.gif

In the left-hand column is a 10 symbol string consisting of the symbols d, r, w, x, -, and, occasionally, s or S. If d is present, it will be at the left hand end of the string, and indicates a directory: otherwise - will be the starting symbol of the string. (第一个字母如果是d,代表这是个文件夹)

The 9 remaining symbols indicate the permissions, or access rights, and are taken as three groups of 3.(接下来以三个字符为一组,共三组)

The left group of 3 gives the file permissions for the user that owns the file (or directory) (ee51ab in the above example); (第一组代表文件所有人的权限)

the middle group gives the permissions for the group of people to whom the file (or directory) belongs (eebeng95 in the above example);(第二组代表文件所在群组的权限)
the rightmost group gives the permissions for all others. (第三组标示其他人的权限)

The symbols r, w, etc., have slightly different meanings depending on whether they refer to a simple file or to a directory.

Unix tutor_第3张图片
Paste_Image.png

修改文件的权限 % chmod go-rwx biglist

9,关于进程
A process is an executing program identified by a unique PID (process identifier)
(一个进程就是被唯一进程标识器标识的正在执行的程序)

9-1 % ps (查看当前进程状态)

9-2 % jobs (查看当前挂起或者正在执行中的任务)

9-3 杀进程有两种方式:
kill job kill %jobid
kill process kill pid

10,unix变量 (作用的范围不同)
环境变量 % env
shell变量 % set

你可能感兴趣的:(Unix tutor)