初识linux

初识shell:
GNU bash

命令解释器,我们可以SHELL实现对Linux系统的管理例如:
1. 文件管理
2. 用户管理
3. 权限管理
4. 磁盘管理
5. 软件管理
6. 网络管理
......


一、bash shell提示符:

[root@localhost ~]# date
2014年 04月 21日 星期一 22:10:04 CST
[root@localhost ~]# whoami
root
[root@localhost ~]# useradd test
[root@localhost ~]# passwd test
更改用户 test 的密码 。
新的 密码:
无效的密码: 过短
无效的密码: 过于简单
重新输入新的 密码:
passwd: 所有的身份验证令牌已经成功更新。



、语法

命令:整条shell命令的主体
选项:会影响或微调命令的行为//通常以 -,--, +
参数:命令作用的对象

[root@localhost test]# ls
file1  file2

[root@localhost test]# ls -l

总用量 0
-rw-r--r-- 1 root root 0 4月  21 22:18 file1
-rw-r--r-- 1 root root 0 4月  21 22:18 file2

[root@localhost test]# ls -l file1

-rw-r--r-- 1 root root 0 4月  21 22:18 file1


ls   查看一个目录下有什么文件,或者某一个文件是否存在
-a   all,查看目录下的所有文件,包括隐藏文件
-l   给出文件的长列表
-h   human 人性化方式显示出来  
-d   只列出目录名,不列出其他内容
-v   显示详细过程


#####小知识####

文件时间

Linux文件有三种时间:

访问时间:atime,查看 内容
修改时间:mtime,修改 内容
改变时间:ctime,文件 属性,比如权限


[root@localhost test]# ls -l file1
-rw-r--r-- 1 root root 0 4月  21 22:18 file1

[root@localhost test]# stat file1
 File: "file1"
 Size: 0             Blocks: 0          IO Block: 4096   普通空文件
Device: fc02h/64514d    Inode: 670943      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2014-04-21 22:18:47.443998777 +0800
Modify: 2014-04-21 22:18:47.443998777 +0800
Change: 2014-04-21 22:18:47.443998777 +0800


改变atime:

[root@localhost test]# cat file1
[root@localhost test]# stat file1
 File: "file1"
 Size: 0             Blocks: 0          IO Block: 4096   普通空文件
Device: fc02h/64514d    Inode: 670943      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2014-04-23 05:23:29.093001719 +0800
Modify: 2014-04-21 22:18:47.443998777 +0800
Change: 2014-04-21 22:18:47.443998777 +0800


文件类型:

通过颜色判断文件的类型是错误的!!!
Linux文件是没有扩展名!!!

方法一:
ls -l 文件名    //看第一个字符
-普通文件(文本文件,二进制,电影,图片。。。)
d目录文件(蓝色
b设备文件(块设备)存储设备硬盘,U盘
c设备文件(字符设备)打印机,终端/dev/tty1
s套接字文件
p管道文件
l链接文件(淡蓝色


[root@localhost ~]# file anaconda-ks.cfg
anaconda-ks.cfg: ASCII English text

[root@localhost ~]# file /bin/ls
/bin/ls: ELF 64-bit LSB executable.....

[root@localhost ~]# file /dev/vda
/dev/vda: block special

[root@localhost ~]# file /etc/grub.conf
/etc/grub.conf: symbolic link to `../boot/grub/grub.conf'
[root@localhost ~]# file /dev/tty
/dev/tty: character special

...


、bash功能

1.命令文件自动补全<Tab>键   注意:Tab只能补全命令和文件

[root@localhost ~]# ls /etc/sysconfig/network-scripts/
[root@localhost ~]# ls /etc/sysconfig/network-scripts/ifcfg-eth0
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
[root@localhost ~]# service network restart
[root@localhost ~]# date -s 12:30


2.快捷键

^c   终止前台运行的程序
^d   退出
^l   清屏
^a   光标移到命令行的最前端
^e   光标移到命令行的后端
^r   搜索历史命令,利用关键词
Alt+. 引用上一个命令的最后一个参数,等价于!$


3.历史命令

[root@localhost ~]# history
a. 光标上下键
b. ^r             //搜索历史命令(输入一段某条命令的关键字:必须是连续的)
c. !220           //执行历史命令中第220条命令
d. !字符串        //搜索历史命令中最近一个以xxxx字符开头的命令,例如!ser
e. !$             //引用上一个命令的最后一个参数


[root@localhost grub]# ls /root/test/
file1  file2
[root@localhost grub]# cd !$
cd /root/test/
[root@localhost test]# pwd
/root/test


4.别名

[root@localhost ~]# alias sanyuan='ls -l /root/test'    //设置别名
[root@localhost ~]# sanyuan                             //引用别名
总用量 4
-rwxr--r-- 1 root root 4 4月  23 05:25 file1
-rw-r--r-- 1 root root 0 4月  21 22:18 file2

[root@localhost ~]# unalias sanyuan                     //取消别名


grep使用颜色:

[root@localhost test]# ls | grep file1
file1
方法一:
[root@localhost ~]# grep root /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
[root@localhost ~]# grep --color root /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin

方法二:定义别名grep
[root@localhost ~]# alias grep='grep --color'
[root@localhost ~]# type -a grep
grep is aliased to `grep --color'
grep is /bin/grep
[root@localhost ~]# grep root /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin


####小知识####
bash shell查找命令顺序:
1. 别名      
2. shell内置命令
3. $PATH//环境变量,查看环境变量echo $PATH,例如/bin/ls

# which ls//查看ls命令位置
alias ls='ls --color=tty'
       /bin/ls

type -a 命令       //查看命令类型
[root@station230 ~]# type -a ls  
ls is aliased to `ls --color=tty'
ls is /bin/ls


Linux获得帮助:

1.命令 --help

[root@localhost test]# ls --help
用法:ls [选项]... [文件]...

[root@localhost test]# date --help
用法:date [选项]... [+格式]
 或:date [-u|--utc|--universal][MMDDhhmm[[CC]YY][.ss]]
以给定的格式显示当前时间,或是设置系统日期。

[root@localhost test]# date 0423140914.50
2014年 04月 23日 星期三 14:09:50 CST
[root@localhost test]# hwclock -w        //将系统时间写入BIOS


2.man,info手册,例如:man ls

搜索:/-h    nN    //搜-h选项和上下翻屏

wKioL1NXW26jrwjgAAG8NJKmxzU456.jpg

技巧一:Man手册是分章节,按章节来查找,常用的是1(命令用法),5(文本规范),8(系统管理命令)

/usr/bin/passwd    命令,修改用户密码       man 1 passwd
/etc/passwd        保存用户信息的文件       man 5 passwd
/etc/exports       man exports              man 5 exports


技巧二:按关键字检索(适合记不住手册的全名时使用)
man -k "passwd"
man -k "_selinux";  man ftpd_selinuxwd    
注:从whatis数据库里找(# makewhatis)

# man -a passwd
# man -f passwd


[root@localhost test]# makewhatis        //没有man时执行此命令


注:info手册比man手册介绍的更为详细,但找起来也更麻烦一些


3. /usr/share/doc
参考文档、配置模块文件
例如:PAM
# ls /usr/share/doc/pam-1.1.1/
# firefox /usr/share/doc/pam-1.1.1/html/Linux-PAM_SAG.html

4. RedHat官方手册
http://docs.redhat.com

5. baidu, google



你可能感兴趣的:(初识linux)