本节是shell脚本编程入门教程的第二节,介绍linux shell中文件操作的常用命令,包括rm命令、mkdir命令、stat命令、cat命令等的用法,需要的朋友参考下。
shell脚本编程入门教程(2)第二部分
7)
less命令,less命令符合了少即是多的概念,它提供了额外的信心,显示了文件的总行数,以及行区间,支持所有more命令。
用法参数如下:
[search@h1 logs]$ man less
LESS(1) LESS(1)
NAME
less - opposite of more
SYNOPSIS
less -?
less --help
less -V
less --version
less [-[+]aBcCdeEfFgGiIJKLmMnNqQrRsSuUVwWX~]
[-b space] [-h lines] [-j line] [-k keyfile]
[-{oO} logfile] [-p pattern] [-P prompt] [-t tag]
[-T tagsfile] [-x tab,...] [-y lines] [-[z] lines]
[-# shift] [+[+]cmd] [--] [filename]...
(See the OPTIONS section for alternate option syntax with long option names.)
DESCRIPTION
Less is a program similar to more (1), but which allows backward movement in the file as well as forward movement. Also, less does not have to read
the entire input file before starting, so with large input files it starts up faster than text editors like vi (1). Less uses termcap (or terminfo on
some systems), so it can run on a variety of terminals. There is even limited support for hardcopy terminals. (On a hardcopy terminal, lines which
should be printed at the top of the screen are prefixed with a caret.)
Commands are ba
sed on both more and vi. Commands may be preceded by a decimal number, called N in the descriptions below. The number is used by some
commands, as indicated.
COMMANDS
In the following descriptions, ^X means control-X. ESC stands for the ESCAPE key; for example ESC-v means the two character sequence "ESCAPE", then
"v".
h or H Help: display a summary of these commands. If you forget all the other commands, remember this one.
SPACE or ^V or f or ^F
Scroll forward N lines, default one window (see option -z below). If N is more than the screen size, only the final screenful is displayed.
Warning: some systems use ^V as a special literalization character.
z Like SPACE, but if N is specified, it becomes the new window size.
ESC-SPACE
Like SPACE, but scrolls a full screenful, even if it reaches end-of-file in the process.
RETURN or ^N or e or ^E or j or ^J
Scroll forward N lines, default 1. The entire N lines are displayed, even if N is more than the screen size.
d or ^D
Scroll forward N lines, default one half of the screen size. If N is specified, it becomes the new default for subsequent d and u commands.
b or ^B or ESC-v
Scroll backward N lines, default one window (see option -z below). If N is more than the screen size, only the final screenful is displayed.
w Like ESC-v, but if N is specified, it becomes the new window size.
y or ^Y or ^P or k or ^K
Scroll backward N lines, default 1. The entire N lines are displayed, even if N is more than the screen size. Warning: some systems use ^Y as
8) tail命令,tail命令在实际开发中,非常常用,散仙的经验,基本所有的log文件,都可以用tail 命令查看,因为它可以动态监视日志文件,比如,你在查看日志文件过程中,系统动态输出的文件,都会在屏幕上,实时打印出来,简直就是实时监控的利器。用法如下
tail -f 文件名
具体的参数
[search@h1 logs]$ man tail
TAIL(1) User Commands TAIL(1)
NAME
tail - output the last part of files
SYNOPSIS
tail [OPTION]... [FILE]...
DESCRIPTION
Print the last 10 lines of each FILE to standard output. With more than one FILE, precede each with a header giving the file name. With no FILE, or
when FILE is -, read standard input.
Mandatory arguments to long options are mandatory for short options too.
-c, --bytes=K
output the last K bytes; alternatively, use -c +K to output bytes starting with the Kth of each file
-f, --follow[={name|descriptor}]
output appended data as the file grows; -f, --follow, and --follow=descriptor are equivalent
-F same as --follow=name --retry
-n, --lines=K
output the last K lines, instead of the last 10; or use -n +K to output lines starting with the Kth
--max-unchanged-stats=N
with --follow=name, reopen a FILE which has not changed size after N (default 5) iterations to see if it has been unlinked or renamed (this is
the usual case of rotated log files). With
inotify, this option is rarely useful.
--pid=PID
with -f, terminate after process ID, PID dies
-q, --quiet, --silent
never output headers giving file names
--retry
keep trying to open a file even when it is or becomes inaccessible; useful when following by name, i.e., with --follow=name
-s, --sleep-interval=N
with -f, sleep for approximately N seconds (default 1.0) between iterations.
With inotify and --pid=P, check process P at least once every N seconds.
-v, --verbose
always output headers giving file names
--help display this help and exit
--version
output version information and exit
If the first character of K (the number of bytes or lines) is a ‘+’, print beginning with the Kth item from the start of each file, otherwise, print
the last K items in the file. K may have a multiplier suffix: b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024, GB 1000*1000*1000, G 1024*1024*1024,
and so on for T, P, E, Z, Y.
:
9)head命令,head命令时显示文件开头的内容,默认显示前10行的文本,对于大文件,想大概了解一下文件内容,很有用。
用法: head 文件名