初识50个Linux命令
1. 【命令】:cat
【功能说明】:
concatenate files and print on the standard output #连接文件并打印到标准输出,有标准输出的都可以用重定向定向导入到文件里面
【语法格式】:
cat [OPTION]...[FILE]...
【选项参数】:
参数 |
说明 |
简解 |
-b,--number-nonblank |
number nonempty output lines |
非空输出行编号 |
-n,--number |
number all outputnlines |
所有行输出编号 |
【示例】:
1、基本用法:查看文件内容
[root@oldboy ~]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
2、把log1.txt的文件内容加上行号输入log2.txt这个文件里
[root@oldboy ~]# cat -n log1.txt
1 2012-1
2 2013-1
3 2014-1
4
5
[root@oldboy ~]# cat -n log1.txt>log2.txt
[root@oldboy ~]# cat log2.txt
1 2012-1
2 2013-1
3 2014-1
4
5
3、把文件log1.txt里面的文件空格不显示行号加入log2.txt中
[root@oldboy ~]# cat -n log1.txt
1 2012-1
2 2013-1
3 2014-1
4
5
[root@oldboy ~]# cat -b log1.txt
1 2012-1
2 2013-1
3 2014-1
[root@oldboy ~]# cat -b log1.txt>log2.txt
[root@oldboy ~]# cat log2.txt
1 2012-1
2 2013-1
3 2014-1
4、同时显示log1.txt和log2.txt
[root@oldboy ~]# cat log1.txt log2.txt
2012-1
2013-1
2014-1
1 2012-1
2 2013-1
3 2014-1
5、使用cat编辑文档内容
[root@oldboy ~]# cat >log1.txt<<EOF
> 2012-3
> 2013-3
> 2014-3
> EOF
[root@oldboy ~]# cat log1.txt
2012-3
2013-3
2014-3
6、使用cat追加编辑文档内容
[root@oldboy data]# cat >>oldboy.txt<<EOF
> ni hao
> jin tian tian qi zhen hao
> EOF
[root@oldboy data]# cat oldboy.txt
I am oldboy
I am study linux
ni hao
jin tian tian qi zhen hao
2. 【命令】:cd
【功能说明】:
Change the current directory to DIR #更改当前路径为DIR
【语法格式】:
cd [-L|-P] [dir]
【选项参数】:
参数 |
说明 |
简解 |
-L |
force symbolic links to be followed |
|
-P |
use the physical directory structure without following symbolic |
|
- |
【示例】:
1、基本用法:更改目录路径到根目录
[root@oldboy ~]# cd /
[root@oldboy /]#
2、基本用法:更改目录路径到上级目录
[root@oldboy ~]# cd ..
[root@oldboy /]#
3、更改目录路径到上一次使用的目录
[root@oldboy /]# cd -
/root
[root@oldboy ~]#
3. 【命令】:mkdir
【功能说明】:
make directories #创建目录
【语法格式】:
mkdir [OPTION]... DIRECTORY...
【选项参数】:
参数 |
说明 |
简解 |
-m, --mode |
set file mode (as in chmod), not a=rwx - umask |
设定权限<模式>(类似chmod),而不是rwxrwxrwx减umask |
-p, --parents |
no error if existing, make parent directories as needed |
递归创建目录 |
-v, --verbose |
print a message for each created directory |
每次创建新目录都显示信息 |
-Z |
set the SELinux security context of each created directory to CTX |
【示例】:
1、基本用法:创建目录
[root@oldboy ~]# mkdir /data
[root@oldboy ~]# cd /data
[root@oldboy data]# pwd
/data
2、递归创建多个目录
[root@oldboy data]# mkdir -p /oldboy/oldboy
[root@oldboy data]# cd /oldboy/oldboy
[root@oldboy oldboy]# pwd
/oldboy/oldboy
4. 【命令】:ls
【功能说明】:
list directory contents #列出目标目录中所有的子目录和文件
【语法格式】:
ls [OPTION]... [FILE]...
【选项参数】:
参数 |
说明 |
简解 |
-a, --all |
do not ignore entries starting with. |
列出目录下的所有文件 |
-A, --almost-all |
do not list implied.and .. |
同-a,但不列出“.”(表示当前目录)和“..”(表示当前目录的父目录) |
-b, --escape |
print octal escapes for nongraphic characters |
把文件名中不可输出的字符用反斜杠加字符编号的形式列出 |
-B, --ignore-backups |
do not list implied entries ending with ~ |
不输出以“~”结尾的备份文件 |
-c |
sort by ctime |
配合-lt;根据ctime排序及显示ctime(文件状态最后更改的时间)配合-l:显示ctime但根据名称排序否则:根据ctime排序 |
-C |
list entries by clumns |
每栏由上至下列出项目 |
-d, --directory |
list directory entries instead of contentsm,and do not dereference symbolic links |
将目录象文件一样显示,而不是显示其下的文件 |
-D, --dired |
generate output designed for Emacs’ dired mode |
产生适合Emacs的dired模式使用的结果 |
-f |
do not sort,enable -aU,disable -ls --color |
对输出的文件不进行排序,-aU选项生效,-1st选项失效 |
-F --classify |
append indicator(one of */=>@|)to entries |
在每个文件名后附上一个字符以说明该文件的类型,“*”表示可执行的普通 |
-g |
like -l,but do not list owner |
类似-l,但不列出所有者 |
-h, --human-readable |
with -l,print sizes in human readable format |
以容易理解的格式列出文件大小 |
-H, --dereference-command-line |
follow symbolic links listed on the command line |
使用命令列中的符号链接指示的真正目的地 |
-i, --inode |
print the index number of each file |
打印出每个文件的inode号 |
-I,--ignore=PATTERN |
do not list implied entries matching shell PATTERN |
不打印出任何符合shell万用字符<样式>的项目 |
-k |
like --block-size=1K |
以k字节的形式表示文件的大小 |
-l |
use a long listing format |
除了文件名之外,还将文件的权限、所有者、文件大小等信息详细列出来 |
-L,--dereference |
when showing file information for a symbolic link,show information for the file the link references rather than for the link itself |
当显示符号链接的文件信息时,显示符号链接所指示的对象而并非符号链接本身的信息。 |
-m |
fill width with a comma separated list of entries |
所有项目以逗号分隔,并填满整行行宽 |
-n, --numeric-uid-gid |
like -l,but list numeric user and group IDs |
用数字的UID,GID代替名称 |
-N, --literal |
print raw entry names |
不限制文件长度 |
-o |
like -l,but do not list group information |
类似-l,显示文件的除组信息外的详细信息 |
-p, --indicator-style=slash |
append / indicator to directories |
对目录添加“/”符号 |
-q, --hide-control-chars |
print ? instead of non graphic characters |
用?号代替不可输出的字符 |
-Q, --quote-name |
enclose entry names in double quotes |
把输出的文件名用双引号括起来 |
-r, --reverse |
reverse order while sorting |
依相反次序排列 |
-R, --recursive |
list subdirectories recursively |
同时列出所有子目录层 |
-s, --size |
print the allocated size of each file,in blocks |
以块大小为单位列出所有文件的大小 |
-S |
sort by file size |
根据文件大小排序 |
-t |
sort by modification time |
以文件修改时间排序 |
-T, --tabsize=COLS |
assume tab stops at each COLS instead of 8 |
|
-u |
with -lt: sort by, and show, access time with -l:show access time and sort by name otherwise: sort by access time |
配合-lt:显示访问时间而且依访问时间排序 配合-l:显示访问时间但根据名称排序 其他:根据访问时间排序 |
-U |
do not sort; list entries in directory order |
不进行排序;依文件系统原有的次序列出项目 |
-v |
natural sort of (version) numbers within text |
根据版本进行排序 |
-w, --width=COLS |
assume screen width instead of current value |
自行指定屏幕宽度而不使用目前的数值 |
-x |
list entries by lines instead of by columns |
逐行列出项目而不是逐栏列出 |
-X |
sort alphabetically by entry extension |
根据扩展名排序 |
-1 |
list one file per line |
每行只列出一个文件 |
【示例】:
1、基本用法:查看目录内容
[root@oldboy ~]# ls
anaconda-ks.cfg data install.log install.log.syslog log1.txt log2.txt test.txt
2、基本用法:查看目录全部内容(包含隐藏文件)
[root@oldboy ~]# ls -la
total 88
dr-xr-x---. 3 root root 4096 Mar 7 18:16 .
dr-xr-xr-x. 24 root root 4096 Mar 9 17:00 ..
-rw-------. 1 root root 1079 Mar 3 23:14 anaconda-ks.cfg
-rw-------. 1 root root 5003 Mar 9 04:13 .bash_history
-rw-r--r--. 1 root root 18 May 20 2009 .bash_logout
-rw-r--r--. 1 root root 176 May 20 2009 .bash_profile
-rw-r--r--. 1 root root 176 Sep 23 2004 .bashrc
-rw-r--r--. 1 root root 100 Sep 23 2004 .cshrc
drwxr-xr-x. 3 root root 4096 Mar 9 01:47 data
-rw-r--r--. 1 root root 22179 Mar 3 23:14 install.log
-rw-r--r--. 1 root root 5890 Mar 3 23:13 install.log.syslog
-rw-r--r--. 1 root root 18 Mar 7 18:13 log1.txt
-rw-r--r--. 1 root root 44 Mar 7 17:53 log2.txt
-rw-r--r--. 1 root root 129 Dec 4 2004 .tcshrc
-rw-r--r--. 1 root root 0 Mar 7 18:27 test.txt
3、基本用法:查看目录(使用长模式)
[root@oldboy ~]# ls -l
total 52
-rw-------. 1 root root 1079 Mar 3 23:14 anaconda-ks.cfg
drwxr-xr-x. 3 root root 4096 Mar 9 01:47 data
-rw-r--r--. 1 root root 22179 Mar 3 23:14 install.log
-rw-r--r--. 1 root root 5890 Mar 3 23:13 install.log.syslog
-rw-r--r--. 1 root root 18 Mar 7 18:13 log1.txt
-rw-r--r--. 1 root root 44 Mar 7 17:53 log2.txt
-rw-r--r--. 1 root root 0 Mar 7 18:27 test.txt
5. 【命令】:pwd
【功能说明】:
print name of current/working directory #打印当前目录路径
【语法格式】:
pwd [OPTION]
【选项参数】:
参数 |
说明 |
简解 |
-L, --logical |
use PWD from environment,even if it contains symlinks |
当目录为链接路径时,显示链接路径 |
-P, --physical |
avoid all symlinks |
显示实际物理路径,而非使用链接 |
【示例】:
1、基本用法:显示当前目录所在路径
[root@oldboy ~]# pwd
/root
[root@oldboy ~]#
2、显示当前目录的物理路径
[root@oldboy ~]# cd /etc/init.d
[root@oldboy init.d]# pwd -P
/etc/rc.d/init.d
3、显示当前目录的链接路径
[root@oldboy ~]# cd /etc/init.d
[root@oldboy init.d]# pwd -L
/etc/init.d
6. 【命令】:touch
【功能说明】:
change file timestamps #创建文件或改变文件的时间戳
【语法格式】:
pwd [OPTION]... FILE...
【选项参数】:
参数 |
说明 |
简解 |
-a |
change only the access time |
只更改存取时间 |
-c, --no-create |
do not create any files |
不新建任何文档 |
-d, --date=STRING |
parse STRING and use it instead of current time |
使用指定的日期时间,而非现在的时间 |
-f |
(ignored) |
忽略 |
-h, --no-dereference |
affect each symbolic link instead of any referenced file (useful only on systems that can change the timestamps of a symlink) |
会影响符号链接本身,而非符号链接所指示的目的地 |
-m |
change only the modification time |
只更改变动时间 |
-r, --reference=FILE |
use this file’s times instead of current time |
把指定文档或目录的日期时间,统统设成和参考文档或目录的日期时间相同 |
-t STAMP |
use [[CC]YY]MMDDhhmm[.ss] instead of current time |
使用指定格式的日期时间,而非当前时间 |
--time=WORD |
change the specified time: WORD is access, atime, or use: equivalent to -a WORD is modify or mtime: equivalent to -m |
使用WORD指定的时间:access、atime、use都等于-a选项的效果,而modify、mtime等于-m选项的效果 |
【示例】:
1、基本用法:创建新文件
[root@oldboy data]# touch log2012.log log2013.log
[root@oldboy data]# ll
total 0
-rw-r--r--. 1 root root 0 Mar 9 17:48 log2012.log
-rw-r--r--. 1 root root 0 Mar 9 17:48 log2013.log
2、不创建不存在的文件
[root@oldboy data]# touch -c log2014.log
[root@oldboy data]# ll
total 0
-rw-r--r--. 1 root root 0 Mar 9 17:48 log2012.log
-rw-r--r--. 1 root root 0 Mar 9 17:48 log2013.log
3、更新log2012.log的时间和log.log时间戳相同
[root@oldboy data]# touch log.log
[root@oldboy data]# ll
total 0
-rw-r--r--. 1 root root 0 Mar 9 2016 log2012.log
-rw-r--r--. 1 root root 0 Mar 9 2016 log2013.log
-rw-r--r--. 1 root root 0 May 23 00:00 log.log
[root@oldboy data]# touch -r log.log log2012.log
[root@oldboy data]# ll
total 0
-rw-r--r--. 1 root root 0 May 23 00:00 log2012.log
-rw-r--r--. 1 root root 0 Mar 9 2016 log2013.log
-rw-r--r--. 1 root root 0 May 23 00:00 log.log
4、设定文件时间戳
[root@oldboy data]# touch -t 201211142234.50 log2016.log
[root@oldboy data]# ll
total 0
-rw-r--r--. 1 root root 0 Nov 14 2012 log2016.log
【说明】:
-t time 使用指定的时间值 time 作为指定文件相应时间戳记的新值.此处的 time规定为如下形式的十进制数:
[[CC]YY]MMDDhhmm[.SS]
这里,CC为年数中的前两位,即”世纪数”;YY为年数的后两位,即某世纪中的年数.如果不给出CC的值,则touch 将把年数CCYY限定在1969--2068之内.MM为月数,DD为天将把年数CCYY限定在1969--2068之内.MM为月数,DD为天数,hh 为小时数(几点),mm为分钟数,SS为秒数.此处秒的设定范围是0--61,这样可以处理闰秒.这些数字组成的时间是环境变量TZ指定的时区中的一个时 间.由于系统的限制,早于1970年1月1日的时间是错误的。
7. 【命令】:echo
【功能说明】:
display a line of text #打印输出
【语法格式】:
echo [SHORT-OPTION]... [STRING]...
echo LONG-OPTION
【选项参数】:
参数 |
说明 |
简解 |
-n |
do not output the trailing newline |
不要在最后自动换行 |
-e |
enable interpretation of backslash escapes |
若字符串中出现以下字符,则特别加以处理,而不会将它当成一般文字输出 \a 发出警告声; |
-E |
disable interpretation of backslash escapes (default) |
不解释转意字符 |
【示例】:
1、基本用法:打印内容
[root@oldboy data]# echo "I am studying linux."
I am studying linux.
2、打印变量内容
[root@oldboy data]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
8. 【命令】:xargs
【功能说明】:
build and execute command lines from standard input #从标准输入获取内容创建和执行命令
【语法格式】:
xargs [-0prtx] [-E eof-str] [-e[eof-str]] [--eof[=eof-str]] [--null] [-d delimiter]
[--delimiter delimiter] [-I replace-str] [-i[replace-str]] [--replace[=replace-str]]
[-l[max-lines]] [-L max-lines] [--max-lines[=max-lines]] [-n max-args] [--max-args=max-
args] [-s max-chars] [--max-chars=max-chars] [-P max-procs] [--max-procs=max-procs]
[--interactive] [--verbose] [--exit] [--no-run-if-empty] [--arg-file=file]
[--show-limits] [--version] [--help] [command [initial-arguments]]
【选项参数】:
参数 |
说明 |
简解 |
【示例】:
1、基本用法:与find配合使用,删除/data目录下所有.txt文件
[root@oldboy ~]# find /data -type f -name "*.txt"|xargs rm -f
[root@oldboy ~]# cd /data
[root@oldboy data]# ll
total 0
9. 【命令】:mv
【功能说明】:
move (rename) files #移动或重命名文件
【语法格式】:
mv [OPTION]... [-T] SOURCE DEST
mv [OPTION]... SOURCE... DIRECTORY
mv [OPTION]... -t DIRECTORY SOURCE...
【选项参数】:
参数 |
说明 |
简解 |
--backup[=CONTROL] |
make a backup of each existing destination file |
备份模式:若需覆盖文件,则覆盖前先行备份 |
-b |
like --backup but does not accept an argument |
若需覆盖文件,则覆盖前先行备份。 |
-f, --force |
do not prompt before overwriting |
force 强制的意思,如果目标文件已经存在,不会询问而直接覆盖 |
-i, --interactive |
prompt before overwrite |
若目标文件 (destination) 已经存在时,就会询问是否覆盖 |
-n, --no-clobber |
do not overwrite an existing file |
|
-S, --suffix=SUFFIX |
override the usual backup suffix |
为备份文件指定后缀,而不使用默认的后缀; |
-t, --target-directory=DIRECTORY |
move all SOURCE arguments into DIRECTORY |
指定mv的目标目录,该选项适用于移动多个源文件到一个目录的情况,此时目标目录在前,源文件在后 |
-T, --no-target-directory |
treat DEST as a normal file |
|
-u, --update |
move only when the SOURCE file is newer than the destination file or when the destination file is missing |
若目标文件已经存在,且 source 比较新,才会更新(update) |
-v, --verbose |
explain what is being done |
显示程序执行过程 |
【示例】:
1、基本用法:移动文件
[root@oldboy ~]# mv ett.txt /root/data
[root@oldboy ~]# cd data
[root@oldboy data]# ll
total 4
-rw-r--r--. 1 root root 292 Mar 9 13:28 ett.txt
2、基本用法:移动目录
[root@oldboy ~]# mv /data /root
[root@oldboy ~]# ll
total 56
-rw-------. 1 root root 1079 Mar 3 23:14 anaconda-ks.cfg
drwxr-xr-x. 2 root root 4096 Mar 9 13:56 data
-rw-r--r--. 1 root root 22179 Mar 3 23:14 install.log
3、更改文件名
[root@oldboy data]# ll
total 4
-rw-r--r--. 1 root root 292 Mar 9 13:28 ett.txt
[root@oldboy data]# mv ett.txt oldboy.txt
[root@oldboy data]# ll
total 4
-rw-r--r--. 1 root root 292 Mar 9 13:28 oldboy.txt
4、多个文件移动到同一个目录
[root@localhost test3]# mv -t /opt/soft/test/test4/ log1.txt log2.txt log3.txt
[root@localhost test3]# cd ..
[root@localhost test]# cd test4/
[root@localhost test4]# ll
总计 12
-rw-r--r-- 1 root root 8 10-28 06:15 log1.txt
-rw-r--r-- 1 root root 12 10-28 06:15 log2.txt
-rw-r--r-- 1 root root 13 10-28 06:16 log3.txt
10. 【命令】:rm
【功能说明】:
remove files or directories #移除文件或目录
【语法格式】:
rm [OPTION]... FILE...
【选项参数】:
参数 |
说明 |
简解 |
-f, --force |
ignore nonexistent files,never prompt |
忽略不存在的文件,从不给出提示 |
-i |
prompt before every removal |
进行交互式删除 |
-I |
prompt once before removing more than three files, or when removing recursively. Less intrusive than -i, while still giving protection against most mistakes |
|
-r, -R, --recursive |
remove directories and their contents recursively |
指示rm将参数中列出的全部目录和子目录均递归地删除 |
-v, --verbose |
explain what is being done |
显示命令执行过程 |
【示例】:
1、基本用法:删除文件
[root@oldboy ~]# rm log1.txt
rm: remove regular file `log1.txt'? y
[root@oldboy ~]# ll
total 52
-rw-------. 1 root root 1079 Mar 3 23:14 anaconda-ks.cfg
drwxr-xr-x. 2 root root 4096 Mar 9 13:56 data
-rw-r--r--. 1 root root 22179 Mar 3 23:14 install.log
-rw-r--r--. 1 root root 5890 Mar 3 23:13 install.log.syslog
-rw-r--r--. 1 root root 44 Mar 7 17:53 log2.txt
-rw-r--r--. 1 root root 18 Mar 9 13:19 oldboy.txt
2、基本用法:删除目录
[root@oldboy data]# rm -r a
rm: descend into directory `a'? y
rm: descend into directory `a/b'? y
rm: remove regular empty file `a/b/oldboy.txt'? y
rm: remove directory `a/b/c'? y
rm: remove directory `a/b'? y
rm: remove regular empty file `a/oldboy.txt'? y
rm: remove directory `a'? y
11. 【命令】:find
【功能说明】:
search for files in a directory hierarchy #查找文档
【语法格式】:
find [-H] [-L] [-P] [-D debugopts] [-Olevel] [path...] [expression]
【选项参数】:
参数或选项 |
说明 |
简解 |
-atime n |
File was last accessed n*24 hours ago. When find figures out how many 24-hour periods ago the file was last accessed, any fractional part is ignored, so to match -atime +1, a file has to have been accessed at least two days ago. |
根据最后一次的访问时间查找文件 |
-ctime n |
File’s status was last changed n*24 hours ago. See the comments for -atime to understand how rounding affects the interpretation of file status change times. |
根据最后一次的改变时间查找文件 |
-mtime n |
File’s data was last modified n*24 hours ago. See the comments for -atime to understand how rounding affects the interpretation of file modification times. |
根据最后一次的修改时间查找文件 |
-type c |
File is of type c: b block (buffered) special c character (unbuffered) special d directory p named pipe (FIFO) f regular file l symbolic link; this is never true if the -L option or the -follow option is in effect, unless the symbolic link is broken. If you want to search for symbolic links when -L is in effect, use -xtype. s socket D door (Solaris) |
查找某一类型的文件 b 块设备文件 d 目录 c 字符设备文件 p 管道文件 l 符号链接文件 f 普通文件 s socket文件 |
-name pattern |
Base of file name (the path with the leading directories removed) matches shell pattern pattern. The metacharacters (‘*’, ‘?’, and ‘[]’) match a ‘.’ at the start of the base name (this is a change in findutils-4.2.2; see section STAN-DARDS CONFORMANCE below). To ignore a directory and the files under it, use -prune; see an example in the description of -path. Braces are not recognised as being special, despite the fact that some shells including Bash imbue braces with a special meaning in shell patterns. The filename matching is performed with the use of the fnmatch(3) library function. Don’t forget to enclose the pattern in quotes in order to protect it from expansion by the shell. |
按文件名查找文件 |
-perm mode |
File’s permission bits are exactly mode (octal or symbolic). Since an exact match is required, if you want to use this form for symbolic modes, you may have to specify a rather complex mode string. For example ‘-perm g=w’ will only match files which have mode 0020 (that is, ones for which group write permission is the only permission set). It is more likely that you will want to use the ‘/’ or ‘-’ forms, for example ‘-perm -g=w’, which matches any file with group write permis- sion. See the EXAMPLES section for some illustrative examples. |
按照文件权限来查找文件 |
-size n[cwbkMG] |
File uses n units of space. The following suffixes can be used: ‘b’ for 512-byte blocks (this is the default if no suffix is used) ‘c’ for bytes ‘w’ for two-byte words ‘k’ for Kilobytes (units of 1024 bytes) ‘M’ for Megabytes (units of 1048576 bytes) ‘G’ for Gigabytes (units of 1073741824 bytes) |
按大小查找 |
【示例】:
1、基本用法:按文件名查找文件
[root@oldboy ~]# find /root/data -name "*.txt"
/root/data/oldboy.txt
2、基本用法:按文件类型查找文件
[root@oldboy ~]# find /root/data -type f
/root/data/oldboy.txt
3、查找文件名称不为oldboy.txt的所有文件
[root@oldboy ~]# ll
total 52
-rw-------. 1 root root 1079 Mar 3 23:14 anaconda-ks.cfg
drwxr-xr-x. 2 root root 4096 Mar 9 15:09 data
-rw-r--r--. 1 root root 22179 Mar 3 23:14 install.log
-rw-r--r--. 1 root root 5890 Mar 3 23:13 install.log.syslog
-rw-r--r--. 1 root root 44 Mar 7 17:53 log2.txt
-rw-r--r--. 1 root root 18 Mar 9 13:19 oldboy.txt
[root@oldboy ~]# find /root ! -name "oldboy.txt"
/root
/root/.bash_history
/root/.bashrc
/root/.bash_logout
/root/.bash_profile
/root/data
/root/install.log
/root/log2.txt
/root/.lesshst
/root/.cshrc
/root/anaconda-ks.cfg
/root/install.log.syslog
/root/.tcshrc
4、利用find查找删除扩展名为txt的所有文件
[root@oldboy data]# ll
total 4
-rw-r--r--. 1 root root 0 Mar 9 16:13 1.txt
-rw-r--r--. 1 root root 0 Mar 9 16:13 2.txt
-rw-r--r--. 1 root root 0 Mar 9 16:13 3.txt
-rw-r--r--. 1 root root 292 Mar 9 13:28 oldboy.txt
[root@oldboy data]# find /root/data -type f -name "*.txt"|xargs rm -f
[root@oldboy data]# ll
total 0
【说明】:
1、按修改时间查找文件,+7表示距今天7天以前,7表示距今天整7天,-7表示最近7天
2、-o表示或者的意思,-a表示并且的意思,!表示取反
12. 【命令】:grep
【功能说明】:
print lines matching a pattern #用于过滤、搜索特定字符
【语法格式】:
grep [OPTIONS] PATTERN [FILE...]
grep [OPTIONS] [-e PATTERN | -f FILE] [FILE...]
【选项参数】:
参数 |
说明 |
简解 |
-a, --text |
Process a binary file as if it were text; this is equivalent to the --binary-files=text option. |
不要忽略二进制的数据 |
-A NUM , --after-context=NUM |
Print NUM lines of trailing context after matching lines. Places a line containing a group separator (described under --group-separator) between contiguous groups of matches. With the -o or --only-matching option, this has no effect and a warning is given. |
除了显示符合范本样式的那一列之外,并显示该行之后的内容 |
-b, --byte-offset |
Print the 0-based byte offset within the input file before each line of output. If -o (--only-matching) is specified, print the offset of the matching part itself. |
在显示符合样式的那一行之前,标示出该行第一个字符的编号 |
-B NUM, --before-context=NUM |
Print NUM lines of leading context before matching lines. Places a line containing a group separator (described under --group-separator) between contiguous groups of matches. With the -o or --only-matching option, this has no effect and a warning is given. |
除了显示符合样式的那一行之外,并显示该行之前的内容 |
-c, --count |
Suppress normal output; instead print a count of matching lines for each input file. With the -v, --invert-match option (see below), count non-matching lines. (-c is specified by POSIX.) |
计算符合样式的列数 |
-C NUM, -NUM, --context=NUM |
Print NUM lines of output context. Places a line containing a group separator (described under --group-separator) between contiguous groups of matches. With the -o or --only-matching option, this has no effect and a warning is given. |
除了显示符合样式的那一行之外,并显示该行之前后各n行内容 |
-d ACTION, --directories=ACTION |
If an input file is a directory, use ACTION to process it. By default, ACTION is read, i.e., read directories just as if they were ordinary files. If ACTION is skip, silently skip directories. If ACTION is recurse, read all files under each directory, recursively, following symbolic links only if they are on the command line. This is equivalent to the -r option. |
当指定要查找的是目录而非文件时,必须使用这项参数,否则grep指令将回报信息并停止动作。 |
-e PATTERN, --regexp=PATTERN |
Use PATTERN as the pattern. This can be used to specify multiple search patterns, or to protect a pattern beginning with a hyphen (-). (-e is specified by POSIX.) |
使用正则表达式 |
-E, --extended-regexp |
Interpret PATTERN as an extended regular expression (ERE, see below). (-E is specified by POSIX.) |
使用拓展的正则表达式 |
-f FILE, --file=FILE |
Obtain patterns from FILE, one per line. The empty file contains zero patterns, and therefore matches nothing. (-f is specified by POSIX.) |
指定规则文件,其内容含有一个或多个规则样式,让grep查找符合规则条件的文件内容,格式为每行一个规则样式。 |
-h, --no-filename |
Suppress the prefixing of file names on output. This is the default when there is only one file (or only standard input) to search. |
在显示符合样式的那一行之前,不标示该行所属的文件名称。 |
-H, --with-filename |
Print the file name for each match. This is the default when there is more than one file to search. |
在显示符合样式的那一行之前,表示该行所属的文件名称。 |
-i, --ignore-case |
Ignore case distinctions in both the PATTERN and the input files. (-i is specified by POSIX.) |
忽略字符大小写的差别。 |
-l, --files-with-matches |
Suppress normal output; instead print the name of each input file from which output would normally have been printed. The scanning will stop on the first match. (-l is specified by POSIX.) |
列出文件内容符合指定的样式的文件名称。 |
-L, --files-without-match |
Suppress normal output; instead print the name of each input file from which no output would normally have been printed. The scanning will stop on the first match. |
列出文件内容不符合指定的样式的文件名称。 |
-n, --line-number |
Prefix each line of output with the 1-based line number within its input file. (-n is specified by POSIX.) |
在显示符合样式的那一行之前,标示出该行的列数编号。 |
-q, --quiet, --silent |
Quiet; do not write anything to standard output. Exit immediately with zero status if any match is found, even if an error was detected. Also see the -s or --no-messages option. (-q is specified by POSIX.) |
不显示任何信息。 |
-r, --recursive |
Read all files under each directory, recursively, following symbolic links only if they are on the command line. This is equivalent to the -d recurse option. |
如果文件参数是目录,该选项将递归搜索该目录下的所有子目录和文件。同-R |
-s, --no-messages |
Suppress error messages about nonexistent or unreadable files. Portability note: unlike GNU grep, 7th Edition Unix grep did not conform to POSIX, because it lacked -q and its -s option behaved like GNU grep’s -q option. USG-style grep also lacked -q but its -s option behaved like GNU grep. Portable shell scripts should avoid both -q and -s and should redirect standard and error output to /dev/null instead. (-s is specified by POSIX.) |
不显示错误信息。 |
-v, --invert-match |
Invert the sense of matching, to select non-matching lines. (-v is specified by POSIX.) |
显示不包含匹配文本的所有行。 |
-V, --version |
Print the version number of grep to the standard output stream. This version number should be included in all bug reports (see below). |
显示版本信息。 |
-w, --word-regexp |
Select only those lines containing matches that form whole words. The test is that the matching substring must either be at the beginning of the line, or preceded by a non-word constituent character. Similarly, it must be either at the end of the line or followed by a non-word constituent character. Word- constituent characters are letters, digits, and the underscore. |
只显示完整单词的匹配 |
-x, --line-regexp |
Select only those matches that exactly match the whole line. (-x is specified by POSIX.) |
只显示完整行的匹配 |
【示例】:
1、基本用法:显示文件中包含字符串的行
[root@oldboy ~]# cat oldboy.txt
test
liyao
oldboy
[root@oldboy ~]# grep "oldboy" oldboy.txt
oldboy
[root@oldboy ~]#
2、基本用法:显示文件中不包含字符串的行
[root@oldboy ~]# grep -v "oldboy" oldboy.txt
test
liyao
3、除了显示匹配的一行外,并显示该行之后的n行
[root@oldboy ~]# grep 20 -A 10 test.txt
20
21
22
23
24
25
26
27
28
29
30
【说明】:
grep的正则表达式:
^ #锚定行的开始 如:'^grep'匹配所有以grep开头的行。
$ #锚定行的结束 如:'grep$'匹配所有以grep结尾的行。
. #匹配一个非换行符的字符 如:'gr.p'匹配gr后接一个任意字符,然后是p。
* #匹配零个或多个先前字符 如:'*grep'匹配所有一个或多个空格后紧跟grep的行。
.* #一起用代表任意字符。
[] #匹配一个指定范围内的字符,如'[Gg]rep'匹配Grep和grep。
[^] #匹配一个不在指定范围内的字符,如:'[^A-FH-Z]rep'匹配不包含A-R和T-Z的一个字母开头,紧跟rep的行。
\(..\) #标记匹配字符,如'\(love\)',love被标记为1。
\< #锚定单词的开始,如:'\<grep'匹配包含以grep开头的单词的行。
\> #锚定单词的结束,如'grep\>'匹配包含以grep结尾的单词的行。
x\{m\} #重复字符x,m次,如:'0\{5\}'匹配包含5个o的行。
x\{m,\} #重复字符x,至少m次,如:'o\{5,\}'匹配至少有5个o的行。
x\{m,n\} #重复字符x,至少m次,不多于n次,如:'o\{5,10\}'匹配5--10个o的行。
\w #匹配文字和数字字符,也就是[A-Za-z0-9],如:'G\w*p'匹配以G后跟零个或多个文字或数字字符,然后是p。
\W #\w的反置形式,匹配一个或多个非单词字符,如点号句号等。
\b #单词锁定符,如: '\bgrep\b'只匹配grep。
POSIX字符:
为了在不同国家的字符编码中保持一至,POSIX(The Portable Operating System Interface)增加了特殊的字符类,如[:alnum:]是[A-Za-z0-9]的另一个写法。要把它们放到[]号内才能成为正则表达式,如[A- Za-z0-9]或[[:alnum:]]。在linux下的grep除fgrep外,都支持POSIX的字符类。
[:alnum:] #文字数字字符
[:alpha:] #文字字符
[:digit:] #数字字符
[:graph:] #非空字符(非空格、控制字符)
[:lower:] #小写字符
[:cntrl:] #控制字符
[:print:] #非空字符(包括空格)
[:punct:] #标点符号
[:space:] #所有空白字符(新行,空格,制表符)
[:upper:] #大写字符
[:xdigit:] #十六进制数字(0-9,a-f,A-F)
13. 【命令】:head
【功能说明】:
output the first part of files #打印文件的前几行
【语法格式】:
head [OPTION]... [FILE]...
【选项参数】:
参数 |
说明 |
简解 |
-c, --bytes=[-]K |
print the first K bytes of each file; with the leading ‘-’,print all but the last K bytes of each file |
按前K字节打印文件 |
-n, --lines=[-]K |
print the first K lines instead of the first 10; with the leading ‘-’, print all but the last K lines of each file |
按前K行打印文件 |
-q, --quiet, --silent |
never print headers giving file names |
隐藏文件名 |
-v, --verbose |
always print headers giving file names |
显示文件名 |
【示例】:
1、基本用法:打印文件前几行
[root@oldboy ~]# head -n 13 test.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
2、打印文件前K个字节
[root@oldboy ~]# head -c 20 test.txt
1
2
3
4
5
6
7
8
9
10[root@oldboy ~]#
3、显示文件名
[root@oldboy ~]# head -v test.txt
==> test.txt <==
1
2
3
4
5
6
7
8
9
10
14. 【命令】:cp
【功能说明】:
copy files and directories #复制文件或目录
【语法格式】:
cp [OPTION]... [-T] SOURCE DEST
cp [OPTION]... SOURCE... DIRECTORY
cp [OPTION]... -t DIRECTORY SOURCE...
【选项参数】:
参数 |
说明 |
简解 |
-a, --archive |
same as -dR --preserve=all |
保持源文件的原有结构和属性,与选项“-dpR”相同 |
--backup[=CONTROL] |
make a backup of each existing destination file |
做一个已存在文件的备份 |
-b |
like --backup but does not accept an argument |
覆盖已存在的目标文件前将目标文件备份 |
--copy-contents |
copy contents of special files when recursive |
|
-d |
same as --no-dereference --preserve=links |
如果复制的源文件是符号链接,仅复制符号链接本身,而且保留符号链接所指向的目标文件或目录 |
-f, --force |
if an existing destination file cannot be opened, remove it and try again (redundant if the -n option is used) |
强制覆盖已经存在的目标文件,不提示用户确认 |
-i, --interactive |
prompt before overwrite (overrides a previous -n option) |
在覆盖已存在的目标文件前提示用户进行确认 |
-H |
follow command-line symbolic links in SOURCE |
|
-l, --link |
link files instead of copying |
为源文件创建硬链接 |
-L, --dereference |
always follow symbolic links in SOURCE |
|
-n, --no-clobber |
do not overwrite an existing file (overrides a previous -i option) |
|
-P, --no-dereference |
never follow symbolic links in SOURCE |
|
-p |
same as --preserve=mode,ownership,timestamps |
复制文件时保持源文件的所有者、权限信息以及时间属性 |
--preserve[=ATTR_LIST] |
preserve the specified attributes (default: mode,owner-ship,timestamps), if possible additional attributes: context, links, xattr, all |
|
-c |
same as --preserve=context |
|
--no-preserve=ATTR_LIST |
don’t preserve the specified attributes |
|
--parents |
use full source file name under DIRECTORY |
|
-R, -r, --recursive |
copy directories recursively |
对目录进行复制操作,采用递归的操作方式 |
--reflink[=WHEN] |
control clone/CoW copies. See below. |
|
--remove-destination |
remove each existing destination file before attempting to open it (contrast with --force) |
|
--sparse=WHEN |
control creation of sparse files. See below. |
|
--strip-trailing-slashes |
remove any trailing slashes from each SOURCE argument |
|
-s, --symbolic-link |
make symbolic links instead of copying |
为源文件创建符号链接 |
-S, --suffix=SUFFIX |
override the usual backup suffix |
在备份文件时,用指定的后缀“SUFFIX”代替文件名的默认后缀 |
-t, --target-directory=DIRECTORY |
copy all SOURCE arguments into DIRECTORY |
|
-T, --no-target-directory |
treat DEST as a normal file |
|
-u, --update |
copy only when the SOURCE file is newer than the destination file or when the destination file is missing |
当目标文件不存在或者源文件比目标文件新时才进行复制操作 |
-v, --verbose |
explain what is being done |
详细显示指令执行的操作 |
-x, --one-file-system |
stay on this file system |
复制的文件或目录存放的文件系统,必须与cp指令执行时所处的文件系统相同,否则不复制,亦不处理位于其他分区的文件 |
-Z, --context=CONTEXT |
set security context of copy to CONTEXT |
【示例】:
1、基本用法:复制文件到指定位置
[root@oldboy ~]# cp test.txt data
[root@oldboy ~]# cat data/test.txt
1
2
3
4
5
6
7
2、基本用法:复制目录到指定位置
[root@oldboy ~]# cp -r /root/data /tmp
[root@oldboy ~]# cd /tmp/data
[root@oldboy data]#
3、复制时保持文件属性
[root@oldboy ~]# ll
total 56
-rw-------. 1 root root 1079 Mar 3 23:14 anaconda-ks.cfg
drwxr-xr-x. 7 root root 4096 Mar 13 16:25 data
-rw-r--r--. 1 root root 22179 Mar 3 23:14 install.log
-rw-r--r--. 1 root root 5890 Mar 3 23:13 install.log.syslog
-rw-r--r--. 1 root root 44 Mar 7 17:53 log2.txt
-rw-r--r--. 1 root root 18 Mar 9 13:19 oldboy.txt
-rw-r--r--. 1 root root 292 Mar 13 15:13 test.txt
[root@oldboy ~]# cp -p test.txt /tmp
[root@oldboy ~]# ll /tmp
total 108
drwxr-xr-x 7 root root 4096 Mar 13 16:28 data
-rw-r--r-- 1 root root 292 Mar 13 15:13 test.txt
-rw-------. 1 root root 0 Mar 3 23:09 yum.log
-rw-------. 1 root root 100203 Mar 4 00:39 yum_save_tx-2016-03-04-00-39i_5ZVm.yumtx
15. 【命令】:tail
【功能说明】:
output the last part of files #打印文件末尾几行
【语法格式】:
tail [OPTION]... [FILE]...
【选项参数】:
参数 |
说明 |
简解 |
-c, --bytes=K |
output the last K bytes; alternatively, use -c +K to output bytes starting with the Kth of each file |
输出文件尾部的N个字节内容 |
-f, --follow[={name|descriptor}] |
output appended data as the file grows; -f, --follow, and --follow=descriptor are equivalent |
显示文件最新追加的内容 |
-F |
same as --follow=name --retry |
与选项“--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 |
输出文件尾部K行内容 |
--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. |
参看texinfo文档(默认为5) |
--pid=PID |
with -f, terminate after process ID, PID dies |
与-f合用,表示在进程ID,PID死掉之后结束 |
-q, --quiet, --silent |
never output headers giving file names |
不显示文件名 |
--retry |
keep trying to open a file even when it is or becomes inacces-sible; 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. |
与“-f”连用,指定监视文件变化时间所间隔的秒数 |
-v, --verbose |
always output headers giving file names |
总在开头显示文件名 |
【示例】:
1、基本用法:显示文件末尾的n行
[root@oldboy ~]# tail -8 test.txt
93
94
95
96
97
98
99
100
2、在开头显示文件名
[root@oldboy ~]# tail -v -n 8 test.txt
==> test.txt <==
93
94
95
96
97
98
99
100
16. 【命令】:alias
【功能说明】:
Define or display aliases. #显示或设置别名
【语法格式】:
alias [-p] [name[=value] ... ]
【选项参数】:
参数 |
说明 |
简解 |
-p |
Print all defined aliases in a reusable format |
打印已经设置的命令别名 |
【示例】:
1、基本用法:打印已经设置的别名(-p可以省略)
[root@oldboy ~]# alias -p
alias cp='cp -i'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
2、基本用法:设置新别名
[root@oldboy ~]# alias rm='echo "Do not use rm!"'
[root@oldboy ~]# rm -f test.txt
Do not use rm! -f test.txt
[root@oldboy ~]# alias
alias cp='cp -i'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='echo "Do not use rm!"'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
17. 【命令】:unalias
【功能说明】:
Remove each NAME from the list of defined aliases. #取消别名
【语法格式】:
unalias [-a] name [name ...]
【选项参数】:
参数 |
说明 |
简解 |
-a |
remove all alias definitions. |
取消所有别名 |
【示例】:
1、基本用法:取消别名
[root@oldboy ~]# alias
alias cp='cp -i'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='echo "Do not use rm!"'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
[root@oldboy ~]# unalias rm
[root@oldboy ~]# alias
alias cp='cp -i'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
2、取消所有别名
[root@oldboy ~]# alias
alias cp='cp -i'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
[root@oldboy ~]# unalias -a
[root@oldboy ~]# alias
[root@oldboy ~]#
18. 【命令】:seq
【功能说明】:
print a sequence of numbers #生成数字序列
【语法格式】:
seq [OPTION]... LAST
seq [OPTION]... FIRST LAST
seq [OPTION]... FIRST INCREMENT LAST
【选项参数】:
参数 |
说明 |
简解 |
-f, --format=FORMAT |
use printf style floating-point FORMAT |
格式化输出 |
-s, --separator=STRING |
use STRING to separate numbers (default: \n) |
指定分隔符,默认是换行符 |
-w, --equal-width |
equalize width by padding with leading zeroes |
输出同宽数列,不足的位数用0补齐 |
【示例】:
1、基本用法:生成数字序列
[root@oldboy ~]# seq 10
1
2
3
4
5
6
7
8
9
10
2、格式化输出
[root@oldboy ~]# seq -f 100%g 10
1001
1002
1003
1004
1005
1006
1007
1008
1009
10010
3、指定分隔符
[root@oldboy ~]# seq -s "..." 10
1...2...3...4...5...6...7...8...9...10
[root@oldboy ~]#
4、输出同宽数列
[root@oldboy ~]# seq -w 10
01
02
03
04
05
06
07
08
09
10
19. 【命令】:sed
【功能说明】:
stream editor for filtering and transforming text #用于过滤和转化文本的流编辑器
【语法格式】:
sed [OPTION]... {script-only-if-no-other-script} [input-file]...
【选项参数】:
参数 |
说明 |
简解 |
-n, --quiet, --silent |
suppress automatic printing of pattern space |
取消默认输出,只显示操作过的那一行 |
-e script, --expression=script |
add the script to the commands to be executed |
直接在命令列模式上进行sed的动作编辑 |
-f script-file, --file=script-file |
add the contents of script-file to the commands to be executed |
运行脚本内的动作 |
--follow-symlinks |
follow symlinks when processing in place; hard links will still be broken |
|
-i[SUFFIX], --in-place[=SUFFIX] |
edit files in place (makes backup if extension supplied). The default operation mode is to break symbolic and hard links.This can be changed with --follow-symlinks and --copy |
直接修改读取的文件内容 |
-c, --copy |
use copy instead of rename when shuffling files in -i mode. While this will avoid breaking links (symbolic or hard), the resulting editing operation is not atomic. This is rarely the desired mode; --follow-symlinks is usually enough, and it is both faster and more secure. |
|
-l N, --line-length=N |
specify the desired line-wrap length for the ‘l’ command |
|
--posix |
disable all GNU extensions. |
|
-r, --regexp-extended |
use extended regular expressions in the script |
在脚本中应用拓展的正则表达式 |
-s, --separate |
consider files as separate rather than as a single continuous long stream |
|
-u, --unbuffered |
load minimal amounts of data from the input files and flush the output buffers more often |
【示例】:
1、基本用法:仅列出 /etc/passwd 文件内的第 5-7 行
[root@oldboy ~]# nl /etc/passwd | sed -n '5,7p'
5 lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
6 sync:x:5:0:sync:/sbin:/bin/sync
7 shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
2、利用sed替换取IP地址
[root@oldboy ~]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:9C:9A:32
inet addr:10.0.0.8 Bcast:10.0.0.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe9c:9a32/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:641 errors:0 dropped:0 overruns:0 frame:0
TX packets:321 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:56546 (55.2 KiB) TX bytes:40576 (39.6 KiB)
[root@oldboy ~]# /sbin/ifconfig eth0 | grep 'inet addr' | sed 's#^.*addr:##g' | sed 's#Bcast.*$##g'
10.0.0.8
3、直接修改文件内容
[root@oldboy ~]# cat test.txt
1
2
3
4
5
6
7
8
9
10
[root@oldboy ~]# sed -i 's#5#500#g' test.txt
[root@oldboy ~]# cat test.txt
1
2
3
4
500
6
7
8
9
10
【特别说明】:
动作说明: [n1[,n2]]function
n1, n2 :不见得会存在,一般代表『选择进行动作的行数』,举例来说,如果我的动作是需要在 10 到 20 行之间进行的,则『 10,20[动作行为] 』
function:
a :新增, a 的后面可以接字串,而这些字串会在新的一行出现(目前的下一行)~
c :取代, c 的后面可以接字串,这些字串可以取代 n1,n2 之间的行!
d :删除,因为是删除啊,所以 d 后面通常不接任何咚咚;
i :插入, i 的后面可以接字串,而这些字串会在新的一行出现(目前的上一行);
p :打印,亦即将某个选择的数据印出。通常 p 会与参数 sed -n 一起运行~
s :取代,可以直接进行取代的工作哩!通常这个 s 的动作可以搭配正则表达式!例如 1,20s#old#new#g 就是啦!
20. 【命令】:man
【功能说明】:
format and display the on-line manual pages #查看在线帮助手册
【语法格式】:
man [-acdDfFhkKtwW] [--path] [-m system] [-p string] [-C config_file]
[-M pathlist] [-P pager] [-B browser] [-H htmlpager] [-S sec-
tion_list] [section] name ...
【选项参数】:
参数 |
说明 |
简解 |
【示例】:
1、基本用法:查看在线帮助
[root@oldboy ~]# man ls
LS(1) User Commands LS(1)
NAME
ls - list directory contents
SYNOPSIS
ls [OPTION]... [FILE]...
以下省略
21. 【命令】:useradd
【功能说明】:
create a new user or update default new user information #创建新用户或更新默认新用户的信息
【语法格式】:
useradd [options] LOGIN
useradd -D
useradd -D [options]
【选项参数】:
参数 |
说明 |
简解 |
-c, --comment COMMENT |
Any text string. It is generally a short description of the login, and is currently used as the field for the user's full name. |
加上备注文字 |
-d, --home HOME_DIR |
The new user will be created using HOME_DIR as the value for the user's login directory. The default is to append the LOGIN name to BASE_DIR and use that as the login directory name. The parent directory of HOME_DIR must exist otherwise the home directory cannot be created. |
指定用户登入时的起始目录 |
-D, defaults |
See below, the subsection "Changing the default values". |
变更预设值 |
-e, --expiredate EXPIRE_DATE |
The date on which the user account will be disabled. The date is specified in the format YYYY-MM-DD. If not specified, useradd will use the default expiry date specified by the EXPIRE variable in /etc/default/useradd, or an empty string (no expiry) by default. |
指定账号的有效期限 |
-f, --inactive INACTIVE |
The number of days after a password expires until the account is permanently disabled. A value of 0 disables the account as soon as the password has expired, and a value of -1 disables the feature. If not specified, useradd will use the default inactivity period specified by the INACTIVE variable in /etc/default/useradd, or -1 by default. |
指定在密码过期后多少天即关闭该账号 |
-g, --gid GROUP |
The group name or number of the user's initial login group. The group name must exist. A group number must refer to an already existing group. |
指定用户所属的群组 |
-G, --groups GROUP1[,GROUP2,...[,GROUPN]]] |
A list of supplementary groups which the user is also a member of. Each group is separated from the next by a comma, with no intervening whitespace. The groups are subject to the same restrictions as the group given with the -g option. The default is for the user to belong only to the initial group. |
指定用户所属的附加群组 |
-m, --create-home |
Create the user's home directory if it does not exist. The files and directories contained in the skeleton directory (which can be defined with the -k option) will be copied to the home directory. |
自动建立用户的登入目录 |
-M |
Do not create the user's home directory, even if the system wide setting from /etc/login.defs (CREATE_HOME) is set to yes. |
不要自动建立用户的登入目录 |
-N, --no-user-group |
Do not create a group with the same name as the user, but add the user to the group specified by the -g option or by the GROUP variable in /etc/default/useradd. |
取消建立以用户名称为名的群组 |
-r, --system |
Create a system account. |
建立系统账号 |
-s, --shell SHELL |
The name of the user's login shell. The default is to leave this field blank, which causes the system to select the default login shell specified by the SHELL variable in /etc/default/useradd, or an empty string by default. |
指定用户登入后使用的shell |
-u, --uid UID |
The numerical value of the user's ID. This value must be unique, unless the -o option is used. The value must be non-negative. The default is to use the smallest ID value greater than or equal to UID_MIN and greater than every other user. |
指定用户ID |
【示例】:
1、基本用法:创建新用户
[root@oldboy ~]# useradd test
[root@oldboy ~]# cat /etc/passwd|tail -1
test:x:501:501::/home/test:/bin/bash
22. 【命令】:passwd
【功能说明】:
update user’s authentication tokens #为用户设置或修改密码
【语法格式】:
passwd [-k] [-l] [-u [-f]] [-d] [-e] [-n mindays] [-x
maxdays] [-w warndays] [-i inactivedays] [-S] [--stdin]
[username]
【选项参数】:
参数 |
说明 |
简解 |
-d |
This is a quick way to delete a password for an account. It will set the named account password-less. Available to root only. |
删除密码,仅有系统管理者才能使用 |
-k |
The option -k, is used to indicate that the update should only be for expired authentication tokens (passwords); the user wishes to keep their non-expired tokens as before. |
设置只有在密码过期失效后,方能更新 |
-l |
This option is used to lock the specified account and it is available to root only. The locking is performed by rendering the encrypted password into an invalid string (by prefixing the encrypted string with an !). |
锁住密码 |
-S |
This will output a short information about the status of the password for a given account.Available to root user only. |
列出密码的相关信息,仅有系统管理者才能使用 |
-u |
This is the reverse of the -l option - it will unlock the account password by removing the !prefix. This option is available to root only. By default passwd will refuse to create a password-less account (it will not unlock an account that has only "!" as a password). The force option -f will override this protection. |
解开已上锁的账号 |
【示例】:
1、基本用法:设置用户密码
[root@oldboy ~]# passwd oldboy
Changing password for user oldboy.
New password:
BAD PASSWORD: it is too simplistic/systematic
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.
23. 【命令】:uname
【功能说明】:
print system information #打印系统信息
【语法格式】:
uname [OPTION]...
【选项参数】:
参数 |
说明 |
简解 |
-a, --all |
print all information, in the following order, except omit -p and -i if unknown: |
显示全部的信息 |
-s, --kernel-name |
print the kernel name |
显示操作系统类型 |
-n, --nodename |
print the network node hostname |
显示主机名 |
-r, --kernel-release |
print the kernel release |
显示核心版本号 |
-v, --kernel-version |
print the kernel version |
显示操作系统的版本 |
-m, --machine |
print the machine hardware name |
显示机器架构类型 |
-p, --processor |
print the processor type or "unknown" |
|
-i, --hardware-platform |
print the hardware platform or "unknown" |
显示硬件平台 |
-o, --operating-system |
print the operating system |
显示操作系统 |
【示例】:
1、基本用法:显示全部信息
[root@oldboy ~]# uname -a
Linux oldboy 2.6.32-573.el6.x86_64 #1 SMP Thu Jul 23 15:44:03 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
2、基本用法:显示主机名
[root@oldboy ~]# uname -n
oldboy
3、显示核心版本号
[root@oldboy ~]# uname -r
2.6.32-573.el6.x86_64
4、显示机器架构类型
[root@oldboy ~]# uname -m
x86_64
24. 【命令】:hostname
【功能说明】:
show or set the system’s host name #显示和设置主机名
【语法格式】:
hostname [-v] [-a] [--alias] [-d] [--domain] [-f]
[--fqdn] [-A] [--all-fqdns] [-i] [--ip-address] [-I]
[--all-ip-addresses] [--long] [-s] [--short] [-y] [--yp]
[--nis]
hostname [-v] [-F filename] [--file filename] [hostname]
【选项参数】:
参数 |
说明 |
简解 |
-v, --verbose |
Be verbose and tell what’s going on. |
详细信息模式 |
-a, --alias |
Display the alias name of the host (if used) |
显示主机别名 |
-d, --domain |
Display the name of the DNS domain. Don’t use the command domainname to get the DNS domain name because it will show the NIS domain name and not the DNS domain name. Use dnsdomainname instead. |
显示DNS域名 |
-f, --fqdn, --long |
Display the FQDN (Fully Qualified Domain Name). A FQDN consists of a short host name and the DNS domain name. Unless you are using bind or NIS for host lookups you can change the FQDN and the DNS domain name (which is part of the FQDN) in the /etc/hosts file. See the warnings in section THE FQDN above, and avoid using this option; use hostname --all-fqdns instead |
显示FQDN名称 |
-i, --ip-address |
Display the IP address(es) of the host. Note that this works only if the host name can be resolved. Avoid using this option; use hostname --all-ip- addresses instead |
显示主机的ip地址 |
-s, --short |
Display the short host name. This is the host name cut at the first dot. |
显示短主机名称,在第一个点处截断 |
-y, --yp, --nis |
Display the NIS domain name. If a parameter is given (or --file name ) then root can also set a new NIS domain |
显示NIS域名 |
【示例】:
1、基本用法:显示主机名
[root@oldboy ~]# hostname
oldboy
2、基本用法:修改主机名
[root@oldboy ~]# hostname oldgirl
[root@oldboy ~]# hostname
oldgirl
25. 【命令】:runlevel
【功能说明】:
output previous and current runlevel #查看系统运行状态
【语法格式】:
runlevel [OPTION]... [UTMP]
【选项参数】:
参数 |
说明 |
简解 |
--quiet |
Does not output the current and previous run-level, nor does it output unknown in the case of error (but it will exit with an error code). This may be used to test for the presence of a runlevel entry, or to check for errors reading from the file. |
不显示当前运行状态 |
【示例】:
1、基本用法:查看系统运行状态
[root@oldboy ~]# runlevel
N 3
26. 【命令】:init
【功能说明】:
Upstart process management daemon #设置系统运行状态
【语法格式】:
init [OPTION]...
【选项参数】:
参数 |
说明 |
简解 |
-v, --verbose |
Outputs verbose messages about job state changes and event emissions to the system console or log,useful for debugging boot. |
显示详细信息 |
-q, --quiet |
reduce output to errors only |
只显示错误 |
【示例】:
1、基本用法:关机
[root@oldboy ~]# init 0
2、基本用法:重启
[root@oldboy ~]# init 6
27. 【命令】:shutdown
【功能说明】:
bring the system down #关机
【语法格式】:
shutdown [OPTION]... TIME [MESSAGE]
【选项参数】:
参数 |
说明 |
简解 |
-r |
Requests that the system be rebooted after it has been brought down |
重启系统 |
-h |
Requests that the system be either halted or pow-ered off after it has been brought down, with the choice as to which left up to the system. |
关机 |
-H |
Requests that the system be halted after it has been brought down |
|
-P |
Requests that the system be powered off after it has been brought down. |
|
-c |
Cancels a running shutdown. TIME is not specified with this option, the first argument is MES-SAGE. |
当执行“shutdown -h 11:50”指令时,只要按+键就可以中断关机的指令 |
-k |
Only send out the warning messages and disable logins, do not actually bring the system down |
只发送警告信息,不真关机 |
【示例】:
1、基本用法:立即关机
[root@oldboy ~]# shutdown -h now
2、指定12点关机
[root@oldboy ~]# shutdown -h 12:00
Broadcast message from root@oldboy
(/dev/pts/0) at 11:54 ...
The system is going down for halt in 6 minutes!
28. 【命令】:reboot
【功能说明】:
reboot the system #重启系统
【语法格式】:
reboot [OPTION]...
【选项参数】:
参数 |
说明 |
简解 |
-f, --force |
Does not invoke shutdown(8) and instead performs the actual action you would expect from the name. |
强制重新开机 |
-p, --poweroff |
Instructs the halt command to instead behave as poweroff |
|
-w, --wtmp-only |
Does not call shutdown(8) or the reboot(2) system call and instead only writes the shutdown record to /var/log/wtmp |
仅做测试,并不真正将系统重新开机,只会把重开机的数据写入/var/log目录下的wtmp记录文件。 |
--verbose |
Outputs slightly more verbose messages when rebooting, useful for debugging problems with shutdown. |
|
-n, --no-sync |
don't sync before reboot or halt |
【示例】:
1、基本用法:重启系统
[root@oldboy ~]# reboot
29. 【命令】:history
【功能说明】:
Display or manipulate the history list. #查看命令历史
【语法格式】:
history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg [arg...]
【选项参数】:
参数 |
说明 |
简解 |
-c |
clear the history list by deleting all of the entries |
清空当前历史命令 |
-d |
offset delete the history entry at offset OFFSET |
|
-a |
append history lines from this session to the history file |
将历史命令缓冲区中命令写入历史命令文件中 |
-n |
read all history lines not already read from the history file |
|
-r |
read the history file and append the contents to the history list |
将历史命令文件中的命令读入当前历史命令缓冲区 |
-w |
write the current history to the history file and append them to the history list |
|
-p |
perform history expansion on each ARG and display the result without storing it in the history list |
|
-s |
append the ARGs to the history list as a single entry |
【示例】:
1、基本用法:查看命令历史
[root@oldboy ~]# history
1 cd /usr/local/
2 cd ..
3 pwd
4 cd ../..
5 cd -
6 cd ~
7 cd /
8 ll
9 ls -la
......
30. 【命令】:dmesg
【功能说明】:
print or control the kernel ring buffer #查看系统故障信息
【语法格式】:
dmesg [-c] [-r] [-n level] [-s bufsize]
【选项参数】:
参数 |
说明 |
简解 |
-c |
Clear the ring buffer contents after printing. |
显示信息后,清除ring buffer中的内容 |
-r |
Print the raw message buffer, i.e., don’t strip the log level prefixes. |
|
-s bufsize |
Use a buffer of size bufsize to query the kernel ring buffer. This is 16392 by default. (The default kernel syslog buffer size was 4096 at first, 8192 since 1.3.54, 16384 since 2.1.113.) If you have set the kernel buffer to be larger than the default then this option can be used to view the entire buffer |
设置ring buffer大小,预设置为8196,刚好等于ring buffer的大小 |
-n level |
Set the level at which logging of messages is done to the console. For example, -n 1 prevents all messages, except panic messages, from appear-ing on the console. All levels of messages are still written to /proc/kmsg, so syslogd(8) can still be used to control exactly where kernel messages appear. When the -n option is used,dmesg will not print or clear the kernel ring buffer |
设置记录信息的层级 |
【示例】:
1、基本用法:查看信息
[root@oldboy ~]# dmesg
Initializing cgroup subsys cpuset
Initializing cgroup subsys cpu
Linux version 2.6.32-573.el6.x86_64 (mockbuild@c6b9.bsys.dev.centos.org) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC) ) #1 SMP Thu Jul 23 15:44:03 UTC 2015
Command line: ro root=UUID=8fc55236-ce36-4cc4-9924-202ed5142065 rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
31. 【命令】:ifup、ifdown
【功能说明】:
ifup - bring a network interface up #开启网卡
ifdown - take a network interface down #关闭网卡
【语法格式】:
ifup IFACE [boot]
ifdown IFACE
【选项参数】:
参数 |
说明 |
简解 |
【示例】:
1、基本用法:关闭、开启网卡
[root@oldboy ~]# ifdown eth0
[root@oldboy ~]# ifup eth0
Determining if ip address 10.0.0.8 is already in use for device eth0...
32. 【命令】:nl
【功能说明】:
number lines of files #显示文件行号
【语法格式】:
nl [OPTION]... [FILE]...
【选项参数】:
参数 |
说明 |
简解 |
-b, --body-numbering=STYLE |
use STYLE for numbering body lines |
指定行号指定的方式,主要有两种: -b a :表示不论是否为空行,也同样列出行号(类似 cat -n); -b t :如果有空行,空的那一行不要列出行号(默认值); |
-d, --section-delimiter=CC |
use CC for separating logical pages |
|
-f, --footer-numbering=STYLE |
use STYLE for numbering footer lines |
|
-h, --header-numbering=STYLE |
use STYLE for numbering header lines |
|
-i, --line-increment=NUMBER |
line number increment at each line |
|
-l, --join-blank-lines=NUMBER |
group of NUMBER empty lines counted as one |
|
-n, --number-format=FORMAT |
insert line numbers according to FORMAT |
列出行号表示的方法,主要有三种: -n ln :行号在萤幕的最左方显示; -n rn :行号在自己栏位的最右方显示,且不加 0 ; -n rz :行号在自己栏位的最右方显示,且加 0 ; |
-p, --no-renumber |
do not reset line numbers at logical pages |
在逻辑定界符处不重新开始计算 |
-s, --number-separator=STRING |
add STRING after (possible) line number |
|
-v, --starting-line-number=NUMBER |
first line number on each logical page |
|
-w, --number-width=NUMBER |
use NUMBER columns for line numbers |
行号栏位的占用的位数 |
【示例】:
1、基本用法:显示行号(默认空行不显示)
[root@oldboy ~]# nl test.txt
1 10
2 14
3 99
4 8a1
5 69
2、显示行号(空行也显示)
[root@oldboy ~]# nl -b a test.txt
1 10
2 14
3 99
4
5
6
7 8a1
8 69
3、让行号前自动补上0,统一输出格式
[root@oldboy ~]# nl -b a -n rz test.txt
000001 10
000002 14
000003 99
000004
000005
000006
000007 8a1
000008 69
4、调整统一输出格式为三位数字
[root@oldboy ~]# nl -b a -n rz -w 3 test.txt
001 10
002 14
003 99
004
005
006
007 8a1
008 69
33. 【命令】:less
【功能说明】:
opposite of more #分屏查看文本(可回退)
【语法格式】:
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]...
【选项参数】:
参数 |
说明 |
简解 |
-bn |
Specifies the amount of buffer space less will use for each file, in units of kilobytes (1024 bytes). By default 64K of buffer space is used for each file (unless the file is a pipe; see the -B option). The -b option specifies instead that n kilobytes of buffer space should be used for each file. If n is -1, buffer space is unlimited; that is, the entire file can be read into memory. |
设置缓冲区的大小 |
-e |
Causes less to automatically exit the second time it reaches end-of-file. By default, the only way to exit less is via the "q" command. |
当文件显示结束后,自动离开 |
-f |
Forces non-regular files to be opened. (A non-regular file is a directory or a device special file.) Also suppresses the warning message when a binary file is opened. By default, less will refuse to open non-regular files. Note that some operating systems will not allow directories to be read, even if -f is set |
强迫打开特殊文件,例如外围设备代号、目录和二进制文件 |
-g |
Normally, less will highlight ALL strings which match the last search command. The -g option changes this behavior to highlight only the particular string which was found by the last search command. This can cause less to run somewhat faster than the default |
只标志最后搜索的关键词 |
-i |
Causes searches to ignore case; that is, uppercase and lowercase are considered identical. This option is ignored if any uppercase letters appear in the search pattern; in other words, if a pattern contains uppercase letters, then that search does not ignore case |
忽略搜索时的大小写 |
-m |
Causes less to prompt verbosely (like more), with the percent into the file. By default, less prompts with a colon |
显示类似more命令的百分比 |
-N |
Causes a line number to be displayed at the beginning of each line in the display. |
显示每行的行号 |
-ofilename |
Causes less to copy its input to the named file as it is being viewed. This applies only when the input file is a pipe, not an ordinary file. If the file already exists, less will ask for confirmation before overwriting it |
将less 输出的内容在指定文件中保存起来 |
-Q |
Causes totally "quiet" operation: the terminal bell is never rung. |
不使用警告音 |
-s |
Causes consecutive blank lines to be squeezed into a single blank line. This is useful when viewing nroff output |
显示连续空行为一行 |
-S |
Causes lines longer than the screen width to be chopped rather than folded. That is, the portion of a long line that does not fit in the screen width is not shown. The default is to fold long lines; that is, display the remainder on the next line |
行过长时间将超出部分舍弃 |
-xn |
Sets tab stops. If only one n is specified, tab stops are set at multiples of n. If multiple values separated by commas are specified, tab stops are set at those positions, and then continue with the same spacing as the last two. For example, -x9,17 will set tabs at positions 9, 17,25, 33, etc. The default for n is 8 |
将“tab”键显示为规定的数字空格 |
【示例】:
1、基本用法:查看文件
[root@oldboy ~]# less test.txt
10
14
99
8a1
69
38
【特别说明】
1.全屏导航
ctrl + F - 向前移动一屏
ctrl + B - 向后移动一屏
ctrl + D - 向前移动半屏
ctrl + U - 向后移动半屏
2.单行导航
j - 向前移动一行
k - 向后移动一行
3.其它导航
G - 移动到最后一行
g - 移动到第一行
q / ZZ - 退出 less 命令
4.其它有用的命令
v - 使用配置的编辑器编辑当前文件
h - 显示 less 的帮助文档
&pattern - 仅显示匹配模式的行,而不是整个文件
5.标记导航
当使用 less 查看大文件时,可以在任何一个位置作标记,可以通过命令导航到标有特定标记的文本位置:
ma - 使用 a 标记文本的当前位置
'a - 导航到标记 a 处
34. 【命令】:more
【功能说明】:
file perusal filter for crt viewing #分屏查看文件(不可回退)
【语法格式】:
more [-dlfpcsu] [-num] [+/pattern] [+linenum] [file ...]
【选项参数】:
参数 |
说明 |
简解 |
+num |
Start at line number num |
从笫n行开始显示 |
-num |
This option specifies an integer which is the screen size (in lines) |
定义屏幕大小为n行 |
+/pattern |
The +/ option specifies a string that will be searched for before each file is displayed |
在每个档案显示前搜寻该字串(pattern),然后从该字串前两行之后开始显示 |
-c |
Do not scroll. Instead, paint each screen from the top, clearing the remainder of each line as it is displayed. |
从顶部清屏,然后显示 |
-d |
more will prompt the user with the message "[Press space to continue, ’q’ to quit.]" and will display"[Press ’h’ for instructions.]" instead of ringing the bell when an illegal key is pressed |
提示“Press space to continue,’q’ to quit(按空格键继续,按q键退出)”,禁用响铃功能 |
-l |
more usually treats ^L (form feed) as a special character, and will pause after any line that contains a form feed. The -l option will prevent this behavior. |
忽略Ctrl+l(换页)字符 |
-p |
Do not scroll. Instead, clear the whole screen and then display the text |
通过清除窗口而不是滚屏来对文件进行换页,与-c选项相似 |
-s |
Squeeze multiple blank lines into one. |
把连续的多个空行显示为一行 |
-u |
Suppress underlining |
把文件内容中的下画线去掉 |
【示例】:
1、基本用法:查看文件
[root@oldboy ~]# more test.txt
10
14
99
8a1
69
38
【特别说明】
Enter 向下n行,需要定义。默认为1行
Ctrl+F 向下滚动一屏
空格键 向下滚动一屏
Ctrl+B 返回上一屏
= 输出当前行的行号
:f 输出文件名和当前行的行号
V 调用vi编辑器
!命令 调用Shell,并执行命令
q 退出more
35. 【命令】:wc
【功能说明】:
print newline, word, and byte counts for each file #打印行数、字数
【语法格式】:
wc [OPTION]... [FILE]...
wc [OPTION]... --files0-from=F
【选项参数】:
参数 |
说明 |
简解 |
-c, --bytes |
print the byte counts |
打印字节数 |
-m, --chars |
print the character counts |
打印字符数 |
-l, --lines |
print the newline counts |
打印行数 |
--files0-from=F |
read input from the files specified by NUL-terminated names in file F; If F is - then read names from standard input |
|
-L, --max-line-length |
print the length of the longest line |
打印最长行的长度 |
-w, --words |
print the word counts |
打印单词数 |
【示例】:
1、基本用法:打印行数、单词数、字节数及文件名
[root@oldboy ~]# wc test.txt
9 6 22 test.txt
2、只打印统计数字不打印文件名
[root@oldboy ~]# cat test.txt|wc -l
9
36. 【命令】:chkconfig
【功能说明】:
updates and queries runlevel information for system services #管理开机自启动程序
【语法格式】:
chkconfig [--list] [--type type][name]
chkconfig --add name
chkconfig --del name
chkconfig --override name
chkconfig [--level levels] [--type type] name<on|off|reset|resetpriorities>
chkconfig [--level levels] [--type type] name
【选项参数】:
参数 |
说明 |
简解 |
--level levels |
Specifies the run levels an operation should pertain to. It is given as a string of numbers from 0 to 6. For example, --level 35 specifies run- levels 3 and 5 |
指定系统服务要在哪一个执行等级中开启或关毕 |
--add name |
This option adds a new service for management by chkconfig. When a new service is added, chkconfig ensures that the service has either a start or a kill entry in every runlevel. If any run-level is missing such an entry, chkconfig creates the appropriate entry as specified by the default values in the init script. Note that default entries in LSB-delimited ’INIT INFO’ sections take precedence over the default runlevels in the initscript; if any Required-Start or Required-Stop entries are present, the start and stop priorities of the script will be adjusted to account for these dependencies |
增加所指定的系统服务,让chkconfig指令得以管理它,并同时在系统启动的叙述文件内增加相关数据 |
--del name |
The service is removed from chkconfig management,and any symbolic links in /etc/rc[0-6].d which pertain to it are removed.Note that future package installs for this service may run chkconfig --add, which will re-add such links. To disable a service, run chkconfig name off. |
删除所指定的系统服务,不再由chkconfig指令管理,并同时在系统启动的叙述文件内删除相关数据 |
--list name |
This option lists all of the services which chkconfig knows about, and whether they are stopped or started in each runlevel. If name is specified, information in only display about service name. |
罗列所有服务在各执行等级上的开启、关闭情况 |
【示例】:
1、基本用法:查看所有服务在各执行等级上的开启、关闭情况
[root@oldboy ~]# chkconfig --list
abrt-ccpp 0:off 1:off 2:off 3:off 4:off 5:off 6:off
abrtd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
acpid 0:off 1:off 2:off 3:off 4:off 5:off 6:off
atd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
auditd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
blk-availability 0:off 1:on 2:off 3:off 4:off 5:off6:off
cpuspeed 0:off 1:on 2:off 3:off 4:off 5:off 6:off
crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off
haldaemon 0:off 1:off 2:off 3:off 4:off 5:off 6:off
......
2、基本用法:在指定执行等级上关闭(开启)一个服务
[root@oldboy ~]# chkconfig --level 2345 atd off
[root@oldboy ~]# chkconfig --list|grep "atd"
atd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
37. 【命令】:tar
【功能说明】:
manual page for tar 1.23 #打包命令
【语法格式】:
tar [OPTION...] [FILE]...
【选项参数】:
参数 |
说明 |
简解 |
-A |
append tar files to an archive |
新增压缩文件到已存在的压缩 |
-c |
create a new archive |
建立新的压缩文件 |
-d |
find differences between archive and file system |
记录文件的差别 |
-r |
append files to the end of an archive |
添加文件到已经压缩的文件结尾 |
-u |
only append files newer than copy in archive |
添加改变了和现有的文件到已经存在的压缩文件 |
-x |
extract files from an archive |
从压缩的文件中提取文件 |
-t |
list the contents of an archive |
显示压缩文件的内容 |
-z |
filter the archive through gzip |
支持gzip解压文件 |
-j |
filter the archive through bzip2 |
支持bzip2解压文件 |
-v |
verbosely list files processed |
显示操作过程 |
-W |
attempt to verify the archive after writing it |
确认压缩文件的正确性 |
-C |
change to directory DIR |
切换到指定目录 |
-f |
use archive file or device ARCHIVE |
指定压缩文件 |
【示例】:
1、基本用法:打包文件zcvf
[root@oldboy ~]# tar zcvf data.tar.gz ./data
./data/
./data/d.txt
./data/oldboy.txt
./data/dir5/
./data/dir1/
./data/test.txt
./data/c.txt
./data/dir2/
./data/dir3/
./data/dir4/
./data/e.txt
[root@oldboy ~]# ls
anaconda-ks.cfg install.log oldboy test.txt
data install.log.syslog oldboy.tar.gz
data.tar.gz log2.txt oldboy.txt
2、基本用法:解包zxvf
[root@oldboy tmp]# tar zxvf data.tar.gz
./data/
./data/d.txt
./data/oldboy.txt
./data/dir5/
./data/dir1/
./data/test.txt
./data/c.txt
./data/dir2/
./data/dir3/
./data/dir4/
./data/e.txt
[root@oldboy tmp]# ls
data data.tar.gz file1.txt file2.txt oldboy test.txt
3、批量排除打包
[root@oldboy opt]# cat paichu.log
stu05
stu06
stu07
[root@oldboy opt]# tar zcvfX paichuX.tar.gz paichu.log ./test
./test/
./test/stu03
./test/stu01
./test/stu02
./test/stu09
./test/stu08
./test/stu10
./test/stu04
[root@oldboy opt]# tar tf paichuX.tar.gz
./test/
./test/stu03
./test/stu01
./test/stu02
./test/stu09
./test/stu08
./test/stu10
./test/stu04
38. 【命令】:cut
【功能说明】:
remove sections from each line of files #
【语法格式】:
cut OPTION... [FILE]...
【选项参数】:
参数 |
说明 |
简解 |
-b, --bytes=LIST |
select only these bytes |
以字节为单位进行分割 |
-c, --characters=LIST |
select only these characters |
以字符为单位进行分割 |
-d, --delimiter=DELIM |
use DELIM instead of TAB for field delimiter |
自定义分隔符,默认为制表符 |
-f, --fields=LIST |
select only these fields; also print any line that contains no delimiter character, unless the -soption is specified |
与-d一起使用,指定显示哪个区域 |
-n |
with -b: don’t split multibyte characters |
取消分割多字节字符仅和 -b 标志一起使用。如果字符的最后一个字节落在由 -b 标志的 List 参数指示的范围之内,该字符将被写出;否则,该字符将被排除。 |
--complement |
complement the set of selected bytes, characters or fields |
补足被选择的字节、字符或字段 |
-s, --only-delimited |
do not print lines not containing delimiters |
不打印不含分隔符的行 |
--output-delimiter=STRING |
use STRING as the output delimiter the default is to use the input delimiter |
指定分隔符打印样式 |
【示例】:
1、基本用法:以字节为单位取列
[root@oldboy ~]# cat oldboy.txt
inet addr:10.0.0.8 Bcast:10.0.0.255 Mask:255.255.255.0
[root@oldboy ~]# cut -b6-18 oldboy.txt
addr:10.0.0.8
2、基本用法:以字符为单位取列
[root@oldboy ~]# cat oldboy.txt
inet addr:10.0.0.8 Bcast:10.0.0.255 Mask:255.255.255.0
[root@oldboy ~]# cut -c6-18 oldboy.txt
addr:10.0.0.8
3、基本用法:以分隔符为单位取列
[root@oldboy ~]# cat /etc/passwd|head -5
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
[root@oldboy ~]# cat /etc/passwd|head -5|cut -d':' -f5
root
bin
daemon
adm
lp
39. 【命令】:tr
【功能说明】:
translate or delete characters #转换或删除字符
【语法格式】:
tr [OPTION]... SET1 [SET2]
【选项参数】:
参数 |
说明 |
简解 |
-c, -C, --complement |
use the complement of SET1 |
取代所有不属于第一字符集的字符 |
-d, --delete |
delete characters in SET1, do not translate |
删除所有属于第一字符集的字符 |
-s, --squeeze-repeats |
replace each input sequence of a repeated character that is listed in SET1 with a single occurrence of that character |
把连续重复的字符以单独一个字符表示 |
-t, --truncate-set1 |
first truncate SET1 to length of SET2 |
先删除第一字符集较第二字符集多出的字符 |
【示例】:
1、基本用法:替换字符
[root@oldboy ~]# echo abcdef|tr 'a-f' 'x-za-c'
xyzabc
2、删除字符
[root@oldboy ~]# echo abcdef|tr -d 'a-c'
def
3、连续重复的字符以单独一个字符表示
[root@oldboy ~]# echo aaabbbccc|tr -s 'abc'
abc
[root@oldboy ~]# echo aaabbbccc|tr -s 'a'
abbbccc
40. 【命令】:stat
【功能说明】:
display file or file system status #显示文件和文件系统状态(查看文件属性)
【语法格式】:
stat [OPTION]... FILE...
【选项参数】:
参数 |
说明 |
简解 |
-L, --dereference |
follow links |
如果是链接文件,则获取原文件信息 |
-Z, --context |
print the SELinux security context |
打印SELinux安全上下文信息 |
-f, --file-system |
display file system status instead of file status |
显示文件系统状态而非文件状态 |
-c --format=FORMAT |
use the specified FORMAT instead of the default; output a newline after each use of FORMAT |
自定义输出格式,结尾有换行 |
--printf=FORMAT |
like --format, but interpret backslash escapes, and do not output a mandatory trailing newline. If you want a newline, include \n in FORMAT. |
自定义输出格式,结尾无换行符,需手动添加 |
-t, --terse |
print the information in terse form |
以简洁方式输出信息 |
【示例】:
1、基本用法:查看文件信息
[root@oldboy ~]# stat test.txt
File: `test.txt'
Size: 22 Blocks: 8 IO Block: 4096 regular file
Device: 803h/2051d Inode: 11628 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2016-03-19 16:08:55.616298620 +0800
Modify: 2016-03-19 16:08:44.504300222 +0800
Change: 2016-03-19 16:08:44.505300149 +0800
2、利用stat取文件权限属性
[root@oldboy ~]# stat test.txt
File: `test.txt'
Size: 22 Blocks: 8 IO Block: 4096 regular file
Device: 803h/2051d Inode: 11628 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
......
[root@oldboy ~]# stat -c %a test.txt
644
41. 【命令】:file
【功能说明】:
determine file type #显示文件类型
【语法格式】:
file [-bchikLNnprsvz0] [--apple] [--mime-encoding]
[--mime-type] [-e testname] [-F separator] [-f namefile]
[-m magicfiles] file ...
file -C [-m magicfiles]
file [--help]
【选项参数】:
参数 |
说明 |
简解 |
-b |
Do not prepend filenames to output lines (brief mode) |
列出文件辨识结果时,不显示文件名称。 |
-c |
Cause a checking printout of the parsed form of the magic file. This is usually used in conjunction with the -m flag to debug a new magic file before installing it |
详细显示指令执行过程,便于排错或分析程序执行的情形 |
-f |
Read the names of the files to be examined from namefile (one per line) before the argument list.Either namefile or at least one filename argument must be present; to test the standard input, use ‘-’ as a filename argument. |
列出文件中文件名的文件类型 |
-F |
Use the specified string as the separator between the filename and the file result returned. Defaults to‘:’. |
使用指定分隔符号替换输出文件名后的默认的“:”分隔符 |
-i |
Causes the file command to output mime type strings rather than the more traditional human readable ones.Thus it may say ‘text/plain; charset=us-ascii’ rather than ‘ASCII text’. In order for this option to work,file changes the way it handles files recognized by the command itself (such as many of the text file types, directories etc), and makes use of an alternative ‘magic’ file. (See the FILES section, below) |
输出mime类型的字符串 |
-L |
option causes symlinks to be followed, as the like-named option in ls(1) (on systems that support symbolic links). This is the default if the environment variable POSIXLY_CORRECT is defined |
查看对应软链接对应文件的文件类型 |
-z |
Try to look inside compressed files. |
尝试去解读压缩文件的内容 |
【示例】:
1、基本用法:显示文件类型
[root@oldboy ~]# file test.txt
test.txt: ASCII text
[root@oldboy ~]# file /data
/data: directory
42. 【命令】:last
【功能说明】:
show listing of last logged in users #查看用户登录信息
【语法格式】:
last [-R] [-num] [ -n num ] [-adFiowx] [ -f file ] [ -t
YYYYMMDDHHMMSS ] [name...] [tty...]
lastb [-R] [-num] [ -n num ] [ -f file ] [-adFiowx]
[name...] [tty...]
【选项参数】:
参数 |
说明 |
简解 |
-a |
Display the hostname in the last column. Useful in combination with the next flag |
将登录系统的的主机名称或IP地址,显示在最后一行 |
-d |
For non-local logins, Linux stores not only the host name of the remote host but its IP number as well.This option translates the IP number back into a hostname |
将IP地址转换成主机名称 |
-f |
Specifies a file to search other than /var/log/wtmp |
指定记录文件,默认是显示/var/log目录下的wtmp文件的记录,但/var/log目录下得btmp能显示的内容更丰富,可以显示远程登录,例如ssh登录 ,包括失败的登录请求 |
-i |
This option is like -d in that it displays the IP number of the remote host, but it displays the IP number in numbers-and-dots notation. |
-i显示特定ip登录的情况。跟踪用 -i显示特定ip登录的情况。跟踪用 |
-o |
Read an old-type wtmp file (written by linux-libc5 applications). |
|
-n |
This is a count telling last how many lines to show. |
-n <显示列数>或-<显示列数> 设置列出名单的显示列数 |
-w |
Display full user and domain names in the output |
|
-R |
Suppresses the display of the hostname field |
不显示登入系统的主机名称或IP(省略 hostname 的栏位) |
-t |
Display the state of logins as of the specified time. This is useful, e.g., to determine easily who was logged in at a particular time -- specify that time with -t and look for "still logged in" |
显示YYYYMMDDHHMMSS之前的信息 |
-x |
Display the system shutdown entries and run level changes. |
显示系统关闭、用户登录和退出的历史 |
【示例】:
1、基本用法:查看用户登录信息
[root@oldboy ~]# last
oldboy pts/0 10.0.0.1 Sun Mar 20 12:15 still logged in
reboot system boot 2.6.32-573.el6.x Sun Mar 20 12:15 - 15:08 (02:53)
oldboy pts/1 10.0.0.1 Sat Mar 19 15:36 - down (06:49)
root tty1 Sat Mar 19 15:35 - down (06:50)
2、显示最后登录系统的N条记录
[root@oldboy ~]# last -n 10
oldboy pts/0 10.0.0.1 Sun Mar 20 12:15 still logged in
reboot system boot 2.6.32-573.el6.x Sun Mar 20 12:15 - 15:25 (03:10)
oldboy pts/1 10.0.0.1 Sat Mar 19 15:36 - down (06:49)
root tty1 Sat Mar 19 15:35 - down (06:50)
oldboy pts/0 10.0.0.1 Sat Mar 19 10:28 - 15:52 (05:24)
reboot system boot 2.6.32-573.el6.x Sat Mar 19 10:28 - 22:25 (11:57)
root tty1 Sat Mar 19 10:27 - down (00:00)
oldboy pts/0 10.0.0.1 Sat Mar 19 10:20 - down (00:07)
oldboy pts/0 10.0.0.1 Sat Mar 19 10:19 - 10:20 (00:00)
reboot system boot 2.6.32-573.el6.x Sat Mar 19 10:19 - 10:27 (00:08)
wtmp begins Thu Mar 3 23:14:45 2016
3、将IP地址转换成主机名称
[root@oldboy ~]# last -n 5 -d
oldboy pts/0 localhost Sun Mar 20 12:15 still logged in
reboot system boot 0.0.0.0 Sun Mar 20 12:15 - 15:27 (03:11)
oldboy pts/1 localhost Sat Mar 19 15:36 - down (06:49)
root tty1 0.0.0.0 Sat Mar 19 15:35 - down (06:50)
oldboy pts/0 localhost Sat Mar 19 10:28 - 15:52 (05:24)
4、指定/var/log/btmp文件,查看登录系统的用户相关信息
[root@oldboy ~]# last -n 5 -f /var/log/btmp
btmp begins Thu Mar 3 23:14:22 2016
43. 【命令】:lastlog
【功能说明】:
reports the most recent login of all users or of a given user #查看最近登录的用户信息
【语法格式】:
lastlog [options]
【选项参数】:
参数 |
说明 |
简解 |
-b, --before DAYS |
Print only lastlog records older than DAYS |
显示指定天数前的登录信息 |
-h, --help |
Display help message and exit. |
显示帮助 |
-t, --time DAYS |
Print the lastlog records more recent than DAYS |
显示指定天数以来的登录信息 |
-u, --user LOGIN|RANGE |
Print the lastlog record of the specified user(s) |
显示指定用户的最近登录信息 |
【示例】:
1、基本用法:显示最近登录的用户信息
[root@oldboy ~]# lastlog
Username Port From Latest
root tty1 Sat Mar 19 15:35:02 +0800 2016
bin **Never logged in**
daemon **Never logged in**
adm **Never logged in**
lp **Never logged in**
sync **Never logged in**
shutdown **Never logged in**
halt **Never logged in**
mail **Never logged in**
......
oldboy pts/0 10.0.0.1 Sun Mar 20 12:15:35 +0800 2016
test **Never logged in**
2、显示某一个用户最近登录信息
[root@oldboy ~]# lastlog -u oldboy
Username Port From Latest
oldboy pts/0 10.0.0.1 Sun Mar 20 12:15:35 +0800 2016
44. 【命令】:df
【功能说明】:
report file system disk space usage #查看系统磁盘空间的使用情况
【语法格式】:
df [OPTION]... [FILE]...
【选项参数】:
参数 |
说明 |
简解 |
-a |
include dummy file systems |
包含全部的文件系统 |
-B |
use SIZE-byte blocks |
以指定的区块大小来显示区块数目 |
-h |
print sizes in human readable format (e.g., 1K 234M 2G) |
以可读性较高的方式来显示信息 |
-H |
likewise, but use powers of 1000 not 1024 |
与-h相同,但在计算时是以1000Bytes为换算单位而非1024 Bytes |
-i |
list inode information instead of block usage |
显示inode的信息 |
-k |
like --block-size=1K |
指定区块大小为1024字节 |
-l |
limit listing to local file systems |
仅显示本地的文件系统 |
--no-sync |
do not invoke sync before getting usage info (default) |
在取得磁盘使用信息前,不要执行sync指令,此为预设值 |
-P |
use the POSIX output format |
使用POSIX的输出格式 |
--sync |
invoke sync before getting usage info |
在取得磁盘使用信息前,先执行sync指令 |
-t |
limit listing to file systems of type TYPE |
仅显示指定文件系统类型的磁盘信息 |
-T |
print file system type |
显示文件系统的类型 |
-x |
limit listing to file systems not of type TYPE |
不要显示指定文件系统类型的磁盘信息 |
【示例】:
1、基本用法:查看磁盘空间使用情况
[root@oldboy ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 7149156 1494028 5285312 23% /
tmpfs 243320 0 243320 0% /dev/shm
/dev/sda1 194241 40498 143503 23% /boot
[root@oldboy ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 6.9G 1.5G 5.1G 23% /
tmpfs 238M 0 238M 0% /dev/shm
/dev/sda1 190M 40M 141M 23% /boot
2、基本用法:查看inode的消耗情况
[root@oldboy ~]# df -hi
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda3 452K 55K 397K 13% /
tmpfs 60K 1 60K 1% /dev/shm
/dev/sda1 50K 39 50K 1% /boot
[root@oldboy ~]# df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda3 462384 56221 406163 13% /
tmpfs 60830 1 60829 1% /dev/shm
/dev/sda1 51200 39 51161 1% /boot
45. 【命令】:dumpe2fs
【功能说明】:
dump ext2/ext3/ext4 filesystem information #查看文件系统内部信息(元数据)
【语法格式】:
dumpe2fs [ -bfhixV ] [ -o superblock=superblock ] [ -o blocksize=block-
size ] device
【选项参数】:
参数 |
说明 |
简解 |
-b |
print the blocks which are reserved as bad in the filesystem |
打印文件系统中预留的块信息 |
-o superblock=superblock |
use the block superblock when examining the filesystem. This option is not usually needed except by a filesystem wizard who is examining the remains of a very badly corrupted filesystem |
指定检查文件系统时使用的超级块 |
-o blocksize=blocksize |
use blocks of blocksize bytes when examining the filesystem.This option is not usually needed except by a filesystem wizard who is examining the remains of a very badly corrupted filesystem |
检查文件系统时使用指定的块大小 |
-f |
force dumpe2fs to display a filesystem even though it may have some filesystem feature flags which dumpe2fs may not understand(and which can cause some of dumpe2fs’s display to be suspect) |
|
-h |
only display the superblock information and not any of the block group descriptor detail information |
仅显示超级块信息 |
-i |
display the filesystem data from an image file created by e2image, using device as the pathname to the image file |
从指定的文件系统映像文件中读取文件系统信息 |
-x |
print the detailed group information block numbers in hexadecimal format |
以16进制格式打印信息块成员 |
-V |
print the version number of dumpe2fs and exit. |
【示例】:
1、基本用法:查看文件系统内部信息
[root@oldboy ~]# dumpe2fs /dev/sda1
dumpe2fs 1.41.12 (17-May-2010)
Filesystem volume name: <none>
Last mounted on: /boot
Filesystem UUID: 3e368f7e-0775-4c00-afba-f8880d916366
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize
Filesystem flags: signed_directory_hash
Default mount options: user_xattr acl
......
Group 0: (Blocks 1-8192) [ITABLE_ZEROED]
Checksum 0x303a, unused inodes 2009
Primary superblock at 1, Group descriptors at 2-2
Reserved GDT blocks at 3-258
Block bitmap at 259 (+258), Inode bitmap at 275 (+274)
Inode table at 291-546 (+290)
3785 free blocks, 2009 free inodes, 6 directories, 2009 unused inodes
Free blocks: 4408-8192
Free inodes: 40-2048
Group 1: (Blocks 8193-16384) [INODE_UNINIT, ITABLE_ZEROED]
......
46. 【命令】:tree
【功能说明】:
list contents of directories in a tree-like format #以树的形式罗列目录内容
【语法格式】:
tree [-adfghilnopqrstuvxACDFNS] [-L level [-R]] [-H baseHREF] [-T title] [-o
filename] [--nolinks] [-P pattern] [-I pattern] [--inodes] [--device]
[--noreport] [--dirsfirst] [--version] [--help] [--filelimit #] [directory
...]
【选项参数】:
参数 |
说明 |
简解 |
-a |
All files are printed. By default tree does not print hidden files(those beginning with a dot ‘.’). In no event does tree print the file system constructs ‘.’ (current directory) and ‘..’ (previous directory) |
显示所有文件和目录 |
-A |
Turn on ANSI line graphics hack when printing the indentation lines |
使用ASNI绘图字符显示树状图而非以ASCII字符组合 |
-C |
Turn colorization on always, using built-in color defaults if the LS_COLORS environment variable is not set. Useful to colorize output to a pipe |
在文件和目录清单加上色彩,便于区分各种类型 |
-d |
List directories only |
只罗列目录 |
-D |
Print the date of the last modification time for the file listed |
列出文件或目录的更改时间 |
-L |
Max display depth of the directory tree |
罗列的层次深度 |
-f |
Prints the full path prefix for each file |
在每个文件或目录之前,显示完整的相对路径名称 |
-F |
Append a ‘/’ for directories, a ‘=’ for socket files, a ‘*’ for executable files and a ‘|’ for FIFO’s, as per ls -F |
在执行文件,目录,Socket,符号连接,管道名称名称,各自加上"*","/","=","@","|"号 |
-g |
Print the group name, or GID # if no group name is available, of the file. |
列出文件或目录的所属群组名称,没有对应的名称时,则显示群组识别码 |
-i |
Makes tree not print the indentation lines, useful when used in conjunction with the -f option |
不以阶梯状列出文件或目录名称 |
-I |
Do not list those files that match the wild-card pattern |
不显示符合范本样式的文件或目录名称 |
-l |
Follows symbolic links if they point to directories, as if they were directories. Symbolic links that will result in recursion are avoided when detected |
如遇到性质为符号连接的目录,直接列出该连接所指向的原始目录 |
-n |
Turn colorization off always, over-ridden by the -C option |
不在文件和目录清单加上色彩 |
-N |
Print non-printable characters as is instead of the default caret notation |
直接列出文件和目录名称,包括控制字符 |
-p |
Print the file type and permissions for each file (as per ls -l) |
列出权限标示 |
-P |
List only those files that match the wild-card pattern. Note: you must use the -a option to also consider those files beginning with a dot ‘.’ for matching. Valid wildcard operators are ‘*’ (any zero or more characters), ‘?’ (any single character), ‘[...]’ (any single character listed between brackets (optional - (dash) for character range may be used: ex: [A-Z]), and ‘[^...]’ (any single character not listed in brackets) and ‘|’ separates alternate patterns |
只显示符合范本样式的文件或目录名称 |
-q |
Print non-printable characters in filenames as question marks instead of the default caret notation |
用"?"号取代控制字符,列出文件和目录名称 |
-s |
Print the size of each file in bytes along with the name |
列出文件或目录大小 |
-t |
Sort the output by last modification time instead of alphabetically |
用文件和目录的更改时间排序 |
-u |
Print the username, or UID # if no username is available, of the file |
列出文件或目录的拥有者名称,没有对应的名称时,则显示用户识别码 |
-x |
Stay on the current file-system only. Ala find -xdev |
将范围局限在现行的文件系统中,若指定目录下的某些子目录,其存放于另一个文件系统上,则将该子目录予以排除在寻找范围外 |
【示例】:
1、基本用法:以树形罗列目录
[root@oldboy ~]# tree oldboy
oldboy
├── ext
│ └── oldboy
├── jeacen
├── oldboy
├── test
├── wodi.gz
├── xiaodong
├── xiaofan
├── xingfujie
└── yingsui.gz
2、只罗列目录
[root@oldboy ~]# tree -d
.
├── data
│ ├── dir1
│ ├── dir2
│ ├── dir3
│ ├── dir4
│ └── dir5
└── oldboy
├── ext
├── test
├── xiaodong
├── xiaofan
└── xingfujie
3、只罗列目录,显示深度为1层
[root@oldboy ~]# tree -Ld 1
.
├── data
└── oldboy
4、显示完整的相对路径
[root@oldboy ~]# tree -f data
data
├── data/c.txt
├── data/dir1
├── data/dir2
├── data/dir3
├── data/dir4
├── data/dir5
├── data/d.txt
├── data/e.txt
├── data/oldboy.txt
└── data/test.txt
5、不以阶梯状形式显示
[root@oldboy ~]# tree -i data
data
c.txt
dir1
dir2
dir3
dir4
dir5
d.txt
e.txt
oldboy.txt
test.txt
6、为显示内容添加提示符
[root@oldboy ~]# tree -F oldboy
oldboy
├── ext/
│ └── oldboy
├── jeacen
├── oldboy
├── test/
├── wodi.gz
├── xiaodong/
├── xiaofan/
├── xingfujie/
└── yingsui.gz
47. 【命令】:id
【功能说明】:
print real and effective user and group IDs #显示用户ID及组ID
【语法格式】:
id [OPTION]... [USERNAME]
【选项参数】:
参数 |
说明 |
简解 |
-a |
ignore, for compatibility with other versions |
|
-Z |
print only the security context of the current user |
|
-g |
print only the effective group ID |
显示用户所属群组的ID |
-G |
print all group IDs |
显示用户所有群组的ID |
-n |
print a name instead of a number, for -ugG |
显示用户所属群组的名称 |
-r |
print the real ID instead of the effective ID, with -ugG |
显示实际ID |
-u |
print only the effective user ID |
显示用户ID |
【示例】:
1、基本用法:显示用户ID及组ID
[oldboy@oldboy ~]$ id oldboy
2、显示用户ID
[oldboy@oldboy ~]$ id -u oldboy
500
48. 【命令】:ln
【功能说明】:
make links between files #创建链接
【语法格式】:
ln [OPTION]... [-T] TARGET LINK_NAME (1st form)
ln [OPTION]... TARGET (2nd form)
ln [OPTION]... TARGET... DIRECTORY (3rd form)
ln [OPTION]... -t DIRECTORY TARGET... (4th form)
【选项参数】:
参数 |
说明 |
简解 |
-f |
remove existing destination files |
链接时先将与dist同档案名的档案删除 |
-d |
allow the superuser to attempt to hard link directories (note: will probably fail due to system restrictions, even for the superuser) |
允许系统管理者硬链接自己的目录 |
-i |
prompt whether to remove destinations |
在删除与dist同名的档案时先进行询问 |
-n |
treat destination that is a symlink to a directory as if it were a normal file |
在进行软链接时,将dist视为一般的档案 |
-s |
make symbolic links instead of hard links |
创建软链接 |
-v |
print name of each linked file |
在链接之前显示其档案名 |
-b |
like --backup but does not accept an argument |
将在链接时会被覆写或删除的档案进行备份 |
-S |
override the usual backup suffix |
将备份的档案都加上SUFFIX的字尾 |
【示例】:
1、基本用法:创建文件硬链接
[root@oldboy ~]# ln oldboy.txt oldboy_hard_link
[root@oldboy ~]# ls
anaconda-ks.cfg install.log log2.txt oldboy_hard_link oldboy.txt
data install.log.syslog oldboy oldboy.tar.gz test.txt
2、基本用法:创建文件软链接
[root@oldboy ~]# ln -s oldboy.txt oldboy_soft_link
[root@oldboy ~]# ls
anaconda-ks.cfg install.log log2.txt oldboy_hard_link oldboy.tar.gz test.txt
data install.log.syslog oldboy oldboy_soft_link oldboy.txt
49. 【命令】:du
【功能说明】:
estimate file space usage #查看文件和目录大小
【语法格式】:
du [OPTION]... [FILE]...
du [OPTION]... --files0-from=F
【选项参数】:
参数 |
说明 |
简解 |
-a |
write counts for all files, not just directories |
显示目录中所有文件大小 |
-b |
equivalent to ‘--apparent-size --block-size=1’ |
显示目录或文件大小时,以byte为单位 |
-c |
produce a grand total |
显示一个大小总和 |
-k |
like --block-size=1K |
以KB为单位输出 |
-m |
like --block-size=1M |
以MB为单位输出 |
-s |
display only a total for each argument |
仅显示总计,只列出最后加总的值 |
-h |
print sizes in human readable format (e.g., 1K 234M 2G) |
人类可读 |
-x |
skip directories on different file systems |
以一开始处理时的文件系统为准,若遇上其它不同的文件系统目录则略过 |
-L |
dereference all symbolic links |
显示选项中所指定符号链接的源文件大小 |
-S |
do not include size of subdirectories |
显示个别目录的大小时,并不含其子目录的大小 |
-X |
exclude files that match any pattern in FILE |
|
--exclude=PATTERN |
exclude files that match PATTERN |
略过指定的目录或文件 |
-D |
dereference only symlinks that are listed on the command line |
显示指定符号链接的源文件大小 |
-H |
equivalent to --dereference-args (-D) |
与-h参数相同,但是是以1000为换算单位 |
-l |
count sizes many times if hard linked |
重复计算硬链接的文件 |
【示例】:
1、基本用法:显示目录或文件所占空间
[root@oldboy ~]# du
4 ./oldboy/xiaofan
8 ./oldboy/ext
4 ./oldboy/xingfujie
4 ./oldboy/xiaodong
4 ./oldboy/test
40 ./oldboy
4 ./data/dir5
4 ./data/dir1
4 ./data/dir2
4 ./data/dir3
4 ./data/dir4
28 ./data
172 .
2、显示指定文件所占空间
[root@oldboy ~]# du oldboy.txt
4 oldboy.txt
3、显示指定目录所占空间
[root@oldboy ~]# du oldboy
4 oldboy/xiaofan
8 oldboy/ext
4 oldboy/xingfujie
4 oldboy/xiaodong
4 oldboy/test
40 oldboy
4、以易读模式显示
[root@oldboy ~]# du -h
4.0K ./oldboy/xiaofan
8.0K ./oldboy/ext
4.0K ./oldboy/xingfujie
4.0K ./oldboy/xiaodong
4.0K ./oldboy/test
40K ./oldboy
4.0K ./data/dir5
4.0K ./data/dir1
4.0K ./data/dir2
4.0K ./data/dir3
4.0K ./data/dir4
28K ./data
172K .
50. 【命令】:which
【功能说明】:
shows the full path of (shell) commands #从PATH变量所在路径查找二进制命令
【语法格式】:
which [options] [--] programname [...]
【选项参数】:
参数 |
说明 |
简解 |
【示例】:
1、基本用法:查找命令
[root@oldboy ~]# which cat
/bin/cat
初识50个Linux命令的更多相关文章
- 常用的50条linux 命令
从今天起,咱开始正式学习python了,于是遍整理了50条linux的常用命令. 1 线上查询帮助命令 :man 遇到什么不会的命令可以 man +你想要查询的命令 (需要有网),因为是英文的所以 ...
- 50条LINUX命令整理
1. find 基本语法参数如下: find [PATH] [option] [action] # 与时间有关的参数: -mtime n : n为数字,意思为在n天之前的“一天内”被更改过的文件: - ...
- linux命令**50
1.ls命令 命令格式: ls [选项] [目录名] 命令功能: 列出目标目录中所有的子目录和文件. 常用参数: -a,列出所有文件包括隐藏文件 -l,列出详细信息,文件大小一般以字节大小显示 -h, ...
- linux 50个常用命令
1.ls命令 ls是list的缩写,常用命令为ls(显示出当前目录列表),ls -l(详细显示当前目录列表),ls -lh(人性化的详细显示当前目录列表),ls -a(显示出当前目录列表,包含隐藏文件 ...
- [转帖]50个必知的Linux命令技巧,你都掌握了吗?
50个必知的Linux命令技巧,你都掌握了吗? https://blog.51cto.com/lizhenliang/2131141 https://blog.51cto.com/lizhenlian ...
- Linux命令行–初识Linux shell
shell及脚本简介 GNU/Linux shell 是个交互工具,它为用户提供了启动程序.管理文件系统上的文件以及管理运行在Linux系统上的进程的途径 . shell的核心是命令行提示符 它是s ...
- Linux基础二:初识linux命令
一.UNIX和Linux操作系统概述 1.UNIX是什么 1)UNIX的定义: UNIX是一个计算机操作系统,一个用来协调.管理和控制计算机硬件和软件资源的控制程序. 2)UNIX操作系统的特点:多用 ...
- 《Linux命令行与shell脚本编程大全 第3版》Linux命令行---50
以下为阅读<Linux命令行与shell脚本编程大全 第3版>的读书笔记,为了方便记录,特地与书的内容保持同步,特意做成一节一次随笔,特记录如下:
- 《Linux命令行与shell脚本编程大全 第3版》
第一部分 Linux 命令行 第1章 初识Linux she1.1 什么是Linux 21.1.1 深入探究Linux 内核 31.1.2 GNU 工具 61.1.3 Linux 桌面环境 81 ...
随机推荐
- ASP.NET 运行时详解 揭开请求过程神秘面纱
对于ASP.NET开发,排在前五的话题离不开请求生命周期.像什么Cache.身份认证.Role管理.Routing映射,微软到底在请求过程中干了哪些隐秘的事,现在是时候揭晓了.抛开乌云见晴天,接下来就 ...
- 关于 CommonJS AMD CMD UMD 规范的差异总结
一.CommonJS 主要是用于服务器端的规范,比如目前的nodeJS. 根据CommonJS规范,一个单独的文件就是一个模块.每一个模块都是一个单独的作用域,也就是说,在一个文件定义的变量(还包括函 ...
- 克隆复制可使用原型( Prototype)设计模式
今天有学习设计模式的原型(Prototype)<设计模式--原型(Prototype)模式>http://www.cnblogs.com/insus/p/4152773.html .为了加 ...
- C#中this的 四种 用法
C#中的this用法,相信大家应该有用过,但你用过几种?以下是个人总结的this几种用法,欢迎大家拍砖,废话少说,直接列出用法及相关代码. this用法1:限定被相似的名称隐藏的成员 /// < ...
- jquery实现智能表单
现在很多网站的注册模块都可以实现即时检查格式是否正确,这样极大的增强了用户体验,对开发非常有利. 下面的代码是利用jquery实现了对一个表单字段格式的即时检查(包括字段长度.邮箱格式),同时在提交时 ...
- 个人学习对UIView动画的总结
我的博客之前已经开通五个月了,但是一直没有写东西.一是不敢写,二是也不知道写啥.毕竟是一个刚刚入行大半年的菜鸟,现在总想通过各种办法提高自己.之前总感觉用到一些东西,只是当时搞懂了一点,加上并没有总结 ...
- csharp: InvokeHelper
Entity Framework https://entityframework.codeplex.com/ Enterprise Library https://entlib.codeplex.co ...
- 常用SQL语句优化技巧
除了建立索引之外,保持良好的SQL语句编写习惯将会降低SQL性能问题发生. ①通过变量的方式来设置参数 好:stringsql = "select * from people p where ...
- 【翻译】配置RSVP-signaled LSP
源地址: https://www.juniper.net/techpubs/software/junos-security/junos-security10.2/junos-security-swco ...
- GTD桌面2.0
在以前实践了一个GTD桌面,当时称为1.0版本,当时的效果是这样的: 2015年更换一点设备,把GTD桌面升级一下,就称为2.0吧.直接上图: 可以发现显示器由以前的1台又变回2台,原以为1台大显示器 ...