[root@rhel7 ~]# hostname www.dabao.com [root@rhel7 ~]# groupadd tom [root@rhel7 ~]# useradd -g tom tom [root@rhel7 ~]# id tom uid=501(tom) gid=501(tom) groups=501(tom) [root@rhel7 ~]# su - tom [tom@rhel7 ~]$ who root tty1 2016-03-20 23:56 (:0) root pts/0 2016-03-21 00:39 (:0.0)
常用的命令
ls
常用参数
含义及用法
-l
long 的缩写 详细列出当前目录下的所有文件属性 七列 文件名 <=255 个字符
-d
directory 的缩写 查看当前目录本身的信息
-h
以人性化的方式显示文件大小,录的大小并不代表目录内所有文件的大小 du -sh /etc<== 查看 etc 目录真正的大小
-a
查看隐藏文件 以 . 开头的文件
-R
查看多层目录
-b
特殊字符将以 \ 分割 ls 查看有特殊字符的文件
ls实验
[tom@rhel7 tmp]$ ls -hl total 68K srwxr-xr-x. 1 root root 0 Mar 20 23:59 gedit.root.3177893063 drwx------. 2 root root 4.0K Feb 5 18:24 keyring-JL7MKY [tom@rhel7 tmp]$ ls -ld /tmp drwxrwxrwt. 22 root root 4096 Mar 21 00:43 /tmp [tom@rhel7 tmp]$ ls -la /tmp total 96 drwxrwxrwt. 22 root root 4096 Mar 21 00:43 . dr-xr-xr-x. 29 root root 4096 Mar 20 23:55 .. drwx------. 2 root root 4096 Mar 20 23:56 .esd-0 drwx------. 2 cong cong 4096 Jan 1 18:33 .esd-500 [tom@rhel7 tmp]$ ls -bl -rw-rw-r--. 1 tom tom 0 Mar 21 00:48 a\ b.txt [tom@rhel7 tmp]$ ls -l -rw-rw-r--. 1 tom tom 0 Mar 21 00:48 a b.txt [tom@rhel7 tmp]$ mkdir -p a/b/c [tom@rhel7 tmp]$ ls -lR a/ a/: total 4 drwxrwxr-x. 3 tom tom 4096 Mar 21 00:50 b a/b: total 4 drwxrwxr-x. 2 tom tom 4096 Mar 21 00:50 c a/b/c: total 0
cd
cd
change directory 切换工作目录
绝对路径
以根为起始的路径
相对路径
~当前用户的家目录 ;. 当前目录 ;.. 上一层用户 ;- 回到上一次所在位置
cd实验
[tom@rhel7 tmp]$ cd /etc/ [tom@rhel7 etc]$ cd ~ [tom@rhel7 ~]$ cd . [tom@rhel7 ~]$ cd .. [tom@rhel7 home]$ cd - /home/tom
pwd
pwd:print working directory 显示当前所在位置的绝对路径
pwd实验
[tom@rhel7 tmp]$ cd /etc/nginx [tom@rhel7 nginx]$ cd conf.d [tom@rhel7 conf.d]$ pwd /etc/nginx/conf.d
[tom@rhel7 ~]$ ls -l --full-time total 0 -rw-rw-r--. 1 tom tom 0 2016-03-21 01:31:22.853039590 +0800 testa_1 -rw-rw-r--. 1 tom tom 0 2016-03-21 01:31:22.853039590 +0800 testa_2 -rw-rw-r--. 1 tom tom 0 2016-03-21 01:31:22.853039590 +0800 testa_3 -rw-rw-r--. 1 tom tom 0 2016-03-21 01:31:22.853039590 +0800 testa_4 -rw-rw-r--. 1 tom tom 0 2016-03-21 01:31:22.853039590 +0800 testb_1 -rw-rw-r--. 1 tom tom 0 2016-03-21 01:31:22.853039590 +0800 testb_2 -rw-rw-r--. 1 tom tom 0 2016-03-21 01:31:22.853039590 +0800 testb_3 -rw-rw-r--. 1 tom tom 0 2016-03-21 01:31:22.853039590 +0800 testb_4 -rw-rw-r--. 1 tom tom 0 2016-03-21 01:31:22.854039544 +0800 testc_1 -rw-rw-r--. 1 tom tom 0 2016-03-21 01:31:22.854039544 +0800 testc_2 -rw-rw-r--. 1 tom tom 0 2016-03-21 01:31:22.854039544 +0800 testc_3 -rw-rw-r--. 1 tom tom 0 2016-03-21 01:31:22.854039544 +0800 testc_4
[tom@rhel7 ~]$ touch "ab cd"
[tom@rhel7 ~]$ ls -b ab\ \ \ cd testa_3 testb_2 testc_1 testc_4 testa_1 testa_4 testb_3 testc_2 testa_2 testb_1 testb_4 testc_3
[tom@rhel7 ~]$ mkdir -p test/test1 [tom@rhel7 ~]$ ls ab cd testa_3 testb_2 testc_1 testc_4 p testa_4 testb_3 testc_2 test testb_1 testb_4 testc_3 [tom@rhel7 ~]$ mkdir {a..f} [tom@rhel7 ~]$ ls a d test testb_2 testc_2 ab cd e testa_3 testb_3 testc_3 b f testa_4 testb_4 testc_4 c p testb_1 testc_1 [tom@rhel7 ~]$ touch {a..f}/file{1..4} [tom@rhel7 ~]$ ls a d test testb_2 testc_2 ab cd e testa_3 testb_3 testc_3 b f testa_4 testb_4 testc_4 c p testb_1 testc_1 [tom@rhel7 ~]$ ls -rR .: testc_4 testb_4 testa_4 f b testc_3 testb_3 testa_3 e ab cd testc_2 testb_2 test d a testc_1 testb_1 p c ./test: test1 ./test/test1: ./p: ./f: file4 file3 file2 file1 ./e: file4 file3 file2 file1 ./d: file4 file3 file2 file1 ./c: file4 file3 file2 file1 ./b: file4 file3 file2 file1 ./a: file4 file3 file2 file1
rmdir
rmdir:remove directory 删除目录
只能删除空目录,出于安全性的考虑
rm -rf [d_name]
可以删除非空目录
rmdir 实验
[booboo@rhel7 ~]$ mkdir aa [booboo@rhel7 ~]$ mkdir -p cc/bb [booboo@rhel7 ~]$ rmdir aa [booboo@rhel7 ~]$ ll total 4 -rwxrwxrwx. 1 booboo booboo 3 Jun 15 23:34 booboo drwxrwxr-x. 3 booboo booboo 15 Jun 16 00:08 cc [booboo@rhel7 ~]$ rmdir cc rmdir: failed to remove ‘cc’: Directory not empty [booboo@rhel7 ~]$ rm -rf cc [booboo@rhel7 ~]$ ll total 4 -rwxrwxrwx. 1 booboo booboo 3 Jun 15 23:34 booboo
cp
cp:copy 复制文件
cp 源文件 目的地(目录)
-p 保留文件原属性
-r 复制目录
cp实验
使用 root 用户,进入 tom 的家目录
[root@rhel7 ~]# cd /home/tom
保留原文件属性复制 testa_3 文件到 /tmp 目录下
[root@rhel7 tom]# cp -p testa_3 /tmp [root@rhel7 tom]# ll /tmp/testa_3 -rw-rw-r--. 1 tom tom 0 Mar 21 01:31 /tmp/testa_3 [root@rhel7 tom]# cp testa_4 /tmp [root@rhel7 tom]# ll /tmp/testa_4 -rw-r--r--. 1 root root 0 Mar 21 01:55 /tmp/testa_4
拷贝目录 a 到 /tmp 下,必须加上 -r ,因为 a 目录下还有 b/c 目录
[root@rhel7 tom]# cp a /tmp cp: omitting directory `a' [root@rhel7 tom]# cp -r a /tmp
mv
mv:move 移动 移动和重命名
mv 源文件 目的地(目录)
mv实验
[tom@rhel7 ~]$ mv testa_3 test [tom@rhel7 ~]$ ls a c f testa_4 testb_3 testc_2 ab cd d p testb_1 testb_4 testc_3 b e test testb_2 testc_1 testc_4 [tom@rhel7 ~]$ mv test??? f/ [tom@rhel7 ~]$ ll -R f f: total 0 -rw-rw-r--. 1 tom tom 0 Mar 21 01:47 file1 -rw-rw-r--. 1 tom tom 0 Mar 21 01:47 file2 -rw-rw-r--. 1 tom tom 0 Mar 21 01:47 file3 -rw-rw-r--. 1 tom tom 0 Mar 21 01:47 file4 -rw-rw-r--. 1 tom tom 0 Mar 21 01:31 testa_4 -rw-rw-r--. 1 tom tom 0 Mar 21 01:31 testb_1 -rw-rw-r--. 1 tom tom 0 Mar 21 01:31 testb_2 -rw-rw-r--. 1 tom tom 0 Mar 21 01:31 testb_3 -rw-rw-r--. 1 tom tom 0 Mar 21 01:31 testb_4 -rw-rw-r--. 1 tom tom 0 Mar 21 01:31 testc_1 -rw-rw-r--. 1 tom tom 0 Mar 21 01:31 testc_2 -rw-rw-r--. 1 tom tom 0 Mar 21 01:31 testc_3 -rw-rw-r--. 1 tom tom 0 Mar 21 01:31 testc_4
[booboo@rhel7 ~]$ vi num [booboo@rhel7 ~]$ cat num booboo 20 100 tom 21 100 tom 21 100 kevin 19 200 booboo 20 100 mark 20 200 [booboo@rhel7 ~]$ sort num booboo 20 100 booboo 20 100 kevin 19 200 mark 20 200 tom 21 100 tom 21 100 [booboo@rhel7 ~]$ sort -r num tom 21 100 tom 21 100 mark 20 200 kevin 19 200 booboo 20 100 booboo 20 100 [booboo@rhel7 ~]$ sort -u num booboo 20 100 kevin 19 200 mark 20 200 tom 21 100 [booboo@rhel7 ~]$ sort -n -k 2 -t " " num |sort -u booboo 20 100 kevin 19 200 mark 20 200 tom 21 100
uniq
[booboo@rhel7 ~]$ uniq num booboo 20 100 tom 21 100 kevin 19 200 booboo 20 100 mark 20 200
[booboo@rhel7 ~]$ type man man is /bin/man [booboo@rhel7 ~]$ type ls ls is aliased to `ls –color=auto' [booboo@rhel7 ~]$ which ls alias ls='ls --color=auto' /bin/ls [booboo@rhel7 ~]$ type touch touch is hashed (/bin/touch) [booboo@rhel7 ~]$ type echo echo is a shell builtin [booboo@rhel7 ~]$ type cat cat is hashed (/bin/cat)
内置命令一般显示为“is a shell builtin ”
除了内置命令外,其他命令都是通过某个安装包安装生成的可执行文件
接下来我们一起看看这些命令都是什么软件生成的
[booboo@rhel7 ~]$ rpm -qf /bin/man man-db-2.6.3-9.el7.x86_64 [booboo@rhel7 ~]$ rpm -qf /bin/ls coreutils-8.22-11.el7.x86_64 [booboo@rhel7 ~]$ rpm -qf /bin/touch coreutils-8.22-11.el7.x86_64 [booboo@rhel7 ~]$ rpm -qf /bin/cat coreutils-8.22-11.el7.x86_64 [booboo@rhel7 ~]$ type if if is a shell keyword
—help 参数
—help参数是大所数命令自带的选项,用于查看使用帮助。
[booboo@rhel7 ~]$ ls --help Usage: ls [OPTION]... [FILE]... List information about the FILEs (the current directory by default). Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.
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 C-style escapes for nongraphic characters --block-size=SIZE scale sizes by SIZE before printing them; e.g., '--block-size=M' prints sizes in units of 1,048,576 bytes; 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, newest first -C list entries by columns --color[=WHEN] colorize the output; WHEN can be 'never', 'auto', or 'always' (the default); more info below -d, --directory list directories themselves, not their contents -D, --dired generate output designed for Emacs' dired mode -f do not sort, enable -aU, disable -ls --color
[booboo@rhel7 ~]$ type cd cd is a shell builtin [booboo@rhel7 ~]$ help cd cd: cd [-L|[-P [-e]]] [dir] Change the shell working directory.
Change the current directory to DIR. The default DIR is the value of the HOME shell variable.
The variable CDPATH defines the search path for the directory containing DIR. Alternative directory names in CDPATH are separated by a colon (:). A null directory name is the same as the current directory. If DIR begins with a slash (/), then CDPATH is not used.
If the directory is not found, and the shell option `cdable_vars' is set, the word is assumed to be a variable name. If that variable has a value, its value is used for DIR.
Options: -L force symbolic links to be followed -P use the physical directory structure without following symbolic links -e if the -P option is supplied, and the current working directory cannot be determined successfully, exit with a non-zero status
The default is to follow symbolic links, as if `-L' were specified.
Exit Status: Returns 0 if the directory is changed, and if $PWD is set successfully when -P is used; non-zero otherwise. [booboo@rhel7 ~]$ type touch touch is hashed (/bin/touch) [booboo@rhel7 ~]$ type echo echo is a shell builtin [booboo@rhel7 ~]$ help echo echo: echo [-neE] [arg ...]
DESCRIPTION Echo 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
--version output version information and exit
If -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
\0NNN byte with octal value NNN (1 to 3 digits)
\xHH byte with hexadecimal value HH (1 to 2 digits)
NOTE: your shell may have its own version of echo, which usually supersedes the version described here. Please refer to your shell's documentation for details about the options it supports.
[booboo@rhel7 ~]$ tzselect Please identify a location so that time zone rules can be set correctly. Please select a continent or ocean. 1) Africa 2) Americas 3) Antarctica 4) Arctic Ocean 5) Asia 6) Atlantic Ocean 7) Australia 8) Europe 9) Indian Ocean 10) Pacific Ocean 11) none - I want to specify the time zone using the Posix TZ format. \#? 5 Please select a country. 1) Afghanistan 18) Israel 35) Palestine 2) Armenia 19) Japan 36) Philippines 3) Azerbaijan 20) Jordan 37) Qatar 4) Bahrain 21) Kazakhstan 38) Russia 5) Bangladesh 22) Korea (North) 39) Saudi Arabia 6) Bhutan 23) Korea (South) 40) Singapore 7) Brunei 24) Kuwait 41) Sri Lanka 8) Cambodia 25) Kyrgyzstan 42) Syria 9) China 26) Laos 43) Taiwan 10) Cyprus 27) Lebanon 44) Tajikistan 11) East Timor 28) Macau 45) Thailand 12) Georgia 29) Malaysia 46) Turkmenistan 13) Hong Kong 30) Mongolia 47) United Arab Emirates 14) India 31) Myanmar (Burma) 48) Uzbekistan 15) Indonesia 32) Nepal 49) Vietnam 16) Iran 33) Oman 50) Yemen 17) Iraq 34) Pakistan \#? 9 Please select one of the following time zone regions. 1) east China - Beijing, Guangdong, Shanghai, etc. 2) Heilongjiang (except Mohe), Jilin 3) central China - Sichuan, Yunnan, Guangxi, Shaanxi, Guizhou, etc. 4) most of Tibet & Xinjiang 5) west Tibet & Xinjiang \#? 1
The following information has been given:
China east China - Beijing, Guangdong, Shanghai, etc.
Therefore TZ='Asia/Shanghai' will be used. Local time is now: Thu Jun 16 15:08:57 CST 2016. Universal Time is now: Thu Jun 16 07:08:57 UTC 2016. Is the above information OK? 1) Yes 2) No \#? 1
You can make this change permanent for yourself by appending the line TZ='Asia/Shanghai'; export TZ to the file '.profile' in your home directory; then log out and log in again.
Here is that TZ value again, this time on standard output so that you can use the /bin/tzselect command in shell scripts: Asia/Shanghai
rhel7 版本
[kiosk@foundation0 Desktop]$ timedatectl Local time: Wed 2016-06-15 16:47:40 CST Universal time: Wed 2016-06-15 08:47:40 UTC RTC time: Wed 2016-06-15 16:47:40 Time zone: Asia/Shanghai (CST, +0800) NTP enabled: yes NTP synchronized: yes RTC in local TZ: yes DST active: n/a
关键词:
UTC 协调世界时 Coordinated Universal Time 又称世界统一时间,世界标准时间,国际协调时间。1972 年1 月1日,UTC(协调世界时)成为新的世界标准时间。 CST 时区缩写 CST可以为如下4个不同的时区的缩写: 美国中部时间:Central Standard Time (USA) UT-6:00 澳大利亚中部时间:Central Standard Time (Australia) UT+9:30 中国标准时间:China Standard Time UT+8:00 例如,UTC是0点,那么CST中国为早晨8点 古巴标准时间:Cuba Standard Time UT-4:00 RTC Time 硬件时钟时间 set-local-rtc 1 本地时区 set-local-rtc 0 UTC DST Daylight Saving Time日光节约时间、夏令时 是一种为节约能源而人为规定地方时间的制度,在这一制度实行期间所采用的统一时间称为“夏令时间”。 一般在天亮早的夏季人为将时间提前一小时,可以使人早起早睡,减少照明量,以充分利用光照资源,从而节约照明用电。 各个采纳夏时制的国家具体规定不同。目前全世界有近110个国家每年要实行夏令时。 1986年至1991年,中国在全国范围实行了六年夏令时,1992年4月5日后不再实行。
cal
cal命令用于显示当前日历,或者指定日期的日历。
cal [-smjy13] [[[day] month] year] -1 显示当月日历并将今日标黑 -3 显示上个月、当月、下个月。 -s 周日作为第一列 -m 周一作为第一列 -j 列出今天是一年的第几天 -y 列出今年所有的月 [root@rhel7 ~]# cal June 2016 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
[root@rhel7 ~]# cal -3 May 2016 June 2016 July 2016 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 7 1 2 3 4 1 2 8 9 10 11 12 13 14 5 6 7 8 9 10 11 3 4 5 6 7 8 9 15 16 17 18 19 20 21 12 13 14 15 16 17 18 10 11 12 13 14 15 16 22 23 24 25 26 27 28 19 20 21 22 23 24 25 17 18 19 20 21 22 23 29 30 31 26 27 28 29 30 24 25 26 27 28 29 30 31 [root@rhel7 ~]# cal -j June 2016 Sun Mon Tue Wed Thu Fri Sat 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182