参数 --help或-h 获得帮助 将 etc和System32目录放到 windows目录 注意:这些命令中目录分割符是/而不是\。其实windows也认/目录分割符. ================================================= 0: bash.exe 【非常重要】 注意:windows换行符实际是2个字符 『回车符 新行符』 ,一般写为"\r\n". 原因是古老的电脑的终端为电传打字机,需要先回车,再换新行,要2步,要2个控制符。 MS偷懒,不愿意做任何处理。以至现在如此别扭。因为这种纠结,MS命令行处理2进制文件 经常被篡改; 2进制数据不能安全地通过管道传递(还没找到开关,不知巫师命令PROMPT能否关闭换行转换)。 UNIX、LINUX都只用一个符号"\n",方便多了;命令行管道可以安全传递 2进制数据 。 标准系统,可以用bash.exe, bash.exe 是 LINUX规范, 其命令行管道可以安全传递 2进制数据。 『bash.exe -c "命令组合"』 代替 『cmd.exe /c "命令组合"』 对bash,命令组合外面的一对引号是必须的,也可以是一对单引号。 1>常用用法: EXEC* &RESULT=*bash.exe -c '命令1| 命令2 2>&1| 命令3' 命令里面的引号,如果和外面的引号相同,前面需要放置\来转义。 由于,外面的引号可以选择双引号和单引号, 可以适当选择避免相同。 由于windows命令常用双引号, 所以外面多选择单引号 上面 2>&1 表示 命令2的标准错误 合并到命令2的标准输出 ================================================= 1:字符串替换工具:sed 【非常重要】 Usage: sed [OPTION]... {script-only-if-no-other-script} [input-file]... -n, --quiet, --silent suppress automatic printing of pattern space -e 脚本串, --expression=脚本串 从脚本串中读取命令 -f 脚本文件, --file=脚本文件 从脚本文件中读取命令 -c --nocr turn off \r$ translation; must be first switch on command line --help display this help and exit -V, --version output version information and exit If no -e, --expression, -f, or --file option is given, then the first 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. (1) 最常用用法: 前命令|sed s/被替换串/替换串/g 前命令 2>&1|sed s/被替换串/替换串/g ECHO 原始内容|sed s/被替换串/替换串/g 最后的g为全部替换,否则只一次。 ECHO后恰好一个空格,多于当作内容。 如PECMD中: EXEC* &RESULT=cmd.exe /c ECHO abc1abc2abc3|sed s/abc/def/g 得到&RESULT:def1def2def3 (2) 从文件读入:sed s/被替换串/替换串/g 源文件 最后的g为全部替换,否则只一次。 如PECMD中: EXEC* &RESULT=sed s/abc/def/g src.txt 假定src.txt 的内容为『abc1abc2abc3』 得到&RESULT:『def1def2def3』 ================================================= 2: 字符翻译器: tr 【非常有用】 用法: tr [选项]... 集合1 [集合2] 输入为标准输入,输出为标准输出 翻译, 或压缩, 或删除 字符. -c, -C, --complement 第一次匹配 集合1 -d, --delete 删除集合1中出现的字符,此时不需要集合2 -s, --squeeze-repeats 匹配连续重复字符,只替换为一个字符,用于翻译 -t, --truncate-set1 首先 缩短 集合1 到和 集合2一样长,用于翻译 --help 帮助 --version 输出版本号 集合 就是一串字符,一对中挂号包围。大部分字符表示本身。少数为转义序列。 转义序列: \NNN 8进制数值NNN 表示的字符 (1 到 3 个 8进制位) \\ \ \a 响铃符 \b 退格符 \f 换页符 \n 新行符 \r 回车符 \t 水平跳格符(TAB) \v 垂直跳格符 字符1-字符2 从字符1到字符2的所有字符,升序 [字符*] 用于 集合2, 重复拷贝该字符直到和集合1一样长 [字符*重复次数] 重复次数个该字符。 重复次数以0开头则为8进制 [:alnum:] 所有字母和数字 [:alpha:] 所有字母 [:blank:] 水平跳格符(TAB)和空白字符(whitespace) [:cntrl:] 所有控制符 [:digit:] 所有数字(0-9) [:graph:] 所有可打印字符,不含空格 [:lower:] 所有小写字母(a-z) [:print:] all printable characters, including space [:punct:] all punctuation characters [:space:] 水平跳格符(TAB)和垂直跳格符(\v)和空白字符(whitespace) [:upper:] 所有大写字母(A-Z) [:xdigit:] 所有16进制数字(0-9 a-f A-F) [=CHAR=] 等于CHAR的所有字符 集合2 中 只有 [:lower:] and [:upper:] 扩展后保证是升序的;只用于大小写转换 集合2 自动扩展到 集合1一样长,重复最后的字符;而忽略多于的字符。 翻译: tr 集合1 集合2 删除: tr -d 集合1 说明,转义序列中的一对中刮号是其转义序列的一部分,和集合外面的中刮号不是一会是,不可省。 如 集合1: [[:xdigit:]] 或 [3-8[:alpha:]] ================================================= 3:文件2进制和文本间的转换 【非常有用】 Usage: xxd [options] [infile [outfile]] or xxd -r [-s [-]offset] [-c cols] [-ps] [infile [outfile]] Options: -a toggle autoskip: A single '*' replaces nul-lines. Default off. -b binary digit dump (incompatible with -p,-i,-r). Default hex. -c cols format octets per line. Default 16 (-i: 12, -ps: 30). -E show characters in EBCDIC. Default ASCII. -g number of octets per group in normal output. Default 2. -h print this summary. -i output in C include file style. -l len stop after octets. -ps output in postscript plain hexdump style. -r reverse operation: convert (or patch) hexdump into binary. -r -s off revert with added to file positions found in hexdump. -s [+][-]seek start at bytes abs. (or +: rel.) infile offset. -u use upper case hex letters. -v show version: "xxd V1.10 27oct98 by Juergen Weigert". (1) 最常用用法,2进制和HEX文本: 2进制=>HEX文本 xxd -g1 源文件 [输出文件] 前命令|xxd -g1 - [输出文件] //前命令的输出作为输入 前命令 2>&1 |xxd -g1 - [输出文件] //先将前命令的标准错误合并到输出,再作为输入 HEX文本=>2进制 xxd -r 源文件 2进制输出文件 前命令|xxd -r - 2进制输出文件 源文件和前命令输出 必须是 xxd HEX文本 格式。 本来可以省略2进制输出文件,直接输出到标准输出。但windows标准输出不支持2进制,可能篡改2进制内容。 一般还是写到文件吧。 (4) 重要开关 -r 反向转换 -r -s off 跳过off 开始反向转换 -c 列数 每少字符解码输出到一列。默认16。(-i模式默认12) -g数字 每多少字节输出一组。默认2. 一般用 『-g1』 -i 源文件转换成C、C++头文件 -b 输出2进制可读文本(010101..),而不是HEX -l len 最多转换len字节 -s [+][-]seekN 跳过seekN 字节,开始转换 -u 输出大写 HEX(ABCDEF) ================================================= 4:行排序:lsort.exe 原名sort.exe由于和windows的是sort重名,改名为lsort 【linux sort】 Usage: sort [OPTION]... [FILE]... Write sorted concatenation of all FILE(s) to standard output. Mandatory arguments to long options are mandatory for short options too. Ordering options: -b, --ignore-leading-blanks ignore leading blanks -d, --dictionary-order consider only blanks and alphanumeric characters -f, --ignore-case fold lower case to upper case characters -g, --general-numeric-sort compare according to general numerical value -i, --ignore-nonprinting consider only printable characters -M, --month-sort compare (unknown) < `JAN' < ... < `DEC' -n, --numeric-sort compare according to string numerical value -r, --reverse reverse the result of comparisons Other options: -c, --check check whether input is sorted; do not sort -k, --key=POS1[,POS2] start a key at POS1, end it at POS2 (origin 1) -m, --merge merge already sorted files; do not sort -o, --output=FILE write result to FILE instead of standard output -s, --stable stabilize sort by disabling last-resort comparison -S, --buffer-size=SIZE use SIZE for main memory buffer -t, --field-separator=SEP use SEP instead of non-blank to blank transition -T, --temporary-directory=DIR use DIR for temporaries, not $TMPDIR or /tmp; multiple options specify multiple directories -u, --unique with -c, check for strict ordering; without -c, output only the first of an equal run -z, --zero-terminated end lines with 0 byte, not newline --help display this help and exit --version output version information and exit POS is F[.C][OPTS], where F is the field number and C the character position in the field. OPTS is one or more single-letter ordering options, which override global ordering options for that key. If no key is given, use the entire line as the key. SIZE may be followed by the following multiplicative suffixes: % 1% of memory, b 1, K 1024 (default), and so on for M, G, T, P, E, Z, Y. With no FILE, or when FILE is -, read standard input. (1) 最常用用法:前命令|SORT 将前命令的输出排序再输出 (2) 最常用用法: SORT 源文件 将源文件排序再输出 (3) 重要开关 -n 按数值而不是字面排序。如按数值10比9大;按字面10比9小。 -r 反向排序 --ignore-case 排序时忽略大小写。可简写 -f --ignore-nonprinting 排序时忽略不可打印字符。可简写 -i --output=输出文件 默认输出显示 --key=POS1[,POS2] 从POS1到POS2为排序关键词。默认整行。 POS形式为:F[.C] F为第几个域(词), C为该域的第几列。 --field-separator=SEP 指定域(词)间分割符,默认为空字符 ================================================= 5: 取文本文件头部 用法: 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=[-]N print the first N bytes of each file; with the leading `-', print all but the last N bytes of each file -n, --lines=[-]N print the first N lines instead of the first 10; with the leading `-', print all but the last N 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 N may have a multiplier suffix: b 512, k 1024, m 1024*1024. (1) 最常用用法:前命令|head 取前命令的输出的前10行再输出 (2) 最常用用法: head 源文件1 [源文件2 ..] 取每个源文件的前10行再输出 (3) 重要开关 --lines=[-]行数 取多少行,默认10. -表示除去最后的多少行以外的全部 --bytes=[-]列数 每行取多少列,默认全部. -表示除去最后的多少列以外的全部 行数/列数可带后缀bkm:b=512, k=1024, m=1024*1024 ================================================= 6: 取文本文件尾部 用法: tail [OPTION]... [FILE]... Print the last 10 lines of each FILE to standard output. With more than one FILE, precede each with a header giving the file name. With no FILE, or when FILE is -, read standard input. Mandatory arguments to long options are mandatory for short options too. --retry keep trying to open a file even if it is inaccessible when tail starts or if it becomes inaccessible later; useful when following by name, i.e., with --follow=name -c, --bytes=N output the last N bytes -f, --follow[={name|descriptor}] output appended data as the file grows; -f, --follow, and --follow=descriptor are equivalent -F same as --follow=name --retry -n, --lines=N output the last N lines, instead of the last 10 --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) --pid=PID with -f, terminate after process ID, PID dies -q, --quiet, --silent never output headers giving file names -s, --sleep-interval=S with -f, sleep for approximately S seconds (default 1.0) between iterations. -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 N (the number of bytes or lines) is a `+', print beginning with the Nth item from the start of each file, otherwise, print the last N items in the file. N may have a multiplier suffix: b 512, k 1024, m 1024*1024. 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 by reopening it periodically to see if it has been removed and recreated by some other program. (1) 最常用用法:前命令|tail 取前命令的输出的后10行再输出 (2) 最常用用法: tail 源文件1 [源文件2 ..] 取每个源文件的后10行再输出 (3) 最常用用法:前命令|tail -f 监视前命令的输出的后10行。显示会动态变化 (4) 重要开关 --lines=行数 取多少行,默认10. --bytes=字符数 取最后的多少字符,默认按行计算. --pid=PID 改PID对应进程终止是自动退出。 -f 监视模式 --sleep-interval=S 监视模式监视周期,单位秒,默认1 行数/字符数可带后缀bkm:b=512, k=1024, m=1024*1024 ================================================= 7: 列出进程:ps Usage ps [-aefl] [-u uid] -f = show process uids, ppids -l = show process uids, ppids, pgids, winpids -u uid = list processes owned by uid -a, -e = show processes of all users -s = show process summary -W = show windows as well as cygwin processes (1) 最常用用法: ps -W 由于各列等宽,可以很容易用MSTR取出各列 ================================================= 8.压缩软件:gzip gzip 1.2.4 (18 Aug 93) usage: gzip [-acdfhlLnNrtvV19] [-S suffix] [file ...] -a --ascii ascii text; convert end-of-lines using local conventions -c --stdout write on standard output, keep original files unchanged -d --decompress decompress -f --force force overwrite of output file and compress links -h --help give this help -l --list list compressed file contents -L --license display software license -n --no-name do not save or restore the original name and time stamp -N --name save or restore the original name and time stamp -q --quiet suppress all warnings -r --recursive operate recursively on directories -S .suf --suffix .suf use suffix .suf on compressed files -t --test test compressed file integrity -v --verbose verbose mode -V --version display version number -1 --fast compress faster -9 --best compress better file... files to (de)compress. If none given, use standard input. ================================================= 9.打包/解包软件:tar GNU `tar' saves many files together into a single tape or disk archive, and can restore individual files from the archive. Usage: tar [OPTION]... [FILE]... Examples: tar -cf archive.tar foo bar # Create archive.tar from files foo and bar. tar -tvf archive.tar # List all files in archive.tar verbosely. tar -xf archive.tar # Extract all files from archive.tar. If a long option shows an argument as mandatory, then it is mandatory for the equivalent short option also. Similarly for optional arguments. Main operation mode: -t, --list list the contents of an archive -x, --extract, --get extract files from an archive -c, --create create a new archive -d, --diff, --compare find differences between archive and file system -r, --append append files to the end of an archive -u, --update only append files newer than copy in archive -A, --catenate append tar files to an archive --concatenate same as -A --delete delete from the archive (not on mag tapes!) Operation modifiers: -W, --verify attempt to verify the archive after writing it --remove-files remove files after adding them to the archive -k, --keep-old-files don't replace existing files when extracting --overwrite overwrite existing files when extracting -U, --unlink-first remove each file prior to extracting over it --recursive-unlink empty hierarchies prior to extracting directory -S, --sparse handle sparse files efficiently -O, --to-stdout extract files to standard output -G, --incremental handle old GNU-format incremental backup -g, --listed-incremental=FILE handle new GNU-format incremental backup --ignore-failed-read do not exit with nonzero on unreadable files Handling of file attributes: --owner=NAME force NAME as owner for added files --group=NAME force NAME as group for added files --mode=CHANGES force (symbolic) mode CHANGES for added files --atime-preserve don't change access times on dumped files -m, --modification-time don't extract file modified time --same-owner try extracting files with the same ownership --no-same-owner extract files as yourself --numeric-owner always use numbers for user/group names -p, --same-permissions extract permissions information --no-same-permissions do not extract permissions information --preserve-permissions same as -p -s, --same-order sort names to extract to match archive --preserve-order same as -s --preserve same as both -p and -s Device selection and switching: -f, --file=ARCHIVE use archive file or device ARCHIVE --force-local archive file is local even if has a colon --rsh-command=COMMAND use remote COMMAND instead of rsh -[0-7][lmh] specify drive and density -M, --multi-volume create/list/extract multi-volume archive -L, --tape-length=NUM change tape after writing NUM x 1024 bytes -F, --info-script=FILE run script at end of each tape (implies -M) --new-volume-script=FILE same as -F FILE --volno-file=FILE use/update the volume number in FILE Device blocking: -b, --blocking-factor=BLOCKS BLOCKS x 512 bytes per record --record-size=SIZE SIZE bytes per record, multiple of 512 -i, --ignore-zeros ignore zeroed blocks in archive (means EOF) -B, --read-full-records reblock as we read (for 4.2BSD pipes) Archive format selection: -V, --label=NAME create archive with volume name NAME PATTERN at list/extract time, a globbing PATTERN -o, --old-archive, --portability write a V7 format archive --posix write a POSIX format archive -j, --bzip2 filter the archive through bzip2 -z, --gzip, --ungzip filter the archive through gzip -Z, --compress, --uncompress filter the archive through compress --use-compress-program=PROG filter through PROG (must accept -d) Local file selection: -C, --directory=DIR change to directory DIR -T, --files-from=NAME get names to extract or create from file NAME --null -T reads null-terminated names, disable -C --exclude=PATTERN exclude files, given as a globbing PATTERN -X, --exclude-from=FILE exclude globbing patterns listed in FILE -P, --absolute-names don't strip leading `/'s from file names -h, --dereference dump instead the files symlinks point to --no-recursion avoid descending automatically in directories -l, --one-file-system stay in local file system when creating archive -K, --starting-file=NAME begin at file NAME in the archive -N, --newer=DATE only store files newer than DATE --newer-mtime compare date and time when data changed only --after-date=DATE same as -N --backup[=CONTROL] backup before removal, choose version control --suffix=SUFFIX backup before removal, override usual suffix Informative output: --help print this help, then exit --version print tar program version number, then exit -v, --verbose verbosely list files processed --checkpoint print directory names while reading the archive --totals print total bytes written while creating archive -R, --block-number show block number within archive with each message -w, --interactive ask for confirmation for every action --confirmation same as -w The backup suffix is `~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX. The version control may be set with --backup or VERSION_CONTROL, values are: t, numbered make numbered backups nil, existing numbered if numbered backups exist, simple otherwise never, simple always make simple backups GNU tar cannot read nor produce `--posix' archives. If POSIXLY_CORRECT is set in the environment, GNU extensions are disallowed with `--posix'. Support for POSIX is only partially implemented, don't count on it yet. ARCHIVE may be FILE, HOST:FILE or USER@HOST:FILE; and FILE may be a file or a device. *This* `tar' defaults to `-f- -b20'. Report bugs to . 生成的*.tar文件,可以进一步gzip压缩成*.tar.gz压缩包; gzip -9 ABC.tar 得到压缩包ABC.tar.gz tar也可用-z开关直接压缩成*.tgz压缩包。(tgz就是tar.gz的缩写) (1) 最常用用法: 压缩: tar -czf 压缩包名 被压目录或文件1 [被压目录或文件2 ...] 列表: tar -lxf 压缩包名 解压: tar [-C 解压目录] -xzf 压缩包名 提取: tar [-C 解压目录] -zf 压缩包名 --get 提取的文件名或目录名 ================================================= 10:输出分流器:tee Usage: tee [OPTION]... [文件1] [文件2 ...] Copy standard input to each FILE, and also to standard output. -a, --append 追加到文件中;否则先清除原有内容。 -i, --ignore-interrupts 忽略Ctrl-C等终止信号 --help display this help and exit --version output version information and exit If a FILE is -, copy again to standard output. 将前一命令的标准输出拷贝到每一个文件,同时输出到标准输出. 输出文件可以是-,表示再拷贝到标准输出一次。 (1) 最常用用法:前命令| tee my.log 前命令 2>&1| tee my.log ================================================= 11: 去除连续重复行:uniq 用法: uniq.exe [选项]... [输入文件 [输出文件]] Discard all but one of successive identical lines from INPUT (or standard input), writing to OUTPUT (or standard output). Mandatory arguments to long options are mandatory for short options too. -c, --count prefix lines by the number of occurrences -d, --repeated 只输出重复行 -D, --all-repeated[=delimit-method] print all duplicate lines delimit-method={none(default),prepend,separate} Delimiting is done with blank lines. -f, --skip-fields=N 比较时忽略开始 N 个域(词) -i, --ignore-case 比较时忽略大小写 -s, --skip-chars=N 比较时忽略开始 N 字符 -u, --unique 只输出唯一行 -w, --check-chars=N 一行中最多比较 N 字符 --help display this help and exit --version output version information and exit A field is a run of whitespace, then non-whitespace characters. Fields are skipped before chars. 默认:连续重复行 只保留一行。 一般先排序 (1) 最常用用法: 前命令| uniq [ - 输出文件] 前命令|sort| uniq [ - 输出文件] sort 文件| uniq [ - 输出文件] uniq 输入文件 [输出文件]