切换目录 cd dirname
cd 进入主目录
cd ~ 进入用户主目录
cd - 返回进入此目录之前所在的目录
cd .. 返回上级
cd ../.. 返回上两级目录
cd !$ 把上个命令的参数作为cd参数使用
ls:显示文件和目录的信息
显示文件和目录的信息
ls 以默认方式显示当前目录文件列表
ls -a 显示所有文件包括隐藏文件
ls -l 或 ll 显示文件属性,包括大小,日期,符号连接,是否可读写及是否可执行
ls -lc 列出文件的最后更改时间
ls -lu 列出文件的最后访问时间
ls -lh 显示文件的大小,以容易理解的格式印出文件大小 (例如 1K 234M2G)
ls -lt 显示文件,按照修改时间排序
sed是一种流编辑器,它是文本处理中非常有用的工具,可以完美配合正则表达式使用。
格式: 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 (将脚本添加到要执行的命令中)
-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 (处理到位时遵循符号链接)
-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if SUFFIX supplied) (就地编辑文件,如果提供后缀则进行备份)
-l N, --line-length=N
specify the desired line-wrap length for the `l' command (为 'l' 命令指定所需的换行长度)
--posix
disable all GNU extensions. (禁用所有GNU拓展)
-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 (从输入文件加载最小数量的数据并刷新输出缓冲区)
-z, --null-data
separate lines by NUL characters (按数字字符分隔行)
--help display this help and exit
--version output version information and exit
If no -e, --expression, -f, or --file option is given, then the first 如果没有指定 -e 或者 -f 选项,则第一个非选项参数被视作要解释的seq脚本,其他剩余参数作为输入文件的名字
non-option argument is taken as the sed script to interpret. all 如果没有指定输入文件,会读取标准输入
remaining arguments are names of input files; if no input files are
specified, then the standard input is read.
eg:
1、组合多个表达式
sed '表达式' | sed '表达式'
等价于
sed '表达式; 表达式'
2、引用
sed表达式可以使用单引号来引用,但是如果表达式内部包含变量字符串,就需要使用双引号。
3、替换字符串
sed -i 's/需要替换的字符串/替代字符串/' filename 会替换所有匹配的字符串
4、替换行
sed -i '/匹配行/c 新内容' filename
eg: sed -i '/aba/c 11111' a.txt 将a.txt中包含aba字符的行替换为 11111
file:确定文件类型
确定文件类型
Usage: file [OPTION...] [FILE...]
Determine type of FILEs.
--help display this help and exit
-v, --version output version information and exit (输出版本信息并退出)
-m, --magic-file LIST use LIST as a colon-separated list of magic number files (使用LIST给magic number 文件以冒号分隔)
-z, --uncompress try to look inside compressed files (尝试查看压缩文件)
-b, --brief do not prepend filenames to output lines
-c, --checking-printout print the parsed form of the magic file, use in (输出magic文件的解析格式,用于和-m一起在安装新的magic文件前先调试它)
conjunction with -m to debug a new magic file
before installing it
-e, --exclude TEST exclude TEST from the list of test to be (从要对文件执行的测试列表中排除测试
performed for file. Valid tests are: 有效的测试是:apptype,ascii,cdf,compress,elf,encoding,soft,tar,text,tokens)
apptype, ascii, cdf, compress, elf, encoding,
soft, tar, text, tokens
-f, --files-from FILE read the filenames to be examined from FILE
-F, --separator STRING use string as separator instead of `:'
-i, --mime output MIME type strings (--mime-type and
--mime-encoding)
--apple output the Apple CREATOR/TYPE
--mime-type output the MIME type
--mime-encoding output the MIME encoding
-k, --keep-going don't stop at the first match (不在第一次匹配就停下来)
-l, --list list magic strength (列出magic强度)
-L, --dereference follow symlinks (default if POSIXLY_CORRECT is set) (遵循符号链接,未设置则默认为POSIXLY_CORRECT)
-h, --no-dereference don't follow symlinks (default if POSIXLY_CORRECT is not set) (不遵循符号链接,未设置则默认为POSIXLY_CORRECT)
-n, --no-buffer do not buffer output (不缓冲输出)
-N, --no-pad do not pad output (不覆盖输出)
-0, --print0 terminate filenames with ASCII NUL (用 ASCII NUL 终止文件名)
-p, --preserve-date preserve access times on files
-P, --parameter set file engine parameter limits
indir 15 recursion limit for indirection
name 30 use limit for name/use magic
elf_notes 256 max ELF notes processed
elf_phnum 128 max ELF prog sections processed
elf_shnum 32768 max ELF sections processed
-r, --raw don't translate unprintable chars to \ooo (不将无法打印的字符转化为\ooo)
-s, --special-files treat special (block/char devices) files as ordinary ones (对特殊(块字符设备)文件视为一般文件)
-C, --compile compile file specified by -m (编译由-m指定的文件)
-d, --debug print debugging messages (打印调试信息)
head:查看文件开头内容
查看文件开头内容
Usage: head [OPTION]... [FILE]...
Print the first 10 lines of each FILE to standard output. 打印每个文件的前十行到标准输出
With more than one FILE, precede each with a header giving the file name. 超过一个文件,在每一个文件前加上文件名的头
With no FILE, or when FILE is -, read standard input. 如果没有文件,或者文件是-,读入标准输入
Mandatory arguments to long options are mandatory for short options too. 规定的长参数和短参数的是一样的
-c, --bytes=[-]K print the first K bytes of each file; 打印每个文件开头k字节的内容
with the leading '-', print all but the last 使用引导符-,打印除了最后k字节的所有内容
K bytes of each file
-n, --lines=[-]K print the first K lines instead of the first 10; 打印每个文件开头K行的内容
with the leading '-', print all but the last 使用引导符-,打印除了最后k行的所有内容
K lines of each file
-q, --quiet, --silent never print headers giving file names 不打印文件名
-v, --verbose always print headers giving file names 打印文件名
--help display this help and exit 显示这个帮助并退出
--version output version information and exit 输出版本信息并退出
K may have a multiplier suffix:
b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024, k可以有多种后缀名
GB 1000*1000*1000, G 1024*1024*1024, and so on for T, P, E, Z, Y.
tail:查看文件末尾内容
查看文件末尾内容
Usage: tail [OPTION]... [FILE]...
Print the last 10 lines of each FILE to standard output. 打印每个文件的最后1-行到标准输出
With more than one FILE, precede each with a header giving the file name. 超过一个文件,在每一个文件前加上文件名的头
With no FILE, or when FILE is -, read standard input. 如果没有文件,或者文件是-,读入标准输入
Mandatory arguments to long options are mandatory for short options too.
-c, --bytes=K output the last K bytes; alternatively, use -c +K 输出最后k字节,
to output bytes starting with the Kth of each file 使用-c +K 从每个文件的第K个开始输出字节
-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; 输出后 K行, 使用-n +K 输出从第K开始的行
or use -n +K to output lines starting with the Kth
--max-unchanged-stats=N
with --follow=name, reopen a FILE which has not 使用 --follow=name 在N次(默认5次)迭代后重新打开一个未更改大小的文件,查看它是否已被
changed size after N (default 5) iterations 取消链接或重命名
to see if it has been unlinked or renamed
(this is the usual case of rotated log files).
With inotify, this option is rarely useful.
--pid=PID with -f, terminate after process ID, PID dies 使用-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 inaccessible; useful when following by
name, i.e., with --follow=name
-s, --sleep-interval=N with -f, sleep for approximately N seconds 使用-f在迭代之间睡眠大约N秒(默认为1.0),使用inotify 和 --pid=P,每隔N秒至少检查进程P一次
(default 1.0) between iterations.
With inotify and --pid=P, check process P at
least once every N seconds.
-v, --verbose always output headers giving file names 输出带文件名
--help display this help and exit
--version output version information and exit
If the first character of K (the number of bytes or lines) is a '+',
print beginning with the Kth item from the start of each file, otherwise,
print the last K items in the file. K may have a multiplier suffix:
b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024,
GB 1000*1000*1000, G 1024*1024*1024, and so on for T, P, E, Z, Y.
With --follow (-f), tail defaults to following the file descriptor, which
means that even if a tail'ed file is renamed, tail will continue to track
its end. This default behavior is not desirable when you really want to
track the actual name of the file, not the file descriptor (e.g., log
rotation). Use --follow=name in that case. That causes tail to track the
named file in a way that accommodates renaming, removal and creation.