@mrz1
2018-01-01T14:17:39.000000Z
字数 13640
阅读 936
笔记
- linux-命令杂项
convert E:/fs:ntfs E盘装换NTFS格式Ping 192.168.139.130$ tasklist 查看进程
[root@zhang user1]# help hashhash: hash [-lr] [-p pathname] [-dt] [name ...]Remember or display program locations.Options:-d forget the remembered location of each NAME 清空指定的命令hash-l display in a format that may be reused as input 显示所有的-p pathname use PATHNAME is the full pathname of NAME-r forget all remembered locations 清空所有命令的hash-t print the remembered location of each NAME, precedingeach location with the corresponding NAME if multipleNAMEs are given 打印hash记录的命令位置
[root@zhang user1]# help historyhistory: history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg [arg...]Display or manipulate the history list.Display the history list with line numbers, prefixing each modifiedentry with a `*'. An argument of N lists only the last N entries.Options:-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 historylist 读取所有命令历史文件追加history 列表中-w write the current history to the history fileand append them to the history list 写当前的历史记录到文件中去-p perform history expansion on each ARG and display the resultwithout storing it in the history list-s append the ARGs to the history list as a single entryIf FILENAME is given, it is used as the history file. Otherwise,if $HISTFILE has a value, that is used, else ~/.bash_history.If the $HISTTIMEFORMAT variable is set and not null, its value is usedas a format string for strftime(3) to print the time stamp associatedwith each displayed history entry. No time stamps are printed otherwise.
- HISTSIZE:命令历史的条数
- HISTFILE:默认为
~/.bash_history- HISTFILESIZE:HISTFILE文件记录历史的条数
- -d: 删除指定的命令
- -c:清空命令
- -a:手工追加当前会话的命令历史到历史文件中去
- n :显示最近的n条命令
- !#:重复执行第#条命令
- !!:重复执行上一条命令
- !str:执行指定str开头的命令(最后一个)
- !?:获得最后执行的状态码
主要和HISTCONTROL这个环境变量有关(/etc/profile)
- ignoredups:忽略重复
- ignorespace:忽略空白开头
- ignoreboth:上面2个都启用
NAMEls - list directory contents 列出目录的内容SYNOPSISls [OPTION]... [FILE]...DESCRIPTIONList information about the FILEs (the current directory by default). Sortentries alphabetically if none of -cftuvSUX nor --sort is specified.Mandatory arguments to long options are mandatory for short options too.-a, --alldo not ignore entries starting with . 列出所有的, 包括隐藏文件-A, --almost-alldo not list implied . and .. 列出所有文件, 不包括.和..这2个--authorwith -l, print the author of each file 列出作者-b, --escapeprint C-style escapes for nongraphic characters 打印非打印符号用c-style--block-size=SIZEscale sizes by SIZE before printing them; e.g., '--block-size=M' printssizes in units of 1,048,576 bytes; see SIZE format below 指定大小单位-B, --ignore-backupsdo not list implied entries ending with ~ 不列出结尾是~的条目-c with -lt: sort by, and show, ctime (time of last modification of filestatus 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 'never', 'auto', or 'always' (thedefault); more info below 设置输出颜色-d, --directorylist directories themselves, not their contents 列出目录自身-D, --diredgenerate output designed for Emacs' dired mode 列出emacs目录模式-f do not sort, enable -aU, disable -ls --color 不做排序-F, --classifyappend indicator (one of */=>@|) to entries 在目录后面添加/--file-typelikewise, except do not append '*'--format=WORDacross -x, commas -m, horizontal -x, long -l, single-column -1, verbose-l, vertical -C--full-timelike -l --time-style=full-iso-g like -l, but do not list owner 不列出所有者--group-directories-firstgroup directories before files; 先列目录,在列出文件can be augmented with a --sort option, but any use of --sort=none (-U)disables grouping-G, --no-groupin a long listing, don't print group names 不打印组名字-h, --human-readable 文件大小自动调整为合适单位with -l, print sizes in human readable format (e.g., 1K 234M 2G)--si likewise, but use powers of 1000 not 1024 使用1000作为k,m的换算单位而不是1024-H, --dereference-command-linefollow symbolic links listed on the command line 追踪符号连接--dereference-command-line-symlink-to-dirfollow each command line symbolic linkthat points to a directory--hide=PATTERNdo not list implied entries matching shell PATTERN (overridden by -a or-A) 不列出匹配的正则--indicator-style=WORDappend indicator with style WORD to entry names: none (default), slash(-p), file-type (--file-type), classify (-F)-i, --inodeprint the index number of each file 打印inode号-I, --ignore=PATTERNdo not list implied entries matching shell PATTERN 不列出匹配的正则-k, --kibibytesdefault to 1024-byte blocks for disk usage-l use a long listing format 使用长格式显示-L, --dereferencewhen showing file information for a symbolic link, show information forthe file the link references rather than for the link itself 符号链接,显示连接到的文件-m fill width with a comma separated list of entries 条目逗号分割-n, --numeric-uid-gidlike -l, but list numeric user and group IDs 类似-l,只是用户名和组使用数字,而不是名字-N, --literalprint raw entry names (don't treat e.g. control characters specially)-o like -l, but do not list group information 不列出组信息-p, --indicator-style=slashappend / indicator to directories 追加/在目录后面-q, --hide-control-charsprint ? instead of nongraphic characters 打印?而不是不可打印的符号--show-control-charsshow nongraphic characters as-is (the default, unless program is 'ls'and output is a terminal)-Q, --quote-nameenclose entry names in double quotes 双引号包住列出的条目--quoting-style=WORDuse quoting style WORD for entry names: literal, locale, shell,shell-always, c, escape-r, --reversereverse order while sorting 反向排序-R, --recursivelist subdirectories recursively 递归列出子目录-s, --sizeprint the allocated size of each file, in blocks 打印分配的大小-S sort by file size 排序文件大小--sort=WORDsort by WORD instead of name: none (-U), size (-S), time (-t), version(-v), extension (-X)--time=WORDwith -l, show time as WORD instead of default modification time: atimeor access or use (-u) ctime or status (-c); also use specified time assort key if --sort=time--time-style=STYLEwith -l, show times using style STYLE: full-iso, long-iso, iso, locale,or +FORMAT; FORMAT is interpreted like in 'date'; if FORMAT is FOR‐MAT1<newline>FORMAT2, then FORMAT1 applies to non-recent files and FOR‐MAT2 to recent files; if STYLE is prefixed with 'posix-', STYLE takeseffect only outside the POSIX locale-t sort by modification time, newest first 排序按照mtime-T, --tabsize=COLSassume tab stops at each COLS instead of 8-u with -lt: sort by, and show, access time; with -l: show access time andsort by name; otherwise: sort by access time-U do not sort; list entries in directory order 按照目录的顺序累出-v natural sort of (version) numbers within text-w, --width=COLSassume 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 每行列出一个文件SELinux options:--lcontextDisplay security context. Enable -l. Lines will probably be too widefor most displays.-Z, --contextDisplay security context so it fits on most displays. Displays onlymode, user, group, security context and file name.--scontextDisplay only security context and file name.--help display this help and exit--versionoutput version information and exit
[root@zhang ~]# ls -ltotal 16-rw-r--r-- 1 root root 154 Sep 25 19:34 adduserbat.sh-:文件类型rw-r--r--:权限1: 文件被硬连接的次数root:文件的ownerroot:文件的group154:文件的大小Sep 25 19:34: 文件最近修改的时间adduserbat.sh: 文件名字
NAMEcat - concatenate files and print on the standard outputSYNOPSIScat [OPTION]... [FILE]...DESCRIPTIONConcatenate FILE(s), or standard input, to standard output.-A, --show-allequivalent to -vET 显示所有-b, --number-nonblanknumber nonempty output lines, overrides -n 编号非空行不编号-e equivalent to -vE-E, --show-endsdisplay $ at end of each line 每行结尾追加一个$-n, --numbernumber all output lines 每行添加一个行号-s, --squeeze-blanksuppress repeated empty output lines 压缩重复的空行-t equivalent to -vT-T, --show-tabsdisplay TAB characters as ^I-u (ignored)
NAMEecho - display a line of text 显示一行文本SYNOPSISecho [SHORT-OPTION]... [STRING]...echo LONG-OPTIONDESCRIPTIONEcho the STRING(s) to standard output.-n do not output the trailing newline 不显示自动换行-e enable interpretation of backslash escapes 启动转义符-E disable interpretation of backslash escapes (default) 关闭转义符--help display this help and exit--versionoutput version information and exitIf -e is in effect, the following sequences are recognized:\\ backslash 打印\\a alert (BEL) 警钟声音\b backspace 删除一个字符\c produce no further output\e escape\f form feed\n new line 新行\r carriage return 回车符\t horizontal tab 制表符\v vertical tab 水平制表符
[root@zhang ~]# echo -e "\033[34mOk\033[0m"Ok(这个字体是带颜色的)
\033[##m:控制颜色第一个#:控制字体的前景色第二个#:控制字体的背景色如果同时使用前景和背景色:\033[3#:4#m\033[0m:关闭字体功能
[root@zhang ~]# which lsalias ls='ls --color=auto'/usr/bin/ls[root@zhang ~]# which ls --skip-alias/usr/bin/ls
[root@zhang ~]# whatis lsls (1) - list directory contentsls (1p) - list directory contents
多个命令可以用;符号分开一个命令可以用\分成多行Shift+pgup向上翻页Shift+pgDn向下翻页$ cat /proc 查看进程文件Ctrl+d 退出$ ifconfig 查看ip$ pwd 查看完整目录$ lscpu$ cat /proc/partitions 查看分区$ echo '- - -' > /sys/class/scsi_host/host0/scan 扫描硬盘做实验用的$ ls /dev/sd* 查看分区$ cat /etc/centos-release 查看centos版本$ uname -r 内核版本$ rpm -qi kernel$ cd /bin 各种小工具$ bc 计算器 obase=8 八进制$ echo 8*9|bc 直接输出结果 组合工具$ shalsum /dev/sro 查看镜像是否损坏$ free 查看内存$ free -m 以MB查看内存$ cat /proc/meminfo 查看总内存$ lsblk 查看硬盘$ df -h$ halt 关机 6上面关机断电7之关机$ poweroff 关机断电$ whoami 查看当前用户$ tty 第几个终端$ halt 关机$ init 0 相当poweroff关机$ init 6 相当reboot 重启计算机重启: reboot-f: 强制,不调用shutdown-p: 切断电源$ init 3 关闭图形切换纯字符页面$ init 5 打开图形切换纯字符页面$ startx 也是打开图形$ runlevel 查看从3切换而来 上次没有事N$ who -r 查看从3切换而来 上次没有事N 更详细$ who am i$ who 多少终端登录$ cat $SHELL 当前使用的shell$ cat /etc/shells 查看系统使用的所有shell$ > a 创建一个a文件$ history 查看历史$ strace 查看系统调用$ ltrace 查看库函数$ echo $PS1 显示提示符格式$ exit 退出$ gedit 图形工具记事本$ nano 修改文本$ rz :上传文件$ nano /etc/profile.d/env.sh 配置颜色PS1="\[\e[1;32m\][\u@\h \W]\\$\[\e[0m\]"$ makewhatis$ touch 创建新文件$ info 查看帮助用法$ iconv 编码 iconv -f gb2312 课堂笔记.txt 转换$ chvt 3切换终端$ reset 重置 timedatectl set-teimzone PACIFIC/TONGATAPU 设置时区$ 时区修改 centos7:timedatectl centos6:tzselect$ tz:windows上传到linux上$ sz:linux传输文件到windows$ cat /etc/motd 登陆成功提示$ nano /etc/gdm/custom.conf 修改这个文件图形界面不用输入密码AutomaticLoginEnable=trueAutomaticLogin=root$help 内部命令列表$enable cmd 启用内部命令$enable –n cmd 禁用内部命令$enable –n 查看所有禁用的内部命令hash常见用法$ hash 显示hash缓存$ hash –l 显示hash缓存,可作为输入使用$ hash –p path name 将命令全路径path起别名为name$ hash –t name 打印缓存中name的路径$ hash –d name 清除name缓存$ hash –r 清除缓存$ which ls 查看缩写$ alias cdnet="cd /etc/sysconfig/network-scripts/" 定义别名 别名优先级最高$ unalias cdnet 取消别名$ nano .bashrc 修改别名文件永久保存$ souce 修改文件立马生效$ . .bashrc 修改文件立马生效如果别名与内部命令有冲突,`ifconfig`这样写就没没事了如果别名同原命令同名,如果要执行原命令,可使用“\COMMAND”`COMMAND`/PATH/COMMAND:外部命令$ nano /etc/bashrc 所有用户都能用自己修改的别名$ ps a$ id -u root$ w 查看所有用户在做什么$ nano /etc/issue 提示信息$rpm -i /run/media/fei/CentOS\ 7\ x86_64/Packages/screen-4.1.0-0.23.20120314git3c2946.el7_2.x86_64.rpm 安装插件$ 创建会话 screen -S help help起的名字$ 对方搜索会话 screen -ls 在连接会话 screen -x help$ 退出会话 ctrl+a+d$ exit全部退出$ echo -e "\a" 提示声音$ echo -e '1234\b\b\b56789' 显示156789$ echo -n abc 不换行$ echo -e '123\r456789' 覆盖前面显示456789$ echo -e '123\t456789' 相当于空格,不同系统不一定是几个空格123 456789$ echo -e '\033[43;31;5mmagedu\033[0m' 带颜色的字$ echo {1..20..2} 打印1 3 5 7 9 11 13 15 17 19刚安装后不可立即使用makewhatis 6|7 mandb制作数据库使用示例查看帮助:$ whatis cal 或 $ man –f cal下载bash到电脑$ man bash >bash.txt$ sz bash.txtcd /usr/share/doc 这个目录下是所有的文档的说明$ sosreport 收集信息发送给红帽重复前一个命令,有4种方法重复前一个命令使用上方向键,并回车执行按 !! 并回车执行输入 !-1 并回车执行按 Ctrl+p 并回车执行!:0 执行前一条命令(去除参数)Ctrl + n 显示当前历史中的下一条命令,但不执行!n 执行history命令输出对应序号n的命令!-n 执行history历史中倒数第n个命令!string 重复前一个以“string”开头的命令!?string 重复前一个包含string的命令!string:p 仅打印命令历史,而不执行!$:p 打印输出 !$ (上一条命令的最后一个参数)的内容!*:p 打印输出 !*(上一条命令的所有参数)的内容^string 删除上一条命令中的第一个string^string1^string2 将上一条命令中的第一个string1替换为string2!:gs/string1/string2 将上一条命令中所有的string1都替换为 stringctrl-r来在命令历史中搜索命令(reverse-i-search)Ctrl+g:从历史搜索模式退出要重新调用前一个命令中最后一个参数:!$ 表示Esc, .(点击Esc键后松开,然后点击 . 键)Alt+ .(按住Alt键的同时点击 . 键)command !^ : 利用上一个命令的第一个参数做cmd的参数command !$ : 利用上一个命令的最后一个参数做cmd的参数command !* : 利用上一个命令的全部参数做cmd的参数command !:n : 利用上一个命令的第n个参数做cmd的参数command !n:^ 调用第n条命令的第一个参数command !n:$ 调用第n条命令的最后一个参数command !n:m 调用第n条命令的第m个参数command !n:* 调用第n条命令的所有参数$ history 查看历史 内部命令$ history -c 清空内存里面历史先执行 > .bash_history 在执行history -c$ !8 根据编号执行编号的命令内存上默认存储多少echo $HISTSIZE 修改文件cat /etc/profile文件上默认存储多少echo $HISTFiLESIZE显示历史文件 $ echo $HISTFILEhistory -ps arg [arg...]-c: 清空命令历史-d offset: 删除历史中指定的第offset个命令n: 显示最近的n条历史-a: 追加本次会话新执行的命令历史列表至历史文件-r: 读历史文件附加到历史列表-w: 保存历史列表到指定的历史文件-n: 读历史文件中未读过的行到历史列表-p: 展开历史参数成多行,但不存在历史列表中-s: 展开历史参数成一行,附加在历史列表后HISTSIZE:命令历史记录的条数HISTFILE:指定历史文件,默认为~/.bash_historyHISTFILESIZE:命令历史文件记录历史的条数HISTTIMEFORMAT=“%F %T “ 显示时间HISTIGNORE=“str1:str2*:… “ 忽略str1命令, str2开头的历史控制命令历史的记录方式:环境变量: HISTCONTROLignoredups 默认,忽略重复的命令,连续且相同为“重复”ignorespace 忽略所有以空白开头的命令ignoreboth 相当于ignoredups, ignorespace的组合erasedups 删除重复命令export 变量名="值“存放在 /etc/profile 或 ~/.bash_profile$ systemctl enable autofs 启动自动挂载点 根目录多出misc net 两个目录$ ls /misc -a$ ls /misc/cd 挂载光盘$ ls cd/Packages/ 包目录$ cat /etc/DIR_COLORS 定义文件的颜色$ touch 创建文件如果存在只会刷新时间戳 $ stat f1 查看时间戳stat文件: metadata, data三个时间戳:access time:访问时间, atime,读取文件内容modify time: 修改时间, mtime,改变文件内容(数据)change time: 改变时间, ctime,元数据发生改变$ touch -t 201002151230.20 f1 只修改访问和修改时间$ touch -c f2 如果只刷新时间戳并不创建f2cp 常用选项-i:覆盖前提示 –n:不覆盖,注意两者顺序-r, -R: 递归复制目录及内部的所有内容-a: 归档,相当于-dR --preserv=all-d: --no-dereference --preserv=links 不复制原文件,只复制链接名--preserv[=ATTR_LIST]mode: 权限ownership: 属主属组timestamp:linksxattrcontextall-p: 等同--preserv=mode,ownership,timestamp-v: --verbose-f: --force-u:--update 只复制源比目标更新文件或目标不存在的文件--backup=numbered 目标存在,覆盖前先备份加数字后缀$ cp -av /etc/ /app/bbb 复制并显示详细信息$ cp /etc/issue f1 --backup=numbered 复制到f1 如果有就把原有的备份只能复制传统文件 不能复制字符文件比如$ cp /dev/zero /app/$ mknod /app/zero c 1 5 这样才可以$ mv f1/ root 如果存在root目录就是移动,不存在就是改名字$ rename '.log' '.log.bak' f* 把所有f*的.log 文件改成.log.bak$ rename file file0 file? 改格式把file改成fil01...rm [OPTION]... FILE...常用选项:-i: 交互式-f: 强制删除-r: 递归--no-preserve-roottree 显示目录树-d: 只显示目录-L level:指定显示的层级数目-P pattern: 只显示由指定pattern匹配到的路径mkdir 创建目录-p: 存在于不报错,且可自动创建所需的各目录-v: 显示详细信息-m MODE: 创建目录时直接指定权限rmdir 删除空目录-p: 递归删除父空目录-v: 显示详细信息rm -r 递归删除目录树alias cdnet="cd /etc/sysconfig/network-scripts/" 定义别名 别名优先级最高nano .bashrc定义别名 alias rm='mv -t /app/bak'保存 . .bashrcrm bash.txt 这个目录就到/app/bak下面了
Ctrl + l 清屏,相当于clear命令Ctrl + o 执行当前命令,并重新显示本命令Ctrl + s 阻止屏幕输出,锁定Ctrl + q 允许屏幕输出Ctrl + c 终止命令Ctrl + z 挂起命令Ctrl + a 光标移到命令行首,相当于HomeCtrl + e 光标移到命令行尾,相当于EndCtrl + f 光标向右移动一个字符Ctrl + b 光标向左移动一个字符Alt + f 光标向右移动一个单词尾Alt + b 光标向左移动一个单词首Ctrl + xx 光标在命令行首和光标之间移动Ctrl + u 从光标处删除至命令行首Ctrl + k 从光标处删除至命令行尾Alt + r 删除当前整行Ctrl + w 从光标处向左删除至单词首Alt + d 从光标处向右删除至单词尾Ctrl + d 删除光标处的一个字符Ctrl + h 删除光标前的一个字符Ctrl + y 将删除的字符粘贴至光标后Alt + c 从光标处开始向右更改为首字母大写的单词Alt + u 从光标处开始,将右边一个单词更改为大写Alt + l 从光标处开始,将右边一个单词更改为小写Ctrl + t 交换光标处和之前的字符位置Alt + t 交换光标处和之前的单词位置Alt + N 提示输入指定字符后,重复显示该字符N次注意: Alt组合快捷键经常和其它软件冲突应用程序->附件->终端支持多个“标签” shell的图形化终端模拟器Ctrl-Shift-n 创建新窗口Ctrl-Shift-q 关闭当前窗口Ctrl-Shift-t 创建一个标签页Ctrl-Shift-w 关闭一个标签页Ctrl-PaUp/PgUn 切换到下一个/前一个标签页Ctrl-Shift-c 复制选中的文本Ctrl-Shift-v 把文本粘帖到当前光标处
$ command 2Tab 所有子命令或文件补全$ string2Tab 以string开头命令$ /2Tab 显示所有根目录下一级目录,包括隐藏目录$ ./2Tab 当前目录下子目录,包括隐藏目录$ *2Tab 当前目录下子目录,不包括隐藏目录$ ~2Tab 所有用户列表$ $2Tab 所有变量$ @2Tab /etc/hosts记录 (centos7不支持)$ =2Tab 相当于ls –A (centos7不支持)