bash 看书摘抄(一):bash基础

bash是最流行、最强大的Unix Shell之一。

 

判断本系统所使用的Shell:echo $SHELL

 

查找bash:

whereis bash

wherece bash

which bash

grep bash /etc/passwd | awk –F ’{printf $7} ’sort –u

 

目录结构:

                                                    根目录

                                                        |

----------------------------------------------------

|                         |                                            |

usr                     etc                                      home

|                                                                       |

lib                              ---------------------------------------------

                                 |                   |                   |                     |

                               leon              alice                hatter             gryphon

 

工作目录,用户主目录:/home/leon

lp memo       //在/home/leon下查找文件memo打印

~标记

在用户名前加~:~leon/story引用leon主目录下story文件,这是绝对路径,与当前目录无关

~本身可以引用自己用户的目录:~/story

改变工作目录

cd

查看当前目录:pwd

直接使用cd将改变到用户主目录

cd - 返回到前一个工作目录

文件名、通配符和路径名扩展

ls duchess queen //查找两个文件

ls –l //列出所有者,大小,最后修改时间和其他信息

ls –a //列出包含隐藏文件所有文件

ls –al

?,*通配符

[abc] //a,b or c

[!A-C] //所有非A,B, and C

echo b{ed,olt,ar}s //大括号通配符,打印出beds,bolts,bars

输入输出

常用UNIX数据过滤功能

cat    将输入复制到输出   //catenate 连接在一起

grep  在输入中检索字符串

sort  在输入中将行排序

cut   从输入中抽取行

sed  对输入执行编辑操作

tr     将输入字符转换成其他字符

键入cat filename:打印出文件内容

键入cat不加参数,将会等待你键入一行文本,回车后重新输出,要停止输入ctrl + D

command < filename 他可以将命令设置为从一个文件而不从终端中接受标准输入

          cat < filename //在终端打印文件内容

command > filename 使命令的标准输出重新定向到命名文件

复制文件:

      cp file1 file2

      cat < file1 > file2

管道行 pipeline //将一个命令的输出重定向到另一个命令的输入

cut –d: –f1 < /etc/passwd | sort //从后面的文件中抽取用:分隔的第一个域(f1),然后排序

adm

bin

leon

ftp

后台作业

uncompress gcc.tar &

jobs 命令检查后台作业

特殊字符和引用

~ 主目录 一(介绍的章节)

` 命令替换 四

# 注释 四

$ 变量表达式 三

& 后台作业 一

* 字符串通配符 一

( 启动子Shell 八

) 停止子Shell 八

\ 引用下一字符 一

| 管道 一

[ 开始字符集通配符号 一

] 结束字符集通配符号 一

{ 开始命令快 七

} 结束命令快 七

; Shell命令分隔符 三

’ 强引用 一

"  弱引用 一

< 输入重定向 一

> 输出重定向 一

/ 路径名目录分隔符 一

? 单个任意字符 一

! 管道行逻辑NOT 五

引用:

echo ’2 * 3 > 5’ is a valid inequality

echo 2 \* 3 \> 5 is a valid inequality

find .-name string //搜索根为当前目录的目录树下名字匹配的文件

$ echo the Since then, developers have written \

> many other implementations, and the \

> IETF has formalized the core XML\

> streaming protocol as the Extensible Messaging\

> and Presence Protocol (XMPP).

 

$ echo the Since then, developers have written

> many other implementations, and the

> IETF has formalized the core XML

> streaming protocol as the Extensible Messaging

> and Presence Protocol (XMPP).

控制键(stty all)

ctrl + C  中止当前命令

ctrl + D  输入结束

ctrl + \   如果ctrl+C无效,则中止当前命令

ctrl + S  停止输出到屏幕

ctrl + Q  重新开始到屏幕的输出

ctrl + ? 或者 DEL 删除最后的字符

ctrl + U  删除整个命令行

Ctrl + Z  暂停当前命令

HELP

help cd

posted @ 2010-04-04 14:22  鱼缸里的小鱼  Views(267)  Comments(0)    收藏  举报