linux you need to know

Jobs are at a higher level than Linux processes; the Linux operating
system knows nothing about them. They are merely constructs

of the shell. Some important vocabulary about job control is


Foreground job
Running in a shell, occupying the shell prompt so you
cannot run another command
Background job
Running in a shell, but not occupying the shell prompt,
so you can run another command in the same shell
Suspend
To stop a foreground job temporarily
Resume
To cause a suspended job to start running again


this power comes with one warning: if any of the files located by
find contains whitespace in its name, this will confuse grep. If one
file is named (say) my stuff, then the grep command constructed is:
$ grep -l myxomatosis my stuff
which tells grep to process two files named my and stuff. Oops! Now
imagine if the program had been rm instead of grep. You’d be telling
rm to delete the wrong files! To avoid this problem, always use find
-print0 instead of -print, which separates lines with ASCII null
characters instead of newline characters, combined with xargs -0,
which expects ASCII nulls:
$ find . -print0 | xargs -0 grep -l myxomatosis
We have barely scratched the surface of the xargs command, so
please experiment! (With harmless commands like grep and ls at
first!)find -print0.


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



xargs Versus Backquotes
If you remember “Quoting” on page 29, you might realize that
some xargs tricks can be accomplished with backquotes:
$ cat file_list | xargs rm -f
$ rm -f `cat file_list`
with xargs
with backquotes
While both commands do similar things, backquotes can fail
if the command line gets so long, after the quoted part is ex-
panded, that it exceeds the maximum length of a shell com-
mand line. xargs does not have this limitation, so it’s safer and
more suitable for large or risky operations.

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


If several programs in your search path have the same name (for
example, /usr/bin/who and /usr/local/bin/who), which reports only
the first.


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



fgrep is convenient when searching for nonalphanumeric charac-
ters like * and { because they are taken literally, not as regular ex-
pression characters.

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

关于打印

Linux has two popular printing systems, called CUPS and
LPRng. Both systems use commands with the same names: lpr,
lpq, and lprm. However, these commands have different op-
tions depending whether you’re using CUPS or LPRng. To be
generally helpful, we will present common options that work
with both systems.


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

Run in current shell with “.” or source
The preceding methods run your script as an independent
entity that has no effect on your current shell.22 If you
want your script to make changes to your current shell
(setting variables, changing directory, and so on), it can
22. That’s because the script runs in a separate shell (a subshell or child
shell) that cannot alter the original shell.
206 | Linux Pocket Guide
www.it-ebooks.info
be run in the current shell with the source or “.”
command:
$ . myscript
$ source myscript


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


Your script can test the number of arguments it received with
$#:
if [ $# -lt 2 ]
then
echo "$0 error: you must supply two arguments"
else
echo "My name is $1 and I come from $2"
fi


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值