unix环境编程笔记:第二章:文件系统

 

一、文件系统的基础:

1. ed 命令: 行编辑命令。

2. cat 命令: 显示文件内容的命令

3. od命令: 八进制显示文件内容: 选项 -c -b -x

4. stty 命令: 终端设置命令, 选项 -tabs

5. 命令cat 与 cat -u的区别

6. 终端输入结束命令和退出终端命令:ctrl+d

7.file命令:查看文件的类型。

8. sort命令:排序命令。

9.  wc 命令,统计文件的字符数、行数(-l)

10. cp命令: copy

11. cmp命令: compare files content

12. grep 命令: filter

 


二、文件目录和文件名

1. ls命令:

2. pwd命令:

3. mkdir命令:

4. cd 命令:

5. du命令: du (disc usage) 磁盘使用情况

  du -a    du -h du -ah | grep filename

6. . :当前目录 。 .. :父目录。

7. find命令: find / -name filename == du -a | grep filename

 


三、文件的权限

1. super-user : root  777

2. crypt: 加密命令。

3. login-id: uid:user-id 一个整数;group-id 也是一个整数

4. /etc/passwd: 记录用户信息的口令文件

5. /etc/shadow: 记录用户加密后的密码文件

wzb56@ubuntu:~/test$ ls -l /usr/bin/passwd
-rwsr-xr-x 1 root root 35944 Dec  8  2008 /usr/bin/passwd

对于文件的所有者而言,在执行域用s代替x,当命令运行时,由文件的所有者赋予其权限。例如passwd命令是个owner是root, passwd命令进行了setuid设置,任何用户都可以运行passwd命令编辑口令文件。

 

set-uid是一个简单但很完美的想法,解决了许多系统安全问题。也具有潜在的危险。

具有set-uid的几个系统程序:

6. who , w, whoami

7. which whereis

8. rm : -R -f

9.  chmod:

10.  chown:

11.  I 节点: 一个文件有几项内容:名称、内容和管理信息、修改时间。 管理信息存放在I节点中,同时,存放的还有一些基本的系统参数:文件的长度,文件在磁盘上的位置等。

I节点中的三个时间:最后一次修改时间(w)、最后一次使用时间(r、x)、以及I节点自身最后一次改变(chmod)。分别用命令: ls -lu junk ; ls -l junk ; ls -lc junk ; ls -lt junk

12. ln命令: 创建link文件

13.mv命令:重命名或移动文件。

14.rcp\scp: 远程复制。(不同linux主机之间对传文件,很有用。)

15. cp  -r

 


四、unix的文件目录结构:

/ : 根文件系统。

/bin :(binaries)二进制文件,可执行的基本程序。

/dev :(devices)设备文件。

/etc: (et cetera)系统的各种配置管理文件。

/etc/passwd : 口令文件。

/etc/shadow: 口令密文文件。

/etc/getty  :  /bin/login初始化的终端连接。

/etc/rc : 系统的初始化shell脚本。

/etc/group: 成员组。

/lib: (library) C编译器的主要部分。

/lib/cpp: c预处理器。

/lib/libc.a: c子例程库。

/tmp: (temporaries) 程序执行过程中创建的临时文件的仓库。

/usr: 用户文件目录。

/usr/bin:

/usr/lib:

/usr/tmp:

 


五、设备文件

1. unix把设备也抽象成为文件,提供了对复杂低级设备的统一操作接口。文件即是字节序列或者bit序列。

    设备文件分为:块设备(b)和字符设备(c)。

    设备文件还有主设备号和从设备号.

    主设备号:区分设备类型。

    从设备号:区分同一设备的不同实例。

    不同的文件系统上I结点是不同的,故不能创建跨文件系统的系统的连接文件用ln。

2. 监控磁盘或文件系统的使用情况的命令有:

   du -ah:(disc usage) 文件系统的磁盘的使用情况。

   df -ah:(disc free space)报告整个文件系统的使用情况。

oggo@ubuntu:~$ du -ah
8.0K    ./.viminfo
4.0K    ./.bash_history
4.0K    ./c/HelloWorld.o
4.0K    ./c/HelloWorld.c
12K     ./c/HelloWorld
4.0K    ./c/makefile
28K     ./c
4.0K    ./oggo
4.0K    ./.vimrc
4.0K    ./wzb/HelloWorld.c
16K     ./wzb/tmp
24K     ./wzb
4.0K    ./.rhosts
12K     ./.makefile.swp
92K     .
oggo@ubuntu:~$ who am i
             oggo     pts/5        Oct  6 09:37 (211.87.235.109)

说明:    user      tty_no       date time      ip

oggo@ubuntu:~$ who | rel="nofollow" grep ogg
oggo     pts/5        Oct  6 09:37 (211.87.235.109)

 

oggo@ubuntu:~$ w
 10:32:53 up  3:20, 11 users,  load average: 0.00, 0.03, 0.07
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
wzb56    pts/4    211.87.235.109   09:29   34:07m  0.08s  0.08s -bash
oggo     pts/5    211.87.235.109   09:37    0.00s  0.08s  0.00s w

 4. last : 查看过去登录用户的信息。

 

