Shell命令ls、passwd、cd、type、which、printenv、date、cal
Linux的基本原则:
1、由目的单一的小程序组成:组合小程序完成复杂任务 2、一切皆文件 3、尽量避免捕获用户接口 4、配置文件保存为纯文本格式 GUI接口: 双击鼠标 CLI接口: 命令提示符,prompt,bash(shell) #:root $:普通用户 命令:命令会被shell送给内核,又内核判断是否具有执行权限以及能否执行,从什么地方开始执行。 [ [email?protected] ~]# lss(通过shell返回的错误信息) -bash: lss: command not found 命令格式: 命令 选项 参数 选项:修改命令的执行方式,选项可以有多个 短选项:一个横杠"-"引导跟一个字符,-character,多个选项彼此可以组合。 例如:-a -b = -ab 长选项:两个横线"--"引导跟一个单词,--word,长选项通常不能组合,必须要分开来写。 参数:命令的作用对象,这个命令对谁生效,可以跟多个参数,多个参数彼此用空格隔开。 [[email?protected] ~]# ls(不带选项) anaconda-ks.cfg pam_mysql-0.7-0.12.rc1.el6.x86_64.rpm cacti-0.8.8b.tar.gz Pictures [[email?protected] ~]# ls -l(-l选项详细信息) 总用量 310680 -rw-------. 1 root root 1394 4月 14 08:38 anaconda-ks.cfg -rw-r--r-- 1 root root 2272130 5月 14 20:14 cacti-0.8.8b.tar.gz drwxr-xr-x. 2 root root 4096 4月 15 21:27 Desktop drwxr-xr-x. 2 root root 4096 4月 15 21:27 Documents [[email?protected] ~]# ls -a(-a查看全部) . .gnote Pictures .. .gnupg Public .abrt .gstreamer-0.10 .pulse anaconda-ks.cfg .gtk-bookmarks .pulse-cookie [[email?protected] ~]# ls -a -l(多个选项,-a显示所有,-l详细信息) 总用量 310848 dr-xr-x---. 31 root root 4096 5月 31 23:30 . dr-xr-xr-x. 26 root root 4096 5月 21 20:43 .. drwxr-xr-x. 3 root root 4096 4月 15 21:55 .abrt -rw-------. 1 root root 1394 4月 14 08:38 anaconda-ks.cfg [[email?protected] ~]# ls -al(多个选项组合使用) 总用量 310848 dr-xr-x---. 31 root root 4096 5月 31 23:30 . dr-xr-xr-x. 26 root root 4096 5月 21 20:43 .. drwxr-xr-x. 3 root root 4096 4月 15 21:55 .abrt -rw-------. 1 root root 1394 4月 14 08:38 anaconda-ks.cfg [[email?protected] ~]# ls /etc/(命令加参数,不带参数显示当前目录) abrt enscript.cfg ld.so.cache pinforc [[email?protected] ~]# ls /root /var(命令跟多个参数使用) /root: anaconda-ks.cfg pam_mysql-0.7-0.12.rc1.el6.x86_64.rpm cacti-0.8.8b.tar.gz Pictures /var: account crash db ftp 如何实现用户登录和切换: [[email?protected] ~]# su student(切换到student用户,半切换,有root) [[email?protected] root]$ exit(退回原来的位置) exit [[email?protected] ~]# su -l student(切换到student用户,-l完全切换,没有root) [[email?protected] ~]$ [[email?protected] ~]$ exit(退出用户) logout 更换密码: [[email?protected] ~]# passwd(更改当前用户密码) Changing password for user root. New password: BAD PASSWORD: it is based on a dictionary word Retype new password: passwd: all authentication tokens updated successfully. Shelll: [[email?protected] ~]# ls(列出当前目录文件和子目录) anaconda-ks.cfg nagios-plugins-2.0.1 rrdtool-1.3.8-7.el6.x86_64.rpm cacti-0.8.8b.tar.gz pwd:Printing Working directory显示当前目录。 [[email?protected] ~]# pwd(显示当前所处的目录) /root [[email?protected] ~]# ls /root/(显示/root目录文件和子目录) anaconda-ks.cfg nagios-plugins-2.0.1 rrdtool-1.3.8-7.el6.x86_64.rpm cacti-0.8.8b.tar.gz ls:list列表,列出;可以列出所指定目录下的所有子目录或者文件。 [[email?protected] ~]# ls -l(显示当前目录文件子目录完整信息,-l显示完整信息) total 310680 -rw-------. 1 root root 1394 Apr 14 08:38 anaconda-ks.cfg(普通文件) -rw-r--r-- 1 root root 2272130 May 14 20:14 cacti-0.8.8b.tar.gz drwxr-xr-x. 2 root root 4096 Apr 15 21:27 Desktop(目录文件) drwxr-xr-x. 2 root root 4096 Apr 15 21:27 Documents [[email?protected] ~]# ls(list列表,列出;可以列出所指定目录下的所有子目录或者文件) anaconda-ks.cfg nagios-plugins-2.0.1 rrdtool-1.3.8-7.el6.x86_64.rpm cacti-0.8.8b.tar.gz [[email?protected] ~]# ls -l /dev/(查看/dev目录下的文件和子目录完整信息,-l长格式,显示完整信息,会显示文件很多属性) total 0 crw-rw---- 1 root video 10,175 May 21 20:43 agpgart(字符设备文件) crw-rw---- 1 root root 10,56 May 21 20:44 autofs lrwxrwxrwx 1 root root 3 May 21 20:43 cdrom -> sr0(符号连接文件) lrwxrwxrwx 1 root root 3 May 21 20:43 cdrw -> sr0 [[email?protected] ~]# ifconfig(查看主机地址) eth0 Link encap:Ethernet HWaddr 00:50:56:3A:91:69 inet addr:172.16.100.1 Bcast:172.16.100.255 Mask:255.255.255.0 inet6 addr: fe80::250:56ff:fe3a:9169/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:40 errors:0 dropped:0 overruns:0 frame:0 TX packets:47 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:4557 (4.4 KiB) TX bytes:5770 (5.6 KiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:868 errors:0 dropped:0 overruns:0 frame:0 TX packets:868 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:57236 (55.8 KiB) TX bytes:57236 (55.8 KiB) 使用Xshell 4登录Linux系统: Xshell:&; ping 172.16.100.1(测试能否ping通linux系统) 正在 Ping 172.16.100.1 具有 32 字节的数据: 来自 172.16.100.1 的回复: 字节=32 时间<1ms TTL=64 来自 172.16.100.1 的回复: 字节=32 时间<1ms TTL=64 172.16.100.1 的 Ping 统计信息: 数据包: 已发送 = 2,已接收 = 2,丢失 = 0 (0% 丢失), 往返行程的估计时间(以毫秒为单位): 最短 = 0ms,最长 = 0ms,平均 = 0ms Xshell:&; ssh 172.16.100.1(使用ssh连接linux主机) [[email?protected] ~]# ls -l /tmp/(查看/tmp目录下文件及子目录完整信息) total 44 -rw------- 1(文件硬连接次数) root(所有者) root 18009 May 29 19:44 yum_save_tx-2014-05-29-19-44KIYaTb.yumtx(能读能写不能执行) drwx------. 2 Smoke Smoke 4096 Apr 14 01:19 pulse-8G34pGhBrYlR drwxr-xr-x 2 root root 4096 May 29 19:39 puppet srwxr-xr-x 1 root root 0 May 18 02:43 mapping-root(套接字文件) [[email?protected] ~]# ls -l -h(查看当前目录文件及子目录完整信息并做单位换算,-l显示完整信息,-h单位换算) total 304M -rw-------. 1 root root 1.4K Apr 14 08:38 anaconda-ks.cfg -rw-r--r-- 1 root root 2.2M May 14 20:14 cacti-0.8.8b.tar.gz drwxr-xr-x. 2 root root 4.0K Apr 15 21:27 Desktop drwxr-xr-x. 2 root root 4.0K Apr 15 21:27 Documents [[email?protected] ~]# ls -lh(查看当前目录文件及子目录完整信息并做单位换算,-l显示完整信息,-h单位换算,组合选项) total 304M -rw-------. 1 root root 1.4K Apr 14 08:38 anaconda-ks.cfg -rw-r--r-- 1 root root 2.2M May 14 20:14 cacti-0.8.8b.tar.gz drwxr-xr-x. 2 root root 4.0K Apr 15 21:27 Desktop drwxr-xr-x. 2 root root 4.0K Apr 15 21:27 Documents [[email?protected] ~]# ls -a(显示当前目录的文件及子目录所有文件包括隐藏文件,-a代表all显示所有) . .lftp .. .local [[email?protected] ~]# ls .(显示当前目录文件及子目录) anaconda-ks.cfg pam_mysql-0.7-0.12.rc1.el6.x86_64.rpm cacti-0.8.8b.tar.gz Pictures [[email?protected] ~]# ls ..(显示上一级目录的文件及子目录) bin dev home lib64 media mnt opt root selinux srv tmp var boot etc lib lost+found misc net proc sbin shared sys usr [[email?protected] ~]# ls -A(选项-A显示所有文件,但不包括当.前目录和..上级目录) .abrt .local anaconda-ks.cfg .mozilla [[email?protected] ~]# ls -ld /root/(显示目录自身完整信息属性,-l显示完整信息,-d显示目录自身) dr-xr-x---. 31 root root 4096 Jun 1 14:43 /root/ [[email?protected] ~]# ls -i(显示当前目录的文件及子目录的索引节点号,-i显示索引节点号) 793872 anaconda-ks.cfg 786737 pam_mysql-0.7-0.12.rc1.el6.x86_64.rpm 793444 cacti-0.8.8b.tar.gz 790976 Pictures [[email?protected] ~]# ls -R(递归显示当前目录下的文件及子目录及子子目录文件,-R递归显示) .: anaconda-ks.cfg cacti-0.8.8b.tar.gz Desktop [[email?protected] ~]# ls -r(逆序排列显示当前目录下的子目录及文件,-r逆序显示) vmware-tools-distrib nrpe-2.15.tar.gz Videos nrpe-2.15 cd:change directory切换当前工作目录。 [[email?protected] ~]# pwd(显示当前所处目录,在/root目录) /root [[email?protected] ~]# cd /usr/(切换到/usr目录) [[email?protected] usr]# pwd(显示当前所在目录,在/usr目录) /usr [[email?protected] usr]# cd(cd不跟任何参数切换到用户家目录) [[email?protected] ~]# [[email?protected] ~]# cd /usr/(切换到/usr目录) [[email?protected] usr]# cd ~(cd加参数~波浪线回到用户家目录) [[email?protected] ~]# [[email?protected] ~]# cd ~student(cd加参数~用户名,切换到响应用户的家目录) [[email?protected] student]# pwd(显示当前所在的目录,在/home/student) /home/student [[email?protected] student]# cd(cd不跟任何参数切换到用户家目录) [[email?protected] ~]# cd -(cd加参数-,在前一个目录和当前目录进行来回切换) /home/student 命令类型: [[email?protected] ~]# type cd cd is a shell builtin(shell内建,内部命令) [[email?protected] ~]# type ls ls is aliased to `ls --color=auto‘(外部命令) [[email?protected] ~]# type su su is /bin/su(外部命令) [[email?protected] ~]# which ls(查看命令文件所在目录) alias ls=‘ls --color=auto‘ /bin/ls 当我们执行一个命令,并没有告诉它执行那个路径的下的什么命令,它是如何知道的,系统怎么能找到这个命令,按道理来讲我们引用任何一个文件都必须给它一个全路径,系统为了能够让用户能够便捷在命令提示符下执行命令,它给我们内置了一种机制,这种机制是通过一个叫环境变量方式来实现的。 [[email?protected] ~]# /bin/ls(全路径执行ls命令) anaconda-ks.cfg pam_mysql-0.7-0.12.rc1.el6.x86_64.rpm cacti-0.8.8b.tar.gz Pictures [[email?protected] ~]# clear(清屏) [[email?protected] ~]# clear [[email?protected] ~]# printenv(显示环境) HOSTNAME=Smoke(主机名) TERM=xterm(终端类型) SHELL=/bin/bash(使用的shell类型) HISTSIZE=1000 SSH_CLIENT=172.16.100.254 3901 22 QTDIR=/usr/lib64/qt-3.3 QTINC=/usr/lib64/qt-3.3/include SSH_TTY=/dev/pts/0 USER=root LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.tbz=01;31:*.tbz2=01;31:*.bz=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36: MAIL=/var/spool/mail/root PATH=/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin PWD=/root LANG=en_US.UTF-8 SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass HISTCONTROL=ignoredups SHLVL=1 HOME=/root LOGNAME=root QTLIB=/usr/lib64/qt-3.3/lib CVS_RSH=ssh SSH_CONNECTION=172.16.100.254 3901 172.16.100.1 22 LESSOPEN=|/usr/bin/lesspipe.sh %s DISPLAY=localhost:10.0 G_BROKEN_FILENAMES=1 _=/usr/bin/printenv OLDPWD=/home/student [[email?protected] ~]# hash(缓存的命令,hits代表命中多少次,使用多少次。) hits command 4 /bin/touch 1 /usr/bin/printenv 13 /bin/ls 1 /usr/bin/clear 显示系统时间: [[email?protected] ~]# date(显示系统时间) Sun Jun 1 20:07:38 CST 2014 [[email?protected] ~]# clock(显示硬件时间) Sun 01 Jun 2014 08:19:14 PM CST -0.393199 seconds [[email?protected] ~]# hwclock(显示硬件时间) Sun 01 Jun 2014 08:19:51 PM CST -0.535787 seconds 如何获得命令的使用帮助: [[email?protected] ~]# help cd(查看内部命令cd的帮助) cd: cd [-L|-P] [dir] Change the shell working directory. Options: -L force symbolic links to be followed -P use the physical directory structure without following symbolic links The default is to follow symbolic links,as if `-L‘ were specified. Exit Status: Returns 0 if the directory is changed; non-zero otherwise. [[email?protected] ~]# ls --help(查看外部命令ls的使用帮助) Usage: ls [OPTION]... [FILE]... List information about the FILEs (the current directory by default). Sort entries alphabetically if none of -cftuvSUX nor --sort. 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 octal escapes for nongraphic characters --block-size=SIZE use SIZE-byte blocks. 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 -C list entries by columns --color[=WHEN] colorize the output. WHEN defaults to `always‘ or can be `never‘ or `auto‘. More info below -d,--directory list directory entries instead of contents,and do not dereference symbolic links -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. augment 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,print sizes in human readable format (e.g.,1K 234M 2G) --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) --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 like --block-size=1K -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 raw entry names (don‘t treat e.g. control characters specially) -o like -l,but do not list group information -p,--indicator-style=slash append / indicator to directories -q,--hide-control-chars print ? instead of non graphic characters --show-control-chars show non graphic characters as-is (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,c,escape -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 --sort=WORD sort by WORD instead of name: none -U,extension -X,size -S,time -t,version -v --time=WORD with -l,show time as WORD instead of modification time: atime -u,access -u,use -u,ctime -c,or status -c; use specified time as sort key if --sort=time --time-style=STYLE with -l,show times using style STYLE: full-iso,long-iso,iso,+FORMAT. FORMAT is interpreted like `date‘; if FORMAT is FORMAT1<newline>FORMAT2,FORMAT1 applies to non-recent files and FORMAT2 to recent files; if STYLE is prefixed with `posix-‘,STYLE takes effect only outside the POSIX locale -t sort by modification time -T,--tabsize=COLS assume tab stops at each COLS instead of 8 -u with -lt: sort by,access time with -l: show access time and sort 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=COLS assume 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: --lcontext Display security context. Enable -l. Lines will probably be too wide for most displays. -Z,--context Display security context so it fits on most displays. Displays only mode,user,group,security context and file name. --scontext Display only security context and file name. --help display this help and exit --version output version information and exit SIZE may be (or may be an integer optionally followed by) one of following: KB 1000,K 1024,MB 1000*1000,M 1024*1024,and so on for G,T,P,E,Z,Y. 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). [[email?protected] ~]# man ls(查看ls命令的使用手册) LS(1) User Commands LS(1) NAME(命令名字) ls - list directory contents(简要功能说明) SYNOPSIS(使用格式说明) ls [OPTION]... [FILE]... DESCRIPTION(使用描述) List information about the FILEs (the current directory by default). Sort entries alphabetically if none of -cftuvSUX nor --sort. 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 octal escapes for nongraphic characters --block-size=SIZE use SIZE-byte blocks. See SIZE format below -B,--ignore-backups do not list implied entries ending with ~ -c with -lt: sort by,ctime (time of last modification of file status information) with -l: show ctime and sort by name otherwise: sort by ctime -C list entries by columns --color[=WHEN] colorize the output. WHEN defaults to ‘always‘ or can be ‘never‘ or ‘auto‘. More info below -d,--directory list directory entries instead of contents,and do not dereference symbolic links -D,--dired generate output designed for Emacs‘ dired mode -f do not sort,disable -ls --color -F,--classify append indicator (one of */=>@|) to entries --file-type likewise,except do not append ‘*‘ --format=WORD across -x,ver- tical -C --full-time like -l --time-style=full-iso -g like -l,but do not list owner --group-directories-first group directories before files. augment 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,print sizes in human readable format (e.g.,1K 234M 2G) --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) --indicator-style=WORD append indicator with style WORD to entry names: none (default),slash (-p),classify (-F) -i,--inode print the index number of each file -I,--ignore=PATTERN do not list implied entries matching shell PATTERN -k like --block-size=1K -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 raw entry names (don‘t treat e.g. control characters specially) -o like -l,but do not list group information -p,--indicator-style=slash append / indicator to directories -q,--hide-control-chars print ? instead of non graphic characters --show-control-chars show non graphic characters as-is (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,escape -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 --sort=WORD sort by WORD instead of name: none -U,version -v --time=WORD with -l,show time as WORD instead of modification time: atime -u,use -u,or status -c; use specified time as sort key if --sort=time --time-style=STYLE with -l,show times using style STYLE: full-iso,+FORMAT. FORMAT is interpreted like ‘date‘; if FORMAT is FORMAT1<newline>FORMAT2,FORMAT1 applies to non-recent files and FORMAT2 to recent files; if STYLE is prefixed with ‘posix-‘,STYLE takes effect only outside the POSIX locale -t sort by modification time -T,--tabsize=COLS assume tab stops at each COLS instead of 8 -u with -lt: sort by,access time with -l: show access time and sort 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=COLS assume 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: --lcontext Display security context. Enable -l. Lines will probably be too wide for most displays. -Z,--context Display security context so it fits on most displays. Displays only mode,security context and file name. --scontext Display only security context and file name. --help display this help and exit --version output version information and exit SIZE may be (or may be an integer optionally followed by) one of following: KB 1000,K 1024,Y. 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.,2 if serious trouble (e.g.,cannot access command-line argument). AUTHOR(作者) Written by Richard M. Stallman and David MacKenzie. REPORTING BUGS(如果发现命令有BUG将信息发送给谁) Report ls bugs to [email?protected] GNU coreutils home page: < http://www.gnu.org/software/coreutils/ > General help using GNU software: < http://www.gnu.org/gethelp/ > Report ls translation bugs to < http://translationproject.org/team/ > COPYRIGHT(版权) Copyright 2010 Free Software Foundation(自由软件基金会),Inc. License GPLv3+: GNU GPL version 3 or later < http://gnu.org/licenses/gpl.html >. This is free software: you are free to change and redistribute it. There is NO WAR- RANTY,to the extent permitted by law. SEE ALSO(如果想获得进一步信息请查看) The full documentation for ls is maintained as a Texinfo manual. If the info and ls programs are properly installed at your site,the command info coreutils ‘ls invocation‘ should give you access to the complete manual. GNU coreutils 8.4 March 2014 LS(1) [[email?protected] ~]# man cd(内部命令man帮助,man的不是这个命令,而是这个命令所属的shell) BASH_BUILTINS(1) BASH_BUILTINS(1) NAME bash,:,.,[,alias,bg,bind,break,builtin,caller,cd,command,compgen,complete,compopt,continue,declare,dirs,disown,echo,enable,eval,exec,exit,export,false,fc,fg,getopts,hash,help,history,jobs,kill,let,local,logout,mapfile,popd,printf,pushd,pwd,read,readonly,return,set,shift,shopt,source,suspend,test,times,trap,true,type,typeset,ulimit,umask,unalias,unset,wait - bash built-in commands,see bash(1) [[email?protected] ~]# man 2 read(查看read第2章节系统调用章节) READ(2) Linux Programmer‘s Manual(linux开发人员手册) READ(2) NAME read - read from a file descriptor SYNOPSIS #include <unistd.h>(这是一个系统调用) ssize_t read(int fd,void *buf,size_t count); DESCRIPTION read() attempts to read up to count bytes from file descriptor fd into the buffer start- ing at buf. If count is zero,read() returns zero and has no other results. If count is greater than SSIZE_MAX,the result is unspecified. [[email?protected] ~]# export LANG="en"(修改语言编码方式为english) [[email?protected] ~]# man mount(查看mount的man帮助在第8章节) MOUNT(8) Linux Programmer‘s Manual MOUNT(8) NAME mount - mount a filesystem SYNOPSIS mount [-lhV] mount -a [-fFnrsvw] [-t vfstype] [-O optlist] mount [-fnrsvw] [-o option[,option]...] device|dir mount [-fnrsvw] [-t vfstype] [-o options] device dir [[email?protected] ~]# whatis read(查看read命令man帮助在第几章节) read (1p) - read a line from standard input read (2) - read from a file descriptor read (3p) - read from a file read [builtins] (1) - bash built-in commands,see bash(1) [[email?protected] ~]# man 4 tty(查看第四章man帮助节特殊文件) TTY(4) Linux Programmer‘s Manual TTY(4) NAME tty - controlling terminal(用于控制终端) DESCRIPTION The file /dev/tty(对应设备文件) is a character(字符文件) file with major number 5(主号码) and minor number 0(次号码),usually of mode 0666 and owner.group root.tty. It is a synonym for the controlling terminal of a process,if any. In addition to the ioctl(2) requests supported by the device that tty refers to,the ioctl(2) request TIOCNOTTY is supported. [[email?protected] ~]# cat /etc/passwd(查看/etc/passwd文件内容,这个文件是由格式的通过冒号:隔开) root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin [[email?protected] ~]# man passwd(显示的是命令的帮助) PASSWD(1) User utilities PASSWD(1) NAME passwd - update user‘s authentication tokens SYNOPSIS passwd [-k] [-l] [-u [-f]] [-d] [-e] [-n mindays] [-x maxdays] [-w warndays] [-i inac- tivedays] [-S] [--stdin] [username] [[email?protected] ~]# man 5 passwd(显示passwd每隔冒号是什么意思,在第五章文件格式) PASSWD(5) Linux Programmer‘s Manual PASSWD(5) NAME passwd - password file(用户的密码文件) [[email?protected] ~]# man man(获得man的man手册) man(1) man(1) NAME man - format and display the on-line manual pages SYNOPSIS man [-acdfFhkKtwW] [--path] [-m system] [-p string] [-C config_file] [-M pathlist] [-P pager] [-B browser] [-H htmlpager] [-S section_list] [section] name ... man对命令的描述: [[email?protected] ~]# man date(查看date命令的man帮助) DATE(1) User Commands DATE(1) NAME date - print or set the system date and time SYNOPSIS date [OPTION]... [+FORMAT](中括号[]括起来可省略,...表示可以出现多次,可以有多个选项) date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]](中间竖线表示二选一或多选一,只能选择一个不能同时使用) date: date - print or set the system date and time date [OPTION]... [+FORMAT](格式) date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]](修改系统时间,月日小时分钟年.秒) FORMAT(格式): %D date; same as %m/%d/%y(显示月日年) %y last two digits of year (00..99)(显示两位年) %Y year(显示四位年) %d day of month (e.g,01)(显示一个月的第几天) %n a newline(换行) %T time; same as %H:%M:%S(显示小时分钟秒) %F full date; same as %Y-%m-%d(显示年月日) %M minute (00..59)(分钟) %S second (00..60)(显示秒) %s seconds since 1970-01-01 00:00:00 UTC(时间戳,Unix元年计时法,从1970年01月01日00点00分00秒至此刻为止经过的秒数) [[email?protected] ~]# date 0601220514.30(更改系统时间为6月1日22点05分14年30秒) Sun Jun 1 22:05:30 CST 2014 [[email?protected] ~]# date +%D(显示月日年) 06/01/14 [[email?protected] ~]# date +%Y(显示四位年) 2014 [[email?protected] ~]# date +%y(显示两位年) 14 [[email?protected] ~]# date +"This year is %Y"(可以带字符原封不动显示年) This year is 20 [[email?protected] ~]# date +"This year is %Y."(可以带字符和标点符号原封不动显示年) This year is 2014. [[email?protected] ~]# date +%d(显示今天是这个月第几天) 01 [[email?protected] ~]# date +"This year is %Y. Today is %d."(显示年,并显示今天是这个月第几条,加入其他字符标点符号显示) This year is 2014. Today is 01. [[email?protected] ~]# date +"This year is %Y. %nToday is %d."显示年,并显示今天是这个月第几条,加入其他字符标点符号显示,并通过%n换行显示) This year is 2014. Today is 01. [[email?protected] ~]# date +%T(显示小时分钟秒) 22:26:14 [[email?protected] ~]# date +%F(显示年月日) 2014-06-01 [[email?protected] ~]# date +%Y-%m-%d(显示年月日,横线-隔开) 2014-06-01 [[email?protected] ~]# date +%H:%M(显示几点几分,冒号:隔开) 22:29 [[email?protected] ~]# date +%H-%M(显示几点几分,横线-隔开) 22-30 [[email?protected] ~]# date +%s(显示时间戳,从1970.01.01.00.00.00到现在经过的秒数) 1401633375 clock:查看硬件时间,等同于hwclock [[email?protected] ~]# clock(查看硬件时间) Sun 01 Jun 2014 10:39:07 PM CST -0.220458 seconds [[email?protected] ~]# hwclock -w(将系统时间同步到硬件,改硬件时间) [[email?protected] ~]# clock(查看硬件时间) Sun 01 Jun 2014 10:41:11 PM CST -0.127240 seconds [[email?protected] ~]# date 03151132(更改系统时间为错误时间) Sat Mar 15 11:32:00 CST 2014 [[email?protected] ~]# hwclock -s(把硬件时间同步到系统时间,改系统时间) [[email?protected] ~]# date Sun Jun 1 22:43:11 CST 2014 [[email?protected] ~]# man hwclock(查看hwclock的man文档) [[email?protected] ~]# hwclock -r(显示硬件时间) Sun 01 Jun 2014 10:48:40 PM CST -0.112417 seconds 在线文档: [[email?protected] ~]# info ls(查看ls命令的在线文档) 文档:/usr/share/doc:几乎所有的命令文档都有。 [[email?protected] ~]# cd /usr/share/doc/(命令手册文档目录) [[email?protected] doc]# ls(查看目录下的文件及子目录) abrt-2.0.8 libstdc++-devel-4.4.7 abyssinica-fonts-1.0 libtar-1.2.11 cal: calendar日历 [[email?protected] ~]# cal(查看日历) June 2014 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 [[email?protected] ~]# cal 2013(2013年的年历) 2013 January February March Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 2 3 4 5 1 2 1 2 6 7 8 9 10 11 12 3 4 5 6 7 8 9 3 4 5 6 7 8 9 13 14 15 16 17 18 19 10 11 12 13 14 15 16 10 11 12 13 14 15 16 20 21 22 23 24 25 26 17 18 19 20 21 22 23 17 18 19 20 21 22 23 27 28 29 30 31 24 25 26 27 28 24 25 26 27 28 29 30 31 April May June Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 1 2 3 4 1 7 8 9 10 11 12 13 5 6 7 8 9 10 11 2 3 4 5 6 7 8 14 15 16 17 18 19 20 12 13 14 15 16 17 18 9 10 11 12 13 14 15 21 22 23 24 25 26 27 19 20 21 22 23 24 25 16 17 18 19 20 21 22 28 29 30 26 27 28 29 30 31 23 24 25 26 27 28 29 30 July August September Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 1 2 3 1 2 3 4 5 6 7 7 8 9 10 11 12 13 4 5 6 7 8 9 10 8 9 10 11 12 13 14 14 15 16 17 18 19 20 11 12 13 14 15 16 17 15 16 17 18 19 20 21 21 22 23 24 25 26 27 18 19 20 21 22 23 24 22 23 24 25 26 27 28 28 29 30 31 25 26 27 28 29 30 31 29 30 October November December Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 2 3 4 5 1 2 1 2 3 4 5 6 7 6 7 8 9 10 11 12 3 4 5 6 7 8 9 8 9 10 11 12 13 14 13 14 15 16 17 18 19 10 11 12 13 14 15 16 15 16 17 18 19 20 21 20 21 22 23 24 25 26 17 18 19 20 21 22 23 22 23 24 25 26 27 28 27 28 29 30 31 24 25 26 27 28 29 30 29 30 31 [[email?protected] ~]# cal 12 2012(2012年12月日历) December 2012 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 练习: [[email?protected] ~]# type echo(查看echo命令类型,为内部命令) echo is a shell builtin 2、其作用? [[email?protected] ~]# help echo(查看echo命令帮助) [[email?protected] ~]# man echo(查看echo命令man文档) NAME echo - display a line of text(显示一行文本) SYNOPSIS echo [SHORT-OPTION]... [STRING]... echo LONG-OPTION [[email?protected] ~]# echo(打印文本,默认自动换行) echo默认动作,不管输入什么文本都会打印并进行换行 [[email?protected] ~]# echo -n(显示文本不换行) [[email?protected] ~]# echo "The year is 2013. Today is 26."(显示字符) The year is 2013. Today is 26. 3、如何显示"The year is 2013. Today is 26."为两行? [[email?protected] ~]# echo -e "The year is 2013. nToday is 26."(显示字符串,并通过-e选项开启反斜杠转义n进行换行) The year is 2013. Today is 26. [[email?protected] ~]# echo -e "The year is 2013.bToday is 26."(显示字符串,并通过-e选项开启反斜杠转义b退一格删除.点号) The year is 2013Today is 26. [[email?protected] ~]# echo -e "The year is 2013.bbToday is 26."(退格两次) The year is 201Today is 26. [[email?protected] ~]# echo -e "The year is 2013.tToday is 26."(显示字符串,并通过-e选项开启反斜杠转义t横向tab空白) The year is 2013. Today is 26. [[email?protected] ~]# echo -e "The year is 2013.vToday is 26."."(显示字符串,并通过-e选项开启反斜杠转义v纵向tab空白) The year is 2013. Today is 26. [[email?protected] ~]# echo -n "The year is 2013."(显示字符串,-n不换行显示,默认自动换行_ The year is 2013.[[email?protected] ~]# 练习: [[email?protected] ~]# type printf(查看printf命令类型,内部命令) printf is a shell builtin 2、其作用? [[email?protected] ~]# man printf(查看printf命令man文档) NAME printf - format and print data(格式化并显示数据) SYNOPSIS printf FORMAT(格式) [ARGUMENT]...(参数) printf OPTION n:换行符 [[email?protected] ~]# printf "The year is 2013."(格式化并显示数据,默认不会换行) The year is 2013.[[email?protected] ~]# [[email?protected] ~]# printf "The year is 2013.n"(格式化并显示数据,使用n换行;默认不会换行) The year is 2013. [[email?protected] ~]# printf "The year is 2013.nToday is 26."(格式化并显示数据,并通过n将两行字符串换行,但最后一行还没换行) The year is 2013. Today is 26.[[email?protected] ~]# [[email?protected] ~]# printf "The year is 2013.nToday is 26.n"(格式化并显示数据,并通过n将两行字符全部换行) The year is 2013. Today is 26. file命令及其用法: [[email?protected] ~]# file install.log install.log: UTF-8 Unicode text [[email?protected] ~]# file -b install.log <== 不显示文件名称 UTF-8 Unicode text [[email?protected] ~]# file -i install.log <== 显示MIME类别。 install.log: text/plain; charset=utf-8 [[email?protected] ~]# file -b -i install.log text/plain; charset=utf-8 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |