1.1.命令行基础

1)查看cdmkdir是属于内部命令还是外部命令

[root@localhost ~]# type cd mkdir

cd is a shell builtin

mkdir is /bin/mkdir

//可以看到cd是内部命令,而mkdir是外部命令。

2)使用help查看cd的帮助信息

[root@localhost ~]# help cd

cd: cd [-L|-P] [dir]

Change the current directory to DIR. The variable $HOME is the

default DIR. The variable CDPATH defines the search pathfor

the directory containing DIR. Alternative directory names in CDPATH

are separated by a colon (:). A null directory name is the same as

...

3)使用help查看mkdir的帮助信息

[root@localhost ~]# mkdir --help

用法:mkdir [选项] 目录...

若目录不是已经存在则创建目录。


长选项必须用的参数在使用短选项时也是必须的。

-m, --mode=模式设定权限<模式> (类似 chmod),而不是 rwxrwxrwx umask

-p, --parents 需要时创建上层目录,如目录早已存在则不当作错误

-v, --verbose 每次创建新目录都显示信息

-Z, --context=CONTEXT (SELinux) set securitycontext to CONTEXT

--help 显示此帮助信息并退出

--version 输出版本信息并退出


请向<bug-coreutils@gnu.org> 报告错误。

4)使用man查看passwd命令的帮助信息

[root@localhost tmp]# whatis passwd

passwd (1) - update user's authentication tokens

passwd (5) - password file

passwd (rpm) - The passwd utility forsetting/changing passwords using PAM

passwd [sslpasswd] (1ssl) - compute password hashes



[root@localhost ~]# man passwd

Cannot open the messagecatalog "man" for locale "zh_CN.UTF-8"

(NLSPATH="<none>")


Formatting page, pleasewait...

PASSWD(1) User utilities PASSWD(1)


NAME

passwd - update user’s authenticationtokens


SYNOPSIS

passwd [-k] [-l] [-u [-f]] [-d] [-nmindays] [-x maxdays] [-w warndays]

[-i inactivedays] [-S] [--stdin][username]


DESCRIPTION

The passwd utility is used to updateuser’s authentication token(s).

...

5)使用man查看passwd文件的帮助信息

[root@localhost ~]# man 5 passwd

Cannot open the messagecatalog "man" for locale "zh_CN.UTF-8"

(NLSPATH="<none>")


Formatting page, pleasewait...

PASSWD(5) Linux Programmer’s Manual PASSWD(5)


NAME

passwd - password file


DESCRIPTION

Passwd is a text file, that contains alist of the system’s accounts,

...

6)lsman帮助信息重定向到/root/ls-man.txt中并过滤格式

[root@localhost ~]# man ls | col -b >/root/ls-man.txt

//验证

[root@localhost ~]# more /root/ls-man.txt

LS(1) User Commands LS(1)


NAME

ls - list directorycontents


SYNOPSIS

ls [OPTION]... [FILE]...


DESCRIPTION

List information about the FILEs (the currentdirectory by default).

...

1.2.目录和文件基本管理

1)显示现在什么位置

[root@localhost~]# pwd

/root

2)进入/etc/sysconfig/network-scripts

[root@localhost~]# cd /etc/sysconfig/network-scripts/

[root@localhostnetwork-scripts]#

3)长格式并提供易读的属性显示/boot下的vmlinuz开头的文件

[root@localhost~]# ls -l /boot/vmlinuz*

-rw-r--r--1 root root 2125660 2012-11-29 /boot/vmlinuz-2.6.18-348.el5

4)列出/etc目录属性

[root@localhost~]# ls -ld /etc

drwxr-xr-x90 root root 4096 10-20 20:55 /etc

5)递归显示/boot目录下的文件和内容

[root@localhost~]# ls -R /boot

/boot:

config-2.6.18-348.el5 lost+found vmlinuz-2.6.18-348.el5

grub symvers-2.6.18-348.el5.gz

initrd-2.6.18-348.el5.img System.map-2.6.18-348.el5


/boot/grub:

device.map grub.conf minix_stage1_5 stage2

e2fs_stage1_5 iso9660_stage1_5 reiserfs_stage1_5 ufs2_stage1_5

fat_stage1_5 jfs_stage1_5 splash.xpm.gz vstafs_stage1_5

ffs_stage1_5 menu.lst stage1 xfs_stage1_5


/boot/lost+found:

6)显示root下面所有文件包括隐藏文件

[root@localhost~]# ls -a /root

. .cshrc .gnome2 .metacity

.. Desktop .gnome2_private .nautilus

anaconda-ks.cfg .dmrc .gstreamer-0.10 .redhat

.bash_history .eggcups .gtkrc-1.2-gnome2 .scim

.bash_logout .esd_auth .ICEauthority .tcshrc

.bash_profile .gconf install.log .Trash

.bashrc .gconfd install.log.syslog .xsession-errors

.chewing .gnome ls-man.txt

7)进入/tmp目录,删除所有文件和目录,创建file1.txt file2.txt file3.txt file13.txt filea.txtfileab.txt

[root@localhost~]# cd /tmp //进入tmp目录

[root@localhosttmp]# rm -rf /tmp/* //删除子目录和文件

[root@localhosttmp]# ls //验证

[root@localhosttmp]# touch file1.txt file2.txt file3.txt file13.txtfilea.txt fileab.txt //建立文件

[root@localhosttmp]# ls //确认文件建立成功

file13.txt file1.txt file2.txt file3.txt fileab.txt filea.txt

8)显示file开头的,以.txt结尾的,中间2个字符的文件

[root@localhosttmp]# lsfile??.txt

file13.txt fileab.txt

9)显示file开头的,以.txt结尾的,中间是单个数字的文件

