Linux基础命令四
作者:互联网
Linux基础命令四
目录
- Linux基础命令四
- 如何获取命令帮助
- 文件命名规则
- Linux常用命令(续)
- 文本查找 grep egrep fgrep
- grep在过滤的时候会把你需要的那个关键字所在的那一行全部打印出来
- 文件查找
- locate非实时,模糊匹配,查找是根据全系统文件数据库进行的,查找的速度快.依赖于事先构建的索引。索引的构建是在系统较为空闲时自动进行(周期性任务)语法:locate KEYWORD
- updatedb手动生成文件数据库,索引构建过程需要遍历整个根文件系统,极消耗资源
- find实时查找,精确性强,遍历指定目录中所有文件完成查找,查找速度慢,支持众多查找标准.查找路径:默认为当前目录.查找标准:默认为指定路径下的所有文件.语法:find [OPTION...] 查找路径 查找标准 查找到以后的处理动作
- Linux的组分两类 一个是用户的主要组(主组):用户必须属于一个且只有一个主组.组名同用户名,且仅包含一个用户:私有组,一个是用户的附加组(辅助组):一个用户可以属于零个或多个辅助组
- -uid 根据UID进行查找,当用户被删除以后文件的属主会变为此用户的UID
- -gid 根据GID进行查找,当用户被删除以后文件的属组会变为此用户的GID
- -nouser查找没有属主的文件.用户被删除的情况下产生的文件,只有uid没有属主
- -nogroup 查找没有属组的文件.组被删除的情况下产生的文件,只有gid没有属组
- -type 根据文件类型来查找(f,d,c,b,l,p,s)
- -size根据文件大小进行查找。如1k、1M,+10k、+10M,-1k、-1M, . +表示大于,-表示小于
- [+|-]
- #K、#M、#G
- #Unit表示(从#-1到#之间的范围大小)
- -#Unit表示(从0到#-1的范围大小)
- +#Unit表示(大于#的所有)
- -mtime修改时间
- -ctime改变时间
- -atime 访问时间,+5:5天前,-5:5天以内
- -mmin 多少分钟修改过
- -cmin 多少分钟改变过
- -amin多少分钟访问过,+5 :5分钟前.-5:5分钟以内
- -perm mode根据权限精确查找
- -perm -mode文件权限能完全包含此mode时才符合条件
- -perm /mode 9位权限中有任何一位权限匹配都视为符合查找条件
- 组合条件:
- -a
- -o
- -not
- !
- 例:
- !A -a !B = !(A -o B)
- !A -o !B = !(A -a B)
- 处理动作:默认为显示到屏幕上
- -print显示
- -ls类似ls -l的形式显示每一个文件的详细信息
- -delete删除查找到的文件
- -fls (/path/to/somefile) 查找到的所有文件的长格式信息保存至指定文件中
- -ok COMMAND {} ; //对查找到的每个文件执行COMMAND,每次操作都需要用户确认
- -exec COMMAND {} ; //对查找到的每个文件执行COMMAND,操作不需要确认
- 注意:find传递查找到的文件至后面指定的命令时,查找到所有 \
- 符合条件的文件一次性传递给后面的命令,而有些命令不能接受过多参数, \
- 此时命令执行可能会失败。而xargs可规避此问题
- xargs通过管道将查找到的内容给xargs处理,xargs后面直接跟命令即可
- 文件层级系统
- 重定向与管道
- bash字符串处理
如何获取命令帮助
内部命令
[root@lnh ~]# help pwd
pwd: pwd [-LP]
Print the name of the current working directory.
Options:
-L print the value of $PWD if it names the current working
directory
-P print the physical directory, without any symbolic links
By default, `pwd' behaves as if `-L' were specified.
Exit Status:
Returns 0 unless an invalid option is given or the current directory
cannot be read.
//因为内部命令比较少,所以一般不使用这种方法
外部命令
[root@lnh ~]# ls --help
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.
Mandatory arguments to long options are mandatory for short options too.
-a, --all do not ignore entries starting with .
-A, --almost-all do not list implied . and ..
--author with -l, print the author of each file
-b, --escape print C-style escapes for nongraphic characters
--block-size=SIZE with -l, scale sizes by SIZE when printing them;
e.g., '--block-size=M'; see SIZE format below
-B, --ignore-backups do not list implied entries ending with ~
-c with -lt: sort by, and show, ctime (time of last
modification of file status information);
with -l: show ctime and sort by name;
otherwise: sort by ctime, newest first
-C list entries by columns
--color[=WHEN] colorize the output; WHEN can be 'always' (default
if omitted), 'auto', or 'never'; more info below
-d, --directory list directories themselves, not their contents
-D, --dired generate output designed for Emacs' dired mode
-f do not sort, enable -aU, disable -ls --color
-F, --classify append indicator (one of */=>@|) to entries
--file-type likewise, except do not append '*'
--format=WORD across -x, commas -m, horizontal -x, long -l,
single-column -1, verbose -l, vertical -C
--full-time like -l --time-style=full-iso
-g like -l, but do not list owner
--group-directories-first
group directories before files;
can be augmented with a --sort option, but any
use of --sort=none (-U) disables grouping
-G, --no-group in a long listing, don't print group names
-h, --human-readable with -l and -s, print sizes like 1K 234M 2G etc.
--si likewise, but use powers of 1000 not 1024
-H, --dereference-command-line
follow symbolic links listed on the command line
--dereference-command-line-symlink-to-dir
follow each command line symbolic link
that points to a directory
--hide=PATTERN do not list implied entries matching shell PATTERN
(overridden by -a or -A)
--hyperlink[=WHEN] hyperlink file names; WHEN can be 'always'
(default if omitted), 'auto', or 'never'
--indicator-style=WORD append indicator with style WORD to entry names:
none (default), slash (-p),
file-type (--file-type), classify (-F)
-i, --inode print the index number of each file
-I, --ignore=PATTERN do not list implied entries matching shell PATTERN
-k, --kibibytes default to 1024-byte blocks for disk usage;
used only with -s and per directory totals
-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
-N, --literal print entry names without quoting
-o like -l, but do not list group information
-p, --indicator-style=slash
append / indicator to directories
-q, --hide-control-chars print ? instead of nongraphic characters
--show-control-chars show nongraphic characters as-is (the default,
unless program is 'ls' and output is a terminal)
-Q, --quote-name enclose entry names in double quotes
--quoting-style=WORD use quoting style WORD for entry names:
literal, locale, shell, shell-always,
shell-escape, shell-escape-always, c, escape
(overrides QUOTING_STYLE environment variable)
-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, largest first
--sort=WORD sort by WORD instead of name: none (-U), size (-S),
time (-t), version (-v), extension (-X)
--time=WORD with -l, show time as WORD instead of default
modification time: atime or access or use (-u);
ctime or status (-c); also use specified time
as sort key if --sort=time (newest first)
--time-style=TIME_STYLE time/date format with -l; see TIME_STYLE below
-t sort by modification time, newest first
-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, newest first
-U do not sort; list entries in directory order
-v natural sort of (version) numbers within text
-w, --width=COLS set output width to COLS. 0 means no limit
-x list entries by lines instead of by columns
-X sort alphabetically by entry extension
-Z, --context print any security context of each file
-1 list one file per line. Avoid '\n' with -q or -b
--help display this help and exit
--version output version information and exit
The SIZE argument is an integer and optional unit (example: 10K is 10*1024).
Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000).
The TIME_STYLE argument can be full-iso, long-iso, iso, locale, or +FORMAT.
FORMAT is interpreted like in date(1). If FORMAT is FORMAT1<newline>FORMAT2,
then FORMAT1 applies to non-recent files and FORMAT2 to recent files.
TIME_STYLE prefixed with 'posix-' takes effect only outside the POSIX locale.
Also the TIME_STYLE environment variable sets the default style to use.
Using color to distinguish file types is disabled both by default and
with --color=never. With --color=auto, ls emits color codes only when
standard output is connected to a terminal. The LS_COLORS environment
variable can change the settings. Use the dircolors command to set it.
Exit status:
0 if OK,
1 if minor problems (e.g., cannot access subdirectory),
2 if serious trouble (e.g., cannot access command-line argument).
GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Full documentation at: <https://www.gnu.org/software/coreutils/ls>
or available locally via: info '(coreutils) ls invocation'
[root@lnh ~]# pwd --help
pwd: pwd [-LP]
Print the name of the current working directory.
Options:
-L print the value of $PWD if it names the current working
directory
-P print the physical directory, without any symbolic links
By default, `pwd' behaves as if `-L' were specified.
Exit Status:
Returns 0 unless an invalid option is given or the current directory
cannot be read.
//虽然这个是查看外部命令的帮助,但是内部命令也可以查看,我们一般都是使用这种方法来查看帮助,实在查看不了的才是用上面那个进行查看帮助
info COMMAND 在线文档(查看要查看的那个命令信息)
man COMMAND命令手册(一般都是用这个命令查看需要的命令帮助)
whatis COMMAND(查看命令在man文档里面的第几章)
[root@lnh ~]# whatis ls
ls (1) - list directory contents
[root@lnh ~]# ls
anaconda-ks.cfg passwd test tushanbu xxb
[root@lnh ~]# whatis /usr/bin/passwd
openssl-passwd (1ssl) - compute password hashes
passwd (1) - update user's authentication tokens
[root@lnh ~]# whatis passwd
openssl-passwd (1ssl) - compute password hashes
passwd (1) - update user's authentication tokens
//可以查看在man文档里面哪一章节,可以直接在后面接关键字查看
man是分章节的,以下是每一章节的内容介绍
| 1 | 2|3 | 4| 5| 6|7 |8 |
| :-------- | --------
标签:aa,tushanbu,xbz,--,基础,命令,lnh,Linux,root 来源: https://www.cnblogs.com/tushanbu/p/16445029.html