1.linux上文件管理类命令都有哪些,其常用的使用方法极其示例演示。
(1).创建目录
格式:mkdir [选项] 目录
功能:创建目录
常用选项说明:
-m 创建目录的同时设置访问权限
-p 一次性创建多级目录
-v 显示过程
[root@CentOS6 rootfile]# mkdir -p test/file
[root@CentOS6 rootfile]# ls
test
[root@CentOS6 rootfile]# cd test
[root@CentOS6 test]# ls
file
[root@CentOS6 test]#
[root@CentOS6 tmp]# mkdir -m 700 -p /tmp/ppp.txt
[root@CentOS6 tmp]# ll -d ppp.txt
drwx——. 2 root root 4096 Aug 20 09:23 ppp.txt
[root@CentOS6 tmp]# mkdir -v 123
mkdir: created directory `123'
[root@CentOS6 tmp]# ll -d 123
drwxr-xr-x. 2 root root 4096 Aug 20 09:24 123
(2).删除目录
格式:rmdir [选项] 目录
功能:删除目录
常用选项说明:
-p 递归删除目录,当子目录删除后其父目录为空时,也一同删除
[root@CentOS6 tmp]# rmdir -p 123
(3).查看当前目录
格式:pwd
功能:pwd (print working directory),查看当前目录.
常用选项说明:
[root@CentOS6 tmp]# pwd
/tmp
(4).显示目录内容
格式:ls [选项] [文件目录]
功能:显示指定目录中的文件和了目录信息,当不指定目录时,显示当前目录下的文件和子目录信息
常用选项说明:
-a 显示所有文件和子目录,包括隐藏文件和主目录
-l 显示文件和子目录的详细信息,包括文件类型、权限、所有者和所属群组、文件大小、最后修改时间、文件名
-d 如果参数是目录,则只显示目录信息,而不显示其中所包含的文件信息
-t 按时间顺序显示
-r 反向逆序显示
-R 不仅显示指定目录下的文件和子目录信息,而且还递归地显示子目录下的文件和子目录信息
[root@CentOS6 ~]# ls -a
. .11.sh.swp 1.sh 6.sh anaconda-ks.cfg .bashrc .dbus .gconf .gtk-bookmarks install.log.syslog .nautilus .python_history .viminfo
.. 12.sh 2.sh 7.sh a.txt b.txt Desktop .gconfd .gvfs lihui1.txt Pictures .ssh .Xauthority
100 13.sh 3.sh 8.sh .bash_history .cache Documents .gnome2 .ICEauthority lihui.txt Public .tcshrc
10.sh 14.sh 4.sh 9.sh .bash_logout .config Downloads .gnote .imsettings.log .local .pulse Templates
11.sh 15.sh 5.sh .abrt .bash_profile .cshrc .esd_auth .gnupg install.log Music .pulse-cookie Videos
[root@CentOS6 ~]# ls -l
total 228
-rw-r–r–. 1 root root 0 Aug 18 21:31 100
-rw-r–r–. 1 root root 147 Aug 8 21:37 10.sh
-rw-r–r–. 1 root root 284 Aug 8 17:42 11.sh
-rw-r–r–. 1 root root 93 Aug 18 22:07 12.sh
-rw-r–r–. 1 root root 88 Aug 18 21:36 13.sh
-rw-r–r–. 1 root root 90 Aug 18 22:16 14.sh
-rw-r–r–. 1 root root 169 Aug 18 22:43 15.sh
-rw-r–r–. 1 root root 275 Aug 8 12:53 1.sh
-rw-r–r–. 1 root root 141 Aug 8 13:07 2.sh
-rw-r–r–. 1 root root 61 Aug 8 13:13 3.sh
-rwxr-xr-x. 1 root root 135 Aug 8 13:46 4.sh
-rwxr-xr-x. 1 root root 35 Aug 8 14:30 5.sh
-rw-r–r–. 1 root root 51 Aug 8 14:36 6.sh
-rw-r–r–. 1 root root 90 Aug 8 14:41 7.sh
-rw-r–r–. 1 root root 259 Aug 8 17:08 8.sh
-rw-r–r–. 1 root root 154 Aug 8 17:16 9.sh
-rw——-. 1 root root 1510 Aug 3 15:44 anaconda-ks.cfg
-rw-r–r–. 1 root root 0 Aug 18 21:02 a.txt
-rw-r–r–. 1 root root 16 Aug 18 21:05 b.txt
drwxr-xr-x. 2 root root 4096 Aug 3 15:47 Desktop
drwxr-xr-x. 2 root root 4096 Aug 3 15:47 Documents
drwxr-xr-x. 2 root root 4096 Aug 3 15:47 Downloads
-rw-r–r–. 2 root root 50606 Aug 3 15:44 install.log
-rw-r–r–. 1 root root 10225 Aug 3 15:42 install.log.syslog
-rw-r–r–. 2 root root 50606 Aug 3 15:44 lihui1.txt
-rw-r–r–. 1 root root 3 Aug 8 10:58 lihui.txt
drwxr-xr-x. 2 root root 4096 Aug 3 15:47 Music
drwxr-xr-x. 2 root root 4096 Aug 3 15:47 Pictures
drwxr-xr-x. 2 root root 4096 Aug 3 15:47 Public
drwxr-xr-x. 2 root root 4096 Aug 3 15:47 Templates
drwxr-xr-x. 2 root root 4096 Aug 3 15:47 Videos
[root@CentOS6 ~]# ls -d Desktop
Desktop
[root@CentOS6 ~]# ls -lt
total 228
-rw-r–r–. 1 root root 169 Aug 18 22:43 15.sh
-rw-r–r–. 1 root root 90 Aug 18 22:16 14.sh
-rw-r–r–. 1 root root 93 Aug 18 22:07 12.sh
-rw-r–r–. 1 root root 88 Aug 18 21:36 13.sh
-rw-r–r–. 1 root root 0 Aug 18 21:31 100
-rw-r–r–. 1 root root 16 Aug 18 21:05 b.txt
-rw-r–r–. 1 root root 0 Aug 18 21:02 a.txt
-rw-r–r–. 1 root root 147 Aug 8 21:37 10.sh
-rw-r–r–. 1 root root 284 Aug 8 17:42 11.sh
-rw-r–r–. 1 root root 154 Aug 8 17:16 9.sh
-rw-r–r–. 1 root root 259 Aug 8 17:08 8.sh
-rw-r–r–. 1 root root 90 Aug 8 14:41 7.sh
-rw-r–r–. 1 root root 51 Aug 8 14:36 6.sh
-rwxr-xr-x. 1 root root 35 Aug 8 14:30 5.sh
-rwxr-xr-x. 1 root root 135 Aug 8 13:46 4.sh
-rw-r–r–. 1 root root 61 Aug 8 13:13 3.sh
-rw-r–r–. 1 root root 141 Aug 8 13:07 2.sh
-rw-r–r–. 1 root root 275 Aug 8 12:53 1.sh
-rw-r–r–. 1 root root 3 Aug 8 10:58 lihui.txt
drwxr-xr-x. 2 root root 4096 Aug 3 15:47 Desktop
drwxr-xr-x. 2 root root 4096 Aug 3 15:47 Documents
drwxr-xr-x. 2 root root 4096 Aug 3 15:47 Downloads
drwxr-xr-x. 2 root root 4096 Aug 3 15:47 Music
drwxr-xr-x. 2 root root 4096 Aug 3 15:47 Pictures
drwxr-xr-x. 2 root root 4096 Aug 3 15:47 Public
drwxr-xr-x. 2 root root 4096 Aug 3 15:47 Templates
drwxr-xr-x. 2 root root 4096 Aug 3 15:47 Videos
-rw——-. 1 root root 1510 Aug 3 15:44 anaconda-ks.cfg
-rw-r–r–. 2 root root 50606 Aug 3 15:44 install.log
-rw-r–r–. 2 root root 50606 Aug 3 15:44 lihui1.txt
-rw-r–r–. 1 root root 10225 Aug 3 15:42 install.log.syslog
[root@CentOS6 ~]# ll -rt
total 228
-rw-r–r–. 1 root root 10225 Aug 3 15:42 install.log.syslog
-rw-r–r–. 2 root root 50606 Aug 3 15:44 lihui1.txt
-rw-r–r–. 2 root root 50606 Aug 3 15:44 install.log
-rw——-. 1 root root 1510 Aug 3 15:44 anaconda-ks.cfg
drwxr-xr-x. 2 root root 4096 Aug 3 15:47 Videos
drwxr-xr-x. 2 root root 4096 Aug 3 15:47 Templates
drwxr-xr-x. 2 root root 4096 Aug 3 15:47 Public
drwxr-xr-x. 2 root root 4096 Aug 3 15:47 Pictures
drwxr-xr-x. 2 root root 4096 Aug 3 15:47 Music
drwxr-xr-x. 2 root root 4096 Aug 3 15:47 Downloads
drwxr-xr-x. 2 root root 4096 Aug 3 15:47 Documents
drwxr-xr-x. 2 root root 4096 Aug 3 15:47 Desktop
-rw-r–r–. 1 root root 3 Aug 8 10:58 lihui.txt
-rw-r–r–. 1 root root 275 Aug 8 12:53 1.sh
-rw-r–r–. 1 root root 141 Aug 8 13:07 2.sh
-rw-r–r–. 1 root root 61 Aug 8 13:13 3.sh
-rwxr-xr-x. 1 root root 135 Aug 8 13:46 4.sh
-rwxr-xr-x. 1 root root 35 Aug 8 14:30 5.sh
-rw-r–r–. 1 root root 51 Aug 8 14:36 6.sh
-rw-r–r–. 1 root root 90 Aug 8 14:41 7.sh
-rw-r–r–. 1 root root 259 Aug 8 17:08 8.sh
-rw-r–r–. 1 root root 154 Aug 8 17:16 9.sh
-rw-r–r–. 1 root root 284 Aug 8 17:42 11.sh
-rw-r–r–. 1 root root 147 Aug 8 21:37 10.sh
-rw-r–r–. 1 root root 0 Aug 18 21:02 a.txt
-rw-r–r–. 1 root root 16 Aug 18 21:05 b.txt
-rw-r–r–. 1 root root 0 Aug 18 21:31 100
-rw-r–r–. 1 root root 88 Aug 18 21:36 13.sh
-rw-r–r–. 1 root root 93 Aug 18 22:07 12.sh
-rw-r–r–. 1 root root 90 Aug 18 22:16 14.sh
-rw-r–r–. 1 root root 169 Aug 18 22:43 15.sh
[root@CentOS6 ~]# ls -R
.:
100 11.sh 13.sh 15.sh 2.sh 4.sh 6.sh 8.sh anaconda-ks.cfg b.txt Documents install.log lihui1.txt Music Public Videos
10.sh 12.sh 14.sh 1.sh 3.sh 5.sh 7.sh 9.sh a.txt Desktop Downloads install.log.syslog lihui.txt Pictures Templates
./Desktop:
./Documents:
./Downloads:
./Music:
./Pictures:
./Public:
./Templates:
./Videos:
(5).创建文件,改变时间戳
格式:touch filename
功能:创建文件
常用选项说明:
-c: 指定的文件路径不存在时不予创建;
-a: 仅修改access time;
-m:仅修改modify time;
-t: STAMP [[CC]YY]MMDDhhmm[.ss]
[root@CentOS6 ~]# touch -c a.txt
[root@CentOS6 ~]# ll a.txt
-rw-r–r–. 1 root root 0 Aug 20 09:42 a.txt
[root@CentOS6 ~]# stat a.txt
File: `a.txt'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 802h/2050d Inode: 285190 Links: 1
Access: (0644/-rw-r–r–) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2016-08-20 09:42:31.634992244 +0800
Modify: 2016-08-20 09:42:31.634992244 +0800
Change: 2016-08-20 09:42:31.634992244 +0800
[root@CentOS6 ~]# touch -a a.txt
[root@CentOS6 ~]# stat a.txt
File: `a.txt'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 802h/2050d Inode: 285190 Links: 1
Access: (0644/-rw-r–r–) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2016-08-20 09:45:34.653983109 +0800
Modify: 2016-08-20 09:42:31.634992244 +0800
Change: 2016-08-20 09:45:34.653983109 +0800
[root@CentOS6 ~]# touch -m a.txt
[root@CentOS6 ~]# stat a.txt
File: `a.txt'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 802h/2050d Inode: 285190 Links: 1
Access: (0644/-rw-r–r–) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2016-08-20 09:45:34.653983109 +0800
Modify: 2016-08-20 09:45:58.980999270 +0800
Change: 2016-08-20 09:45:58.980999270 +0800
[root@CentOS6 ~]# touch -t 200808080808 a.txt
[root@CentOS6 ~]# stat a.txt
File: `a.txt'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 802h/2050d Inode: 285190 Links: 1
Access: (0644/-rw-r–r–) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2008-08-08 08:08:00.000000000 +0800
Modify: 2008-08-08 08:08:00.000000000 +0800
Change: 2016-08-20 09:47:31.415978403 +0800
(6).cat命令
格式:cat [选项] filename
功能:依次读取filename中的内容
-n:给显示的文本行编号;
-E:显示行结束符$;
[root@CentOS6 ~]# cat /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
games:x:12:100:games:/usr/games:/sbin/nologin
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/cache/rpcbind:/sbin/nologin
rtkit:x:499:499:RealtimeKit:/proc:/sbin/nologin
avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin
vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
haldaemon:x:68:68:HAL daemon:/:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
apache:x:48:48:Apache:/var/www:/sbin/nologin
saslauth:x:498:76:Saslauthd user:/var/empty/saslauth:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
pulse:x:497:496:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
lihui:x:500:500::/home/lihui:/bin/bash
archlinux:x:501:501::/users/archlinux:/bin/bash
[root@CentOS6 ~]# cat -n /etc/passwd
1 root:x:0:0:root:/root:/bin/bash
2 bin:x:1:1:bin:/bin:/sbin/nologin
3 daemon:x:2:2:daemon:/sbin:/sbin/nologin
4 adm:x:3:4:adm:/var/adm:/sbin/nologin
5 lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
6 sync:x:5:0:sync:/sbin:/bin/sync
7 shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
8 halt:x:7:0:halt:/sbin:/sbin/halt
9 mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
10 uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
11 operator:x:11:0:operator:/root:/sbin/nologin
12 games:x:12:100:games:/usr/games:/sbin/nologin
13 gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
14 ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
15 nobody:x:99:99:Nobody:/:/sbin/nologin
16 dbus:x:81:81:System message bus:/:/sbin/nologin
17 usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin
18 rpc:x:32:32:Rpcbind Daemon:/var/cache/rpcbind:/sbin/nologin
19 rtkit:x:499:499:RealtimeKit:/proc:/sbin/nologin
20 avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin
21 vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
22 abrt:x:173:173::/etc/abrt:/sbin/nologin
23 rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
24 nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
25 haldaemon:x:68:68:HAL daemon:/:/sbin/nologin
26 ntp:x:38:38::/etc/ntp:/sbin/nologin
27 apache:x:48:48:Apache:/var/www:/sbin/nologin
28 saslauth:x:498:76:Saslauthd user:/var/empty/saslauth:/sbin/nologin
29 postfix:x:89:89::/var/spool/postfix:/sbin/nologin
30 gdm:x:42:42::/var/lib/gdm:/sbin/nologin
31 pulse:x:497:496:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
32 sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
33 tcpdump:x:72:72::/:/sbin/nologin
34 lihui:x:500:500::/home/lihui:/bin/bash
35 archlinux:x:501:501::/users/archlinux:/bin/bash
[root@CentOS6 ~]# cat -nE /etc/passwd
1 root:x:0:0:root:/root:/bin/bash$
2 bin:x:1:1:bin:/bin:/sbin/nologin$
3 daemon:x:2:2:daemon:/sbin:/sbin/nologin$
4 adm:x:3:4:adm:/var/adm:/sbin/nologin$
5 lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin$
6 sync:x:5:0:sync:/sbin:/bin/sync$
7 shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown$
8 halt:x:7:0:halt:/sbin:/sbin/halt$
9 mail:x:8:12:mail:/var/spool/mail:/sbin/nologin$
10 uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin$
11 operator:x:11:0:operator:/root:/sbin/nologin$
12 games:x:12:100:games:/usr/games:/sbin/nologin$
13 gopher:x:13:30:gopher:/var/gopher:/sbin/nologin$
14 ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin$
15 nobody:x:99:99:Nobody:/:/sbin/nologin$
16 dbus:x:81:81:System message bus:/:/sbin/nologin$
17 usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin$
18 rpc:x:32:32:Rpcbind Daemon:/var/cache/rpcbind:/sbin/nologin$
19 rtkit:x:499:499:RealtimeKit:/proc:/sbin/nologin$
20 avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin$
21 vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin$
22 abrt:x:173:173::/etc/abrt:/sbin/nologin$
23 rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin$
24 nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin$
25 haldaemon:x:68:68:HAL daemon:/:/sbin/nologin$
26 ntp:x:38:38::/etc/ntp:/sbin/nologin$
27 apache:x:48:48:Apache:/var/www:/sbin/nologin$
28 saslauth:x:498:76:Saslauthd user:/var/empty/saslauth:/sbin/nologin$
29 postfix:x:89:89::/var/spool/postfix:/sbin/nologin$
30 gdm:x:42:42::/var/lib/gdm:/sbin/nologin$
31 pulse:x:497:496:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin$
32 sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin$
33 tcpdump:x:72:72::/:/sbin/nologin$
34 lihui:x:500:500::/home/lihui:/bin/bash$
35 archlinux:x:501:501::/users/archlinux:/bin/bash$
(7).more命令
格式:more [选项] filename
功能:依次读取filename中的内容,该命令与cat的不同是可以逐屏往下翻页显示,按q退出。
常用选项说明:
-p 显示下一屏之前先清屏
-s 文件中连续的空白行压缩成一个空白行显示
[root@CentOS6 ~]# more /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
games:x:12:100:games:/usr/games:/sbin/nologin
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/cache/rpcbind:/sbin/nologin
rtkit:x:499:499:RealtimeKit:/proc:/sbin/nologin
avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin
vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
haldaemon:x:68:68:HAL daemon:/:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
apache:x:48:48:Apache:/var/www:/sbin/nologin
saslauth:x:498:76:Saslauthd user:/var/empty/saslauth:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
pulse:x:497:496:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
lihui:x:500:500::/home/lihui:/bin/bash
archlinux:x:501:501::/users/archlinux:/bin/bash
[root@CentOS6 ~]# more -p /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
games:x:12:100:games:/usr/games:/sbin/nologin
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/cache/rpcbind:/sbin/nologin
rtkit:x:499:499:RealtimeKit:/proc:/sbin/nologin
avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin
vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
haldaemon:x:68:68:HAL daemon:/:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
apache:x:48:48:Apache:/var/www:/sbin/nologin
saslauth:x:498:76:Saslauthd user:/var/empty/saslauth:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
pulse:x:497:496:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
lihui:x:500:500::/home/lihui:/bin/bash
archlinux:x:501:501::/users/archlinux:/bin/bash
[root@CentOS6 ~]# more /root/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
(8).less命令
格式:less [选项] filename
功能:依次读取filename中的内容,该命令与more的不同是不仅可以向下翻页,还可以向上翻页,使用上下键、Enter、空格、pageDown、pageUp可以实现前后翻页,按q退出。
[root@CentOS6 ~]# less /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
games:x:12:100:games:/usr/games:/sbin/nologin
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/cache/rpcbind:/sbin/nologin
rtkit:x:499:499:RealtimeKit:/proc:/sbin/nologin
avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin
vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
haldaemon:x:68:68:HAL daemon:/:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
apache:x:48:48:Apache:/var/www:/sbin/nologin
saslauth:x:498:76:Saslauthd user:/var/empty/saslauth:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
pulse:x:497:496:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
lihui:x:500:500::/home/lihui:/bin/bash
archlinux:x:501:501::/users/archlinux:/bin/bash
(END)
(9).head命令
格式:head [选项] filename
功能:显示文件的头几行
常用选项说明:
-n 显示文件的前n行,如果没有n值,默认为10行
[root@CentOS6 ~]# head -n 10 /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
(10).tail命令
格式:tail [选项] filename
功能:显示文件的末尾几行
常用选项说明:
+n 从第n行开始显示
-n 显示文件的最后n行,如果没有n值,默认为最后10行
[root@CentOS6 ~]# tail -n +20 /etc/passwd
avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin
vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
haldaemon:x:68:68:HAL daemon:/:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
apache:x:48:48:Apache:/var/www:/sbin/nologin
saslauth:x:498:76:Saslauthd user:/var/empty/saslauth:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
pulse:x:497:496:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
lihui:x:500:500::/home/lihui:/bin/bash
archlinux:x:501:501::/users/archlinux:/bin/bash
[root@CentOS6 ~]# tail -n 20 /etc/passwd
dbus:x:81:81:System message bus:/:/sbin/nologin
usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/cache/rpcbind:/sbin/nologin
rtkit:x:499:499:RealtimeKit:/proc:/sbin/nologin
avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin
vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
haldaemon:x:68:68:HAL daemon:/:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
apache:x:48:48:Apache:/var/www:/sbin/nologin
saslauth:x:498:76:Saslauthd user:/var/empty/saslauth:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
pulse:x:497:496:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
lihui:x:500:500::/home/lihui:/bin/bash
archlinux:x:501:501::/users/archlinux:/bin/bash
(11).格式:find [选项] filename
功能:从指定的目录开始,递归地搜索其子目录,查找满足条件的文件并对之采取相关的操作
常用选项说明:
-name ‘字串’ 要查找的文件名,可以用通配符*、?、[]
-group ‘字串’ 文件所属的用户组名
-user 文件所属的用户名
find命令提供的查询条件可以是一个用逻辑符and、or、not组成的复合条件
-a 逻辑与
-o 逻辑或
-! 逻辑非
[root@CentOS6 /]# find -name passwd
./etc/passwd
./etc/pam.d/passwd
./usr/bin/passwd
./selinux/class/passwd
./selinux/class/passwd/perms/passwd
[root@CentOS6 /]# find -group root
[root@CentOS6 /]# find -user root
[root@CentOS6 /]# find -user root -a -group root
[root@CentOS6 /]# find -user root -o -group root
[root@CentOS6 /]# find -user root -! -group root
(12).格式:wc [选项] filename
功能:统计文件的字节数、字数、行数
常用选项说明:
-c 统计字节数
-l 统计行数
-w 统计字数
[root@CentOS6 /]# ls /etc | wc -l
253
[root@CentOS6 /]# ls /etc | wc -c
2378
[root@CentOS6 /]# ls /etc/passwd | wc -w
1
(13).cp 命令
格式:cp [选项] 源目录或文件 目标目录或文件
功能:将给出的文件或目录复制到另一个文件或目录中
常用选项说明:
-i:交互式复制,即覆盖之前提醒用户确认;
-f:强制覆盖目标文件;
-r, -R:递归复制目录;
-d:复制符号链接文件本身,而非其指向的源文件;
-a:-dR –preserve=all, archive,用于实现归档;
–preserv=
mode:权限
ownership:属主和属组
timestamps: 时间戳
context:安全标签
xattr:扩展属性
links:符号链接
all:上述所有属性
[root@CentOS6 tmp]# cp -f lihui.txt lihui.sh
cp: overwrite `lihui.sh'? y
[root@CentOS6 tmp]# cp -i lihui.txt lihui.sh
cp: overwrite `lihui.sh'? y
[root@CentOS6 tmp]# cp -r tmp lihui
[root@CentOS6 tmp]# ll -d lihui
drwxr-xr-x. 3 root root 4096 Aug 20 12:04 lihui
[root@CentOS6 etc]# cp -d rc /tmp/lihui_l.txt
[root@CentOS6 etc]# ll /tmp/lihui_l.txt
lrwxrwxrwx. 1 root root 7 Aug 20 12:06 /tmp/lihui_l.txt -> rc.d/rc
[root@CentOS6 etc]# cp -a yum.conf /tmp/yum.arch
[root@CentOS6 etc]# ll /tmp/yum.arch
-rw-r–r–. 1 root root 969 May 12 04:37 /tmp/yum.arch
[root@CentOS6 tmp]# cp -p lihui.txt lihui1.txt
(14).mv命令
格式:mv [选项] 源目录或文件 目标目录或文件
功能:移动或重命名文件或目录
常用选项说明:
-b 若存在同名文件,则覆盖前备份原来的文件
-f 强制覆盖同名文件
[root@CentOS6 tmp]# mv -b lihui.txt lihui1.txt
mv: overwrite `lihui1.txt'? y
[root@CentOS6 tmp]# ll lihui1.txt
-rw-r–r–. 1 root root 3 Aug 14 09:54 lihui1.txt
[root@CentOS6 tmp]# ll lihui*
-rw-r–r–. 1 root root 108 Aug 16 20:39 lihui1.sh
-rw-r–r–. 1 root root 3 Aug 14 09:54 lihui1.txt
-rw-r–r–. 1 root root 3 Aug 14 09:54 lihui1.txt~
-rw——-. 1 root root 7891 Aug 14 09:55 lihui2.txt
-rw-r–r–. 1 root root 119 Aug 16 20:54 lihui3.sh
[root@CentOS6 tmp]# mv -f lihui1.txt lihui2.txt
(15).rm 命令
格式:rm [选项] 文件夹或目录
功能:删除文件夹或目录
常用选项说明:
-f 强制删除文件,不出现确认提示
-r或R 按递归方式删除目录,默认只删除文件
[root@CentOS6 tmp]# rm -f lihui1.txt
[root@CentOS6 tmp]# rm -r lihui
rm: descend into directory `lihui'? y
rm: remove directory `lihui/keyring-bWhZez'? y
rm: remove directory `lihui'? y
(16).whereis命令
功能:查看文件坐在路径
[root@CentOS6 tmp]# whereis man
man: /usr/bin/man /etc/man.config /usr/share/man /usr/share/man/man1p/man.1p.gz /usr/share/man/man7/man.7.gz /usr/share/man/man1/man.1.gz
(17).stat命令
功能:查看文件详细信息
[root@CentOS6 tmp]# stat lihui.sh
File: `lihui.sh'
Size: 3 Blocks: 8 IO Block: 4096 regular file
Device: 802h/2050d Inode: 154300 Links: 1
Access: (0644/-rw-r–r–) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2016-08-16 20:38:09.107996888 +0800
Modify: 2016-08-20 12:02:27.865981006 +0800
Change: 2016-08-20 12:02:27.865981006 +0800
(18).file命令
功能:查看文件类型
[root@CentOS6 tmp]# file lihui.sh
lihui.sh: ASCII text
(19).chmod命令
功能:改变权限
u:属主
g:属组
o:其它
a: 所有
[root@CentOS6 tmp]# chmod +x lihui.sh
[root@CentOS6 tmp]# ll lihui.sh
-rwxr-xr-x. 1 root root 3 Aug 20 12:02 lihui.sh
[root@CentOS6 tmp]# chmod a-x lihui.sh
[root@CentOS6 tmp]# ll lihui.sh
-rw-r–r–. 1 root root 3 Aug 20 12:02 lihui.sh
(20).chown命令
功能:改变属主,属组
常用参数:
-R 递归修改
[root@CentOS6 tmp]# chown -R bin:bin tmp
2.bash的工作特性和执行状态返回值和命令展开所设计的内容极其事例演示。
bash的基础特性之一:
命令历史:shell进程会其会话中保存此前用户提交执行过的命令;
~]# history
定制history的功能,可通过环境变量实现:
HISTSIZE:shell进程可保留的命令历史的条数;
HISTFILE:持久保存命令历史的文件;
.bash_history
HISTFILESIZE:命令历史文件的大小;
命令用法:
history [-c] [-d 偏移量] [n]
或 history -anrw [文件名]
或 history -ps 参数 [参数…]
-c: 清空命令历史;
-d offset:删除指定命令历史
-r: 从文件读取命令历史至历史列表中;
-w:把历史列表中的命令追加至历史文件中;
history #:显示最近的#条命令;
调用命令历史列表中的命令:
!#:再一次执行历史列表中的第#条命令;
!!:再一次执行上一条命令;
!STRING:再一次执行命令历史列表中最近一个以STRING开头的命令;
注意:命令的重复执行有时候需要依赖于幂等性;
调用上一条命令的最后一个参数:
快捷键:ESC, .
字符串:!$
控制命令历史记录的方式:
环境变量:HISTCONTROL
ignoredups:忽略重复的命令;
ignorespace:忽略以空白字符开头的命令;
ignoreboth:以上两者同时生效;
修改变量的值:
NAME='VALUE'
bash的基础特性之二:命令行展开
~:自动展开为用户的家目录,或指定的用户的家目录;
{}:可承载一个以逗号分隔的路径列表,并能够将其展开为多个路径;
例如:/tmp/{a,b} 相当于 /tmp/a /tmp/b
bash的基础特性之三:命令的执行状态结果
命令执行的状态结果:
bash通过状态返回值来输出此结果:
成功:0
[root@CentOS6 tmp]# echo $?
0
失败:1-255
[root@CentOS6 tmp]# echo $?
1
命令执行完成之后,其状态返回值保存于bash的特殊变量$?中;
命令正常执行时,有的还回有命令返回值:
根据命令及其功能不同,结果各不相同;
引用命令的执行结果:
$(COMMAND)
或`COMMAND`
bash的基于特性:引用
强引用:''
弱引用:""
命令引用:“
bash基础特性:快捷键
Ctrl+a:跳转至命令行行首
Ctrl+e:跳转至命令行行尾
Ctrl+u:删除行首至光标所在处之间的所有字符;
Ctrl+k:删除光标所在处至行尾的所有字符;
Ctrl+l:清屏,相当于clear
[root@CentOS6 tmp]# history 10
[root@CentOS6 tmp]# !99
[root@CentOS6 tmp]# !!
[root@CentOS6 tmp]# !rpm
[root@CentOS6 tmp]# history | more
[root@CentOS6 tmp]# history -c
[root@CentOS6 tmp]# history -d 10
[root@CentOS6 tmp]# history -r lihui3.txt
[root@CentOS6 tmp]# echo $HISTSIZE
1000
[root@CentOS6 tmp]# echo $HISTFILESIZE
1000
可以修改这个值在.bash_profile文件,来达到整个bash和子bash都能生效
3.请使用命令展开功能来完成以下练习:
(1).创建/tmp目录下的:a_c,a_d,b_c,b_d
[root@CentOS6 tmp]# mkdir a_c a_d b_c b_d
(2).创建目录
[root@CentOS6 tmp]# mkdir -p /tmp/mylinux/{bin,boot/grub,dev,etc/{rc.d/init.d,sysconfig/network-scripts},lib/modules,lib64,proc,sbin,sys,tmp,usr/local/{bin,sbin},var/{lock,log,run}}
4.文件的元数据有哪些,分别表示什么,如何查看,如何修改时间戳。
[root@CentOS6 tmp]# stat lihui.tar.xz
File: `lihui.tar.xz'
Size: 61640 Blocks: 128 IO Block: 4096 regular file
Device: 802h/2050d Inode: 141364 Links: 1
Access: (0644/-rw-r–r–) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2016-08-13 11:35:56.430007319 +0800
Modify: 2016-08-13 11:35:44.291000003 +0800
Change: 2016-08-13 11:35:44.291000003 +0800
元数据有文件名,大小,块大小,文件类型,设备好,Inode号,连接数,访问权限,属主,属组,访问时间,修改时间,改变时间
修改属主:属组可以用chown,前面有使用说明
权限:chmod修改
链接:可以用link修改
访问时间,改变时间可以用touch修改
修改时间会随着修改时间变化
5.如何定义命令别名,如何查看,如何在命令中引用另一个命令的执行结果?
[root@CentOS6 tmp]# alias
alias cp='cp -i'
alias l.='ls -d .* –color=auto'
alias ll='ls -l –color=auto'
alias ls='ls –color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which –tty-only –read-alias –show-dot –show-tilde'
定义别名:
[root@CentOS6 tmp]# alias cls='clear'
可以定义在.bash_profile,永久生效
引用结果可以用“
[root@CentOS6 /]# echo `pwd`
/
[root@CentOS6 /]# echo $(pwd)
/
6.显示/var目录下所有已l开头,以一个小写字母结尾,且中间至少一位数字(可以有其他字符)的目录或文件。
[root@CentOS6 var]#ll -d l*[0-9]*[a-z]
7.显示/etc目录下,以任意一个数字开头,且以非数字结尾的文件或目录。
[root@CentOS6 etc]# ll -d [0-9]*[^0-9]
8.显示/etc目录下,以非字母开头,后面跟了一个字母以及其它任意长度任意字符的文件或目录。
[root@CentOS6 etc]# ll -d [^a-z][a-z]*
9.在/tmp目录下创建以tfile开头,后跟当前日期和时间的文件,文件名形如:tfile-2016-05-27-09-32-22
[root@CentOS6 tmp]# touch tfile-`date +%F-%H-%m-%S`
10.复制/etc目录下所有以p开头,以非数字结尾的文件或目录到/tmp/mytest1目录中。
[root@CentOS6 tmp]# cp -r /etc/p*[^0-9] /tmp/mytest1
11.复制/etc目录下所有以.d结尾的文件或目录至/tmp/mytest2目录中
[root@CentOS6 etc]# cp -r *.d /tmp/mytest2
12.复制/etc/目录下所有以l或m或n开头,以.conf结尾的文件至/tmp/mytest3目录中
[root@CentOS6 etc]# cp [mnl]*.conf /tmp/mytest3
原创文章,作者:lihuisjsq,如若转载,请注明出处:http://www.178linux.com/38493
评论列表(1条)
写的很好,排版还可以在漂亮一点,加油,题目不全吧,创建目录的没写吧