linux命令ls显示绿色,51CTO博客-专业IT技术博客创作平台-技术成就梦想

命令解释器,我们可以SHELL实现对Linux系统的管理例如:

1. 文件管理

2. 用户管理

3. 权限管理

4. 磁盘管理

5. 软件管理

6. 网络管理

......

内容提要:

bash shell提示符

shell 语法

bash 特性

Linux获得帮助

一、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.

二、shell 语法

=====================

命令    选项   参数

[root@station230 ~]# date

[root@station230 ~]# date +%F

[root@station230 ~]# date -s 12:30

命令:整条shell命令的主体

选项:会影响会微调命令的行为//通常以 -, --, +

参数:命令作用的对象

[root@instructor Desktop]# ls

1.png    tianyun_ULA03.ctb~       tigervnc-1.1.0-5.el6.x86_64.rpm

2.png    tianyun_ULA04.ctb        ULE初始化.ctb

3.png    tianyun_ULA04.ctb~       video_install.sh

ftp      tianyun_ULE_2013_12.ctb

ftp.png  tianyun_ULE.ncd

[root@instructor Desktop]# ls /home/

alice  guests  instructor  lost+found  student

[root@instructor Desktop]# ls -a /home/

.  ..  alice  guests  instructor  lost+found  student

==================================================================

小知识:

*******文件时间*******

ls -l 文件名 仅看的是文件的修改时间

Linux文件有三种时间:

# stat anaconda-ks.cfg

访问时间: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设备文件(字符设备)打印机,终端/dev/tty1

s套接字文件

p管道文件

l链接文件(淡蓝色)

方法二:file

[root@yangs ~]# file anaconda-ks.cfg

anaconda-ks.cfg: ASCII English text

[root@yangs ~]# file /bin/ls

[root@yangs ~]# file /home

[root@yangs ~]# file /dev/sda

/dev/sda: block special                                                              块设备

[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)                                                     管道

[root@tianyun ~]# file /dev/log

/dev/log: socket                                                                         套接字

[root@tianyun ~]# ll anaconda-ks.cfg /dev/tty1 /dev/sda1

=================================================================

三、bash特性

1. 命令和文件(参数)自动补全  注意:Tab只能补全命令和文件  RHEL6

# ls /etc/sysconfig/network-scripts/

# ls /etc/sysconfig/network-scripts/ifcfg-eth0

# cat /etc/sysconfig/network-scripts/ifcfg-eth0

# service network restart

# service sshd restart

# date -s 12:30

2. 快捷键

^c   终止前台运行的程序

^d   退出 等价exit

^l    清屏

^a   光标移到命令行的最前端

^e   光标移到命令行的后端

^u   删除光标前所有字符

^k   删除光标后所有字符

^r   搜索历史命令,利用关键词

Alt+. 引用上一个命令的最后一个参数,等价于!$

ESC . 引用上一个命令的最后一个参数,等价于!$

# ls /etc/sysconfig/network-scripts/ifcfg-eth0

# cat ESC .

3. 历史命令

# history

a. 光标上下键

b. ^r //搜索历史命令(输入一段某条命令的关键字:必须是连续的)

c. !220//执行历史命令中第220条命令

d. !字符串//搜索历史命令中最近一个以xxxx字符开头的命令,例如!ser

e. !$    //引用上一个命令的最后一个参数

[root@instructor ~]# ls   /root   /home

[root@instructor ~]# cd !$

cd /home

[root@instructor ~]# ls   /root   /home

[root@instructor ~]# touch !$/file1

touch /home/file1

4. 别名

# alias//查看系统当前的别名

ll='ls -l --color=tty'

# alias tianyun='ls /etc/sysconfig/network-scripts/'    //建立别名

# unalias  tianyun

//取消tianyun这个别名

[root@tianyun ~]# type -a ls

ls is aliased to `ls --color=auto'

ls is /bin/ls

[root@tianyun ~]# ls                                                    //别名优先

[root@tianyun ~]# \ls                                                   //跳过别名

四、Linux获得帮助

1. 命令  --help

# ls --help

用法:ls [选项]... [文件]...

ls 常见选项

-a    all,查看目录下的所有文件,包括隐藏文件

-l     长列表显示

-h    human 以人性化方式显示出来

-d    只列出目录名,不列出其他内容

-t     按修改时间排序

-S    按文件的Size排序

-r     逆序排列

-i      显示文件的inode号(索引号)

# date --help

Usage: date [OPTION]... [+FORMAT]

or:  date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]

# date 0214080014

# date 0214080014.00

2. man 手册名,例如man ls

搜索:/-h  n N

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

/usr/bin/passwd命令,修改用户密码   man 1 passwd

/etc/passwd保存用户信息的文件   man 5 passwd

/etc/exports 之后将讲到nfs服务的配置文件 man exports    man 5 exports

技巧二:按关键字检索(适合记不住手册的全名时使用)

man ftpd_selinux

man -k "_selinux"       //手册名或手册描述中包含关键字_selinux

注:从whatis数据库里找(# makewhatis)

技巧三:在所有章节中查询

# man -a passwd

# man -f passwd

示例:

# man genisop_w_picpath

/EXAMPLES

To create a vanilla ISO9660 filesystem p_w_picpath in the file

cd.iso,  where the directory cd_dir will become the root

directory if the CD, call:

% genisop_w_picpath -o cd.iso cd_dir

[root@instructor ~]# genisop_w_picpath -o home.iso /home/

[root@instructor ~]# file home.iso

home.iso: ISO 9660 CD-ROM filesystem data 'CDROM

3. /usr/share/doc

参考文档、配置模板文件

例如:PAM

# firefox /usr/share/doc/pam-1.1.1/html/Linux-PAM_SAG.html

4. 官方手册

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

例如:Apache官方手册

5. baidu, google

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值