`
luoxiaofei126
  • 浏览: 15878 次
  • 性别: Icon_minigender_1
  • 来自: 上海
最近访客 更多访客>>
社区版块
存档分类
最新评论

About shell

阅读更多

-----------
Q1.用户登录到Linux机器,系统会启动login子程序处理用户登录请求,如何自动设置用户环境变量?
比如 PATH,CVS_RSH等等

编辑/etc/profile 和 $HOME/.bash_profile $HOME/.bash_login $HOME/.profile
当退出登录时,shell会执行 ~/.bash_logout

Q2.如何快速执行历史命令?

fc -s [cmd] 执行编号为cmd的命令,缺省的话,执行最近1条指令
可以使用alias r='fc -s' 登记1个命令别名,减少键击次数

注:
fc - Fix Command

可以用bash内建的命令查找功能,在命令输入状态下输入C-R,则再输入命令,即可出现
与当前输入字符串匹配的命令列表

Q3.如何快速查看一个用户的id和组id?

输入id 即可查看当前用户的id和组id(包括数字和名称)
输入id [USERNAME] 即可查看 USERNAME的id和组id(包括数字和名称)

Q4.如何查看OS打开的所有文件句柄?

输入lsof,可查看所有的打开文件
输入lsof /path/of/file, 可查看/path/of/file目录中被打开的文件

Q5.如何转化不同编码的文件?

例如 readme.txt 是GB2312编码的,Console只支持utf-8的,要将readme.txt
打印处理,如果不作编码转换,必然出现乱码.
可以用iconv工具进行转化
cat readme.txt| iconv -f gb2312 -t utf-8

Q6.如何在当前的shell会话上下文中设置环境变量?

将设置指令写如一个特定的bash文件,如setup.sh
执行 . setup.sh 命令
注: . 也是bash的一个内建指令

Q7.如何使用Bash的花括号自动扩展?

假设我们要打印出从a到z的26个字母,那么通常做法是从a循环到z,逐个输出,但我们知道
Linux下这样的轮子大多数已经被人发明过了,Bash中就有这样的工具

输入 echo {a..z}

扩展应用:
a) 当我们要列出多个目录下的文件时,这能给我们帮助
ls /path/{dir1, dir2}
b) 当我们要改变多个目录的属主时
chown /path/{ex?.?*, how_ex}

Q8.如何把一个命令的输出赋值给某一个特定的变量?

使用语句
var1=$(command)
或者反引号
var1=`command`

Q9. Bash中如何用快捷键键?

输入 CTRL-W 删除左边文本,直至遇到空格 ( vim 中 dB )
输入 CTRL-K 删除从光标位置到行尾的文本 (vim 中 d$ )
输入 CTRL-Y 粘贴剪贴板中的文本至光标位置 (vim 中 p)
输入 CTRL-r或 CTRL-s, 可匹配增量匹配当前的字, 显示出候选的命令.如果有多个匹配
结果,则输入C-r向后搜索,输入C-s向前搜索.

Q10. 如何让Bash中在sudo/man等命令时也会自动补全命令?

可利用Bash中的Programmable Completion Builtins功能,具体语法见
INFO BASH :: Command Line Editing :: Programmable Completion
比如要让man 具备自动补全的功能,则这么写
complete -F _man $filenames man

_man 函数会被执行,请求所有可能补全的值写在COMPREPLY数组中

Q11. Bash中如何Use Here Document?
使用语法
VAR=<<"EOF"
Some here document
EOF

注: 详见Bash Info - 3.6.5 Here Documents
- read input from the current source until a line containing only WORD (with no trailing
-blanks) is seen.

Q12. Bash中[[和[有何不同?
[[是复合命令,它可以构成测试用的表达式,表达式可以是bash中的条件表达式的任一种,
单目和双目运算的均可.可以用! && || 这样的逻辑运算符.

[是内建命令,同样也是用来测试表达式,表达式可以是Bash条件表达式中的任一种.
可以用! -a -o 这样的逻辑运算符.
两者是除了逻辑运算符不同之外,并无明显区别.

About Man/Info
---------------
Q1.用户手册将命令划分为不同的类别,如何查看分属不同Section的命令?

man 7 locale # 7代表Section 号


About X
--------
X1.如何获得系统中所有的字体?

输入指令 xlsfonts

X2. 如何在ssh登录到远程机器上后在本地运行X应用程序?

假设你的本地主机HostA,远程主机HostB,那么你要远程连接到HostB上运行X应用,显示在
HostA的屏幕上.
1. 配置HostA上 ~/.ssh/config 文件

Host *
ForwardAgent yes
ForwardX11 yes

ForwardX11Trusted yes
2. ssh HostB
3. 执行X应用程序

注意:必须在HostA上开通X11的转发而不是HostB.

X3. 如果使用第2个屏幕-投影仪?

在Ubuntu 7.04以上中自动支持投影仪,即插即用,但需要插上VGA的接口,重新启动系统后方可使用
在Ubuntu 7.10版本接上投影仪后,第2个屏幕无输出,要LOGOUT后才有输出

分享到:
评论

相关推荐

    learning linux shell scripting 2nd

    This book is for readers who are proficient at working with Linux and who want to learn about shell scripting to improve their efficiency and practical skills. The following are few examples where we ...

    Linux Shell Scripting Essentials 无水印pdf 0分

    Familiarize yourself with the terminal by learning about powerful shell features Automate tasks by writing shell scripts for repetitive work Packed with easy-to-follow, hands-on examples to help you ...

    mysql-shell-8.0.18-windows-x86-64bit.zip

    For information about using MySQL Shell, see MySQL Shell 8.0 (part of MySQL 8.0). When MySQL Shell is connected to the MySQL Server through the X Protocol, the X DevAPI can be used to work with both ...

    Mastering Linux Shell Scripting

    In this book, you’ll discover everything you need to know to master shell scripting and make informed choices about the elements you employ. Get to grips with the fundamentals of creating and running...

    Mastering Linux Shell Scripting.epub

    In this book, you’ll discover everything you need to know to master shell scripting and make informed choices about the elements you employ. Get to grips with the fundamentals of creating and running...

    Linux Shell Scripting Cookbook

    初学者的shell脚本编程入门教程(About This Book, Become an expert in creating powerful shell scripts and explore the full possibilities of the shellAutomate any administrative task you could imagine, ...

    Mastering Linux Shell Scripting.mobi

    In this book, you’ll discover everything you need to know to master shell scripting and make informed choices about the elements you employ. Get to grips with the fundamentals of creating and running...

    jxse-shell-2.5

    man An on-line help command that displays information about a specific Shell command mem Display memory information mkadv Make an advertisement from a document mkmsg Make a pipe message mkpipe Create ...

    UNIX Shell Programming(OXFORD,2014)

    Detailed description about different types of editors and shell programming (including Bourne, C, and interactive Korn shell) has also been provided. Chapters dedicated to debugging and system ...

    Mastering Linux Shell Scripting(PACKT,2015)

    In this book, you’ll discover everything you need to know to master shell scripting and make informed choices about the elements you employ. Get to grips with the fundamentals of creating and running...

    Linux Shell Scripting Cookbook - Third Edition

    About This Book Become an expert in creating powerful shell scripts and explore the full possibilities of the shell Automate any administrative task you could imagine, with shell scripts Packed with ...

    csapp-shell-labcsapp-shell-labcsapp-shell-lab

    They can be used to communicate between processes and to notify a process about changes in its environment. In the context of this lab assignment, you will implement signal handlers for specific ...

    UNIX.and.Shell.Programming.0198082169

    Detailed description about different types of editors and shell programming (including Bourne, C, and interactive Korn shell) has also been provided. Chapters dedicated to debugging and system ...

    Mastering Linux Shell Scripting 2nd Edition

    shell. Then, you'll learn how to write a simple bash script and how to edit your bash script using Linux editors. Following this, you will learn how to define a variable and the visibility of a ...

    Mastering Linux Shell Scripting.pdf

    In this book, you’ll discover everything you need to know to master shell scripting and make informed choices about the elements you employ. Get to grips with the fundamentals of creating and running...

    LinuxShell的基本应用.caj

    ABOUT THE LINUX SHELL PDF FILE

Global site tag (gtag.js) - Google Analytics