GNU bash --Linux 默认的 shell
一、bash shell提示符:
===================
[root@station230 ~]# date
2012年 10月 24日 星期三 09:38:54 CST
[root@station230 ~]# whoami
root
[root@station230 ~]# useradd jack
[root@station230 ~]# passwd jack
Changing password for user jack.
New UNIX password:
BAD PASSWORD: it is WAY too short
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@station230 ~]#
二、语法
=====================
命令 选项 参数
[root@station230 ~]# date
[root@station230 ~]# date -s 12:30
命令:整条shell命令的主体
选项:会影响会微调命令的行为 //通常以 -, --, +
参数: 命令作用的对象
ls 查看一个目录下有什么文件,或者某一个文件是否存在
-a all,查看目录下的所有文件,包括隐藏文件
-l 给出文件的长列表
-h human 人性化方式显示出来
-d 只列出目录名,不列出其他内容
-v 显示详细过程
[root@station230 ~]# ls -l install.log rhel5.repo
-rw-r--r-- 1 root root 34793 10-23 13:49 install.log
-rw-r--r-- 1 root root 147 10-23 15:44 rhel5.repo
[root@station230 ~]# ls -l /home
总计 4
drwx------ 3 jack jack 4096 10-24 09:48 jack
[root@station230 ~]#
[root@station230 ~]# ls -ld /home
drwxr-xr-x 3 root root 4096 10-24 09:42 /home
==================================================================
小知识:
***文件时间
ls -l 文件名 仅看的是文件的修改时间
Linux文件有三种时间:stat
例如:stat profile.d/
访问时间:atime,查看 内容
修改时间:mtime,修改 内容
改变时间:ctime,文件 属性,比如权限
[root@station230 ~]# ls -l install.log
-rw-r--r-- 1 root root 34793 10-23 13:49 install.log
[root@station230 ~]#
[root@station230 ~]# stat install.log
File: “install.log”
Size: 34793 Blocks: 80 IO Block: 4096 一般文件
Device: 802h/2050d Inode: 65282 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2012-10-23 16:53:20.000000000 +0800
Modify: 2012-10-23 13:49:46.000000000 +0800
Change: 2012-10-23 13:49:52.000000000 +0800
***文件类型:
通过颜色判断文件的类型是完全错误的!!!
Linux文件是没有扩展名!!!
方法一:
ls -l 文件名 //看第一个字符
- 普通文件(文本文件,二进制,电影,图片。。。)
d 目录文件(蓝色)
b 设备文件(块设备)存储设备硬盘,U盘
c 设备文件(字符设备)打印机,终端
s 套接字文件
p 管道文件
l 链接文件(淡蓝色)
方法二:file
file /bin/ls
file /home
file /dev/sda
[root@station230 ~]# file /etc/grub.conf
/etc/grub.conf: symbolic link to `../boot/grub/grub.conf'
[root@station230 ~]# file /dev/tty1
/dev/tty1: character special (4/1)
[root@station230 ~]# file /dev/initctl
/dev/initctl: fifo (named pipe)
=================================================================
三、bash功能
1. 命令和文件自动补全<tab> 注意:Tab只能补全命令和文件
# ls /etc/sysconfig/network-scripts/
# ls /etc/sysconfig/network-scripts/ifcfg-eth0
# service network restart 这里面service是命令,能补全,其他的不行
# date -s 12:30
2. 快捷键
^c 终止前台运行的程序 或者 另起一行
^d 结束
^l 清屏
^a 光标到命令行的最前端
^e 。。。。。。。。后端
^r 搜索历史命令,利用关键词
3. 历史命令
# history
a. 光标上下键
b. ^r (查找。输入一段某条命令的关键字:必须是连续的)
c. !220 (运行历史命令里第220个命令)
d. !字符串 如:!file 此命令执行的是file操作过的最后一条命令,它会先显示一下你所执行的命令
e. !$
# ls /etc/sysconfig/network-scripts/
# cd !$
cd /etc/sysconfig/network-scripts/
4. 别名
# alias 查看系统当前的别名
ll='ls -l --color=tty'
# alias tianyun='ls /etc/sysconfig/network-scripts/' 建立别名
# unalias tianyun 取消tianyun这个别名
=============================================================
小知识:
shell查找命令顺序:
1. 以路径(绝对路径,相对路径)开始命令,例如:/bin/ls
2. 别名
3. shell内置命令
4. $PATH
# which ls 查看ls命令位置
alias ls='ls --color=tty'
/bin/ls
type --查看命令的
type -a 命令 这个是查看命令的全部,别名或者所在目录
type 查看命令的优先级
[root@station230 ~]# type -a ls 比如 这个有两个ls
ls is aliased to `ls --color=tty'
ls is /bin/ls
[root@station230 ~]# type ls 这个显示出别名优先于/bin/ls
ls is aliased to `ls --color=tty'
扩展阅读:http://vbird.dic.ksu.edu.tw/linux_basic/0320bash.php#bash