常用命令:
pwd:print working directory,查看当前的工作目录;
cd ~user_name:进入用户的家目录;
[root@centos7l ~]# cd ~bob [root@centos7l bob]#
ln file link:创建硬链接;
注:硬链接不能参考不在同一个分区上的文件
硬链接不能参考目录
ln -s item link:创建软链接;
注:软链接可以参考目录
type :显示一个命令的类型;
which:显示一个可执行命令的位置,对bash内置命令和alias不起作用;
man:(man的分类)
1 User commands--一般的用户命令
2 Programming interfaces kernel system calls--编程接口的内核系统调用
3 Programming interfaces to the C library--C语言库的编程接口
4 Special files such as device nodes and drivers--特殊文件比如设备号和驱动
5 File formats--文件格式
6 Games and amusements such as screen savers--游戏娱乐
7 Miscellaneous--杂项
8 System administration commands--系统管理员命令相关
man 5 passwd:查看passwd命令的man文档的第五部分;
apropos:显示合适的命令
[root@centos7rzc ~]# apropos floppy fd (4) - floppy disk device fdformat (8) - low-level format a floppy disk mbadblocks (1) - tests a floppy disk, and marks the bad blocks in the FAT mformat (1) - add an MSDOS filesystem to a low-level formatted floppy disk
whatis:显示一个命令的简单描述
[root@centos7rzc ~]# whatis ls ls (1) - list directory contents ls (1p) - list directory contents
info有关操作:
?——Display command help
PgUp or Backspace——Display previous page
PgDn or Space——Display next page
n Next——Display the next node
p Previous——Display the previous node
u Up——Display the parent node of the currently displayed
node, usually a menu.
Enter——Follow the hyperlink at the cursor location
q——Quit
/usr/share/doc:这个目录下有很多程序的帮助文档;
使用alias创建自己的命令:
[root@centos7rzc ~]# alias foo="cd /usr;ls -l;cd -" [root@centos7rzc ~]# foo total 300 dr-xr-xr-x. 2 root root 81920 Feb 13 08:29 bin drwxr-xr-x. 2 root root 4096 Jun 9 2014 etc drwxr-xr-x. 2 root root 4096 Jun 9 2014 games drwxr-xr-x. 177 root root 16384 Dec 21 11:16 include dr-xr-xr-x. 49 root root 4096 Feb 13 08:28 lib dr-xr-xr-x. 204 root root 135168 Dec 21 11:17 lib64 drwxr-xr-x. 46 root root 12288 Dec 21 11:14 libexec drwxr-xr-x. 12 root root 4096 Dec 21 10:08 local dr-xr-xr-x. 2 root root 20480 Feb 13 08:29 sbin drwxr-xr-x. 330 root root 12288 Dec 21 11:17 share drwxr-xr-x. 4 root root 4096 Dec 21 10:08 src lrwxrwxrwx. 1 root root 10 Dec 21 10:08 tmp -> ../var/tmp /root [root@centos7rzc ~]#
(使用unalias可以解除alias定义的命令:unalias foo)
直接键入alias可以查看系统定义好的alias:
[root@centos7rzc ~]# alias alias cp='cp -i' alias egrep='egrep --color=auto' alias fgrep='fgrep --color=auto' alias foo='cd /usr;ls -l;cd -' alias grep='grep --color=auto' alias l.='ls -d .* --color=auto' alias ll='ls -l --color=auto' alias ls='ls --color=auto' alias mv='mv -i' alias perlll='eval `perl -Mlocal::lib`' alias rm='rm -i' alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
重定向:(0表示标准输入,1表示标准输出,2表示标准错误输出)
输出重定向
[root@centos7rzc ~]# ls -l > test.txt #重定向 [root@centos7rzc ~]# cat test.txt total 64 -rwxr-xr-x. 1 root root 148 Feb 27 05:00 0227_2.sh -rwxr-xr-x. 1 root root 696 Feb 27 05:53 02273.sh ...... drwxr-xr-x. 7 root root 4096 Nov 20 16:49 vmware-tools-distrib
[root@centos7rzc ~]# (cd /usr;ls -l;cd -)>>test.txt #追加重定向 [root@centos7rzc ~]# cat test.txt total 64 -rwxr-xr-x. 1 root root 148 Feb 27 05:00 0227_2.sh ...... drwxr-xr-x. 7 root root 4096 Nov 20 16:49 vmware-tools-distrib total 300 dr-xr-xr-x. 2 root root 81920 Feb 13 08:29 bin drwxr-xr-x. 2 root root 4096 Jun 9 2014 etc
(上下连接起来看) ...... lrwxrwxrwx. 1 root root 10 Dec 21 10:08 tmp -> ../var/tmp /root
错误输出重定向:
[root@centos7rzc ~]# ls /noexist 2>err.txt You have new mail in /var/spool/mail/root [root@centos7rzc ~]# cat err.txt ls: cannot access /noexist: No such file or directory
重定向stdout和stderr到同一个文件
$ ls -l /bin/usr > ls-output.txt 2>&1
或者
$ ls -l /bin/usr &> ls-output.txt
$ ls -l /bin/usr &>> ls-output.txt
uniq - 输出或者过滤重复行;
tee –从标准输入读取输入,然后输出到标准输出和文件;