[root@localhosttmp]# ls file[0-9].txt

file1.txt file2.txt file3.txt

10)显示file开头的,以.txt结尾的,中间部分可能是1 3 a ab的文件

[root@localhosttmp]# lsfile{1,3,a,ab}.txt

file1.txt file3.txt fileab.txt filea.txt

11)定义alias别名,设置myls=ls –lhA

[root@localhost tmp]#alias myls="ls -lhA" //定义别名

//验证

[root@localhost tmp]#alias //查看别名

...

alias myls='ls -lhA'

...


12)查看/boot/etc/pki分别占用多大空间

[root@localhosttmp]# du -sh /boot /etc/pki/

6.5M /boot

792K /etc/pki/

13)创建/vod/movie/cartoon,递归显示/vod目录结构

[root@localhosttmp]# ls -R /vod

/vod:

movie


/vod/movie:

cartoon


/vod/movie/cartoon:

14)把/boot/grub /etc/host.conf拷贝到/root/Desktop下,在尾部添加标记的方式列出Desktop目录下的内容(ls -F

[root@localhosttmp]# cp -a /boot/grub /etc/host.conf /root/Desktop/

//验证

[root@localhosttmp]# ls -F /root/Desktop/

grub/ host.conf

15)删除Desktop下的grubhost.conf

[root@localhosttmp]# rm -rf /root/Desktop/grub /root/Desktop/host.conf

//验证

[root@localhosttmp]# ls /root/Desktop

[root@localhosttmp]#

16)把刚才生成的ls-man.txt移动到桌面

[root@localhosttmp]# mv /root/ls-man.txt /root/Desktop/

//验证

[root@localhosttmp]# ls /root/Desktop/

ls-man.txt

17)把ls-man.txt改名为manls.txt方案

[root@localhosttmp]# mv /root/Desktop/ls-man.txt/root/Desktop/manls.txt


//验证

[root@localhosttmp]# ls /root/Desktop/

manls.txt

1.3.程序和文件检索

1)PATH作用,查看PATH的值

作用:执行任何命令时,都会从PATH的值(即路径)中去搜寻是否有该命令,有则执行;无则告之,找不到此命令。

[root@localhosttmp]# echo $PATH

/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

2)查找shutdown这个命令的绝对路径

[root@localhosttmp]# whichshutdown

/sbin/shutdown

3)通过whereis搜索 rm

[root@localhosttmp]# whereis rm

rm: /bin/rm/usr/share/man/man1p/rm.1p.gz /usr/share/man/man1/rm.1.gz

4)创建myhttpd.conf文件,使用locate查找,是否能够查找到这个文件?

[root@localhost~]# touchmyhttpd.conf //创建

[root@localhost~]# ls //验证

anaconda-ks.cfg Desktop install.log myhttpd.conf

[root@localhost~]# locatemyhttpd.conf //查找

[root@localhost~]#

5)更新数据库/var/lib/mlocate/mlocate.db,使用locate查找,是否能够查找到这个文件?

[root@localhost~]# updated //更新

[root@localhost~]# locatemyhttpd.conf //查找

/root/myhttpd.conf

6)删除myhttpd.conf文件,使用locate查找,是否能够查找到这个文件?

[root@localhost ~]# rm -f myhttpd.conf //删除

[root@localhost~]# lsmyhttpd.conf //验证

ls: myhttpd.conf:没有那个文件或目录

[root@localhost~]# locatemyhttpd.conf //再次查找

/root/myhttpd.conf

7)查找/boot下的链接文件

[root@localhost~]# find /boot-type l

/boot/grub/menu.lst

8)查找/boot下的目录

[root@localhost~]# find /boot-type d

/boot

/boot/grub

/boot/lost+found

9)查找/etc下名字叫resol开头的,以.conf结尾的文件

[root@localhost ~]# find /etc-name resol*.conf

/etc/resolv.conf

10)查找/dev下的字符设备文件,并且名字叫tty1 tty2 tty3

[root@localhost~]# find /dev-name tty[1-3]

/dev/tty3

/dev/tty2

/dev/tty1

11)以易读的属性并长格式显示/boot下以.img结尾的文件

[root@localhost~]# find /boot-name *.img -exec ls -lh {} \;

-rw------- 1 rootroot 2.7M 10-13 22:24 /boot/initrd-2.6.18-348.el5.img

12)查找/boot下以.img结尾的并且大于2M的文件

[root@localhost~]# find /boot-name *.img -a -size +2048k

/boot/initrd-2.6.18-348.el5.img

13)查找系统上面24小时内变动过的文件

[root@localhost~]# find /-mtime 0

/

/lib

/lib/security/pam_krb5

/lib/udev

/bin

...

14)查找/var下大于等于5天前变动过的文件名

[root@localhost~]# find /var -mtime +4

/var

/var/lib

/var/lib/stateless

...

15)查找/var下小于等于4天内变动过的文件名

[root@localhost~]# find /var-mtime -4

/var/lib/rpm/__db.003

/var/lib/rpm/__db.002

/var/lib/rpm/__db.001

/var/lib/logrotate.status

...

16)查找/var下第4-5天那一天变动过的文件名

[root@localhost~]# find /var -mtime 4 | head

/var/lib/rpm

/var/lib/xkb

/var/lib/nfs/rpc_pipefs

...

17)查找/boot下大于2M的文件并把它长格式显示出来

[root@localhost~]# find /boot-size +2048k -exec ls -ls {} \;

2768 -rw------- 1root root 2820764 10-13 22:24 /boot/initrd-2.6.18-348.el5.img

2087 -rw-r--r-- 1root root 2125660 2012-11-29 /boot/vmlinuz-2.6.18-348.el5