5.  产看用户终端的命令:

stty:  设置用户终端。eg: stty -tabs

tty: 产看当前用户的终端设备文件.

oggo@ubuntu:~$ tty
/dev/pts/5
oggo@ubuntu:~$ ls -l /dev/pts/5
crw--w---- 1 oggo tty 136, 5 Oct  6 10:40 /dev/pts/5
用户oggo的虚拟终端号/dev/pts/5:620,write命令使用的就是它。

wzb56@ubuntu on pts/4 at 10:52 ...
hello 1
hehe 0
hehe 1

oggo@ubuntu on pts/5 at 10:52 ...
hello 0
write oggo
hello 1
hehe 0
hehe 1
EOF

需要使用 0,1协议区分用户的消息。ctrl -d 结束对话。


7. 用户登录终端设备的同义词: /dev/tty, 非常实用,而不考录用户实际登录的设备终端。

oggo@ubuntu:~$ grep --help
Usage: grep [OPTION]... PATTERN [FILE]...
Search for PATTERN in each FILE or standard input.
PATTERN is, by default, a basic regular expression (BRE).
Example: grep -i 'hello world' menu.h main.c

Regexp selection and interpretation:
  -E, --extended-regexp     PATTERN is an extended regular expression (ERE)
  -F, --fixed-strings       PATTERN is a set of newline-separated fixed strings
  -G, --basic-regexp        PATTERN is a basic regular expression (BRE)
  -P, --perl-regexp         PATTERN is a Perl regular expression
  -e, --regexp=PATTERN      use PATTERN for matching
  -f, --file=FILE           obtain PATTERN from FILE
  -i, --ignore-case         ignore case distinctions
  -w, --word-regexp         force PATTERN to match only whole words
  -x, --line-regexp         force PATTERN to match only whole lines
  -z, --null-data           a data line ends in 0 byte, not newline

Miscellaneous:
  -s, --no-messages         suppress error messages
  -v, --invert-match        select non-matching lines
  -V, --version             print version information and exit
      --help                display this help and exit
      --mmap                use memory-mapped input if possible

Output control:
  -m, --max-count=NUM       stop after NUM matches
  -b, --byte-offset         print the byte offset with output lines
  -n, --line-number         print line number with output lines
      --line-buffered       flush output on every line
  -H, --with-filename       print the filename for each match
  -h, --no-filename         suppress the prefixing filename on output
      --label=LABEL         print LABEL as filename for standard input
  -o, --only-matching       show only the part of a line matching PATTERN
  -q, --quiet, --silent     suppress all normal output
      --binary-files=TYPE   assume that binary files are TYPE;
                            TYPE is `binary', `text', or `without-match'
  -a, --text                equivalent to --binary-files=text
  -I                        equivalent to --binary-files=without-match
  -d, --directories=ACTION  how to handle directories;
                            ACTION is `read', `recurse', or `skip'
  -D, --devices=ACTION      how to handle devices, FIFOs and sockets;
                            ACTION is `read' or `skip'
  -R, -r, --recursive       equivalent to --directories=recurse
      --include=FILE_PATTERN  search only files that match FILE_PATTERN
      --exclude=FILE_PATTERN  skip files and directories matching FILE_PATTERN
      --exclude-from=FILE   skip files matching any file pattern from FILE
      --exclude-dir=PATTERN directories that match PATTERN will be skipped.
  -L, --files-without-match print only names of FILEs containing no match
  -l, --files-with-matches  print only names of FILEs containing matches
  -c, --count               print only a count of matching lines per FILE
  -T, --initial-tab         make tabs line up (if needed)
  -Z, --null                print 0 byte after FILE name

Context control:
  -B, --before-context=NUM  print NUM lines of leading context
  -A, --after-context=NUM   print NUM lines of trailing context
  -C, --context=NUM         print NUM lines of output context
  -NUM                      same as --context=NUM
      --color[=WHEN],
      --colour[=WHEN]       use markers to highlight the matching strings;
                            WHEN is `always', `never', or `auto'
  -U, --binary              do not strip CR characters at EOL (MSDOS)
  -u, --unix-byte-offsets   report offsets as if CRs were not there (MSDOS)

`egrep' means `grep -E'.  `fgrep' means `grep -F'.
Direct invocation as either `egrep' or `fgrep' is deprecated.
With no FILE, or when FILE is -, read standard input.  If less than two FILEs
are given, assume -h.  Exit status is 0 if any line was selected, 1 otherwise;
if any error occurs and -q was not given, the exit status is 2.

Report bugs to <bug-grep@gnu.org>.


参考文献:

1. Ken Thompson :unix implementation

2. Dennis Richie: The Evolution of the unix time-sharing system.

3. unix文件系统从multics 中借鉴了一些思想。 the multics system: an examination of its structure.

4. Bob Morris and Ken Thompson : password security : a case history

5. Dennis Ritchie:  on the security of unix. 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值