为了账号安全,请及时绑定邮箱和手机立即绑定
慕课网数字资源数据库体验端
Linux达人养成计划 I_学习笔记_慕课网
为了账号安全,请及时绑定邮箱和手机立即绑定

Linux达人养成计划 I

Tony Linux系统工程师
难度入门
时长 6小时 0分
  • .echo输出命令

    .echo[选项][输出内容]

    .选项:

    - -e:不支持反斜线控制的字符转换(ASCII码)

    如:[liu@localhost ~]$ echo "world!"

    -bash: !": event not found

    “”内双引号不支持!或?;

    [liu@localhost ~]$ echo "world"

    World

    “”内的控制字符

    控制字符

    作用解释

    \a

    输出警告音

    \b

    退格键,也就是向左删除键

    \n

    换行符

    \r

    回车符

    \t

    制表符,也就是Tab键

    \v

    垂直制表符

    \0nnn

    按照八进制ASCII码表输出字符。其中0为数字零,nnn是三位八进制数

    \xhh

    按照十六进制ASCII码表输出字符。其中hh是两位十六进制数

    #删除左侧字符

    .[root@localhost ~]echo –e “hell\bo”

    #制表符与换行符

    [root@localhost ~]echo –e “h\te\tl\nl\to”(符号:\t、\t、\n、\t)

    如:[liu@localhost ~]$ echo -e "h\te\tl\nl\to\t"

    h       e       l

    l        o     

    #按照十六进制ASCII码也同样可以输出

    .[root@localhost ~]#echo -e  "\x68\t\x65\t\x6c\n\x6c\t\x6f"

    如:[liu@localhost ~]$ echo -e "\x68\t\x65\t\x6c\n\x6c\t\x6f"(ASCII码根据16进制对应输出字符)

    h       e       l

    l        o

    #输出颜色

    .[root@localhost ~]#echo -e “\e[1;31m 我的名字 \e[0m”

    .#30m=黑色,31m=红色,32m=绿色,33m=黄色

    .#34m=蓝色,35m=洋红,36m=青色,37m=白色

    #设置文字颜色(因为使用Xshell支持中文输入,Linux不支持中文输入)

    如:[liu@localhost ~]$ echo -e "\e[1;31m 我的名字 \e[0m"

     我的名字

    #shell脚本编写

    . [liu@localhost ~]$ vi hello.sh

    .#!/bin/bash

    #The first program

    . echo -e "\e[1;34m我的名字\e[0m" (加空格需要””)

    .脚本执行:

    #赋予执行权限,直接运行

    .chmod 755 hello.sh

    ../hello.sh

    #通过Bash调用执行脚本

    .bash hello.sh

    如:[liu@localhost ~]$ vim hello.sh

    .sh文件中的shell脚本:

    #!/bin/bash

    echo -e "\e[1;31m 我的名字 \e[0m"(注意:退出按下esc键,然后输入:wq退出保存即可!)

    [liu@localhost ~]$ bash hello.sh

     我的名字

    #先授权后执行

    [liu@localhost ~]$ chmod 755 hello.sh

    [liu@localhost ~]$ ./hello.sh

     我的名字


    查看全部
    1 采集 收起 来源:脚本执行方式

    2018-04-25

  • 软链接特征


    查看全部
    0 采集 收起 来源:Linux链接命令

    2018-04-25

  • 硬链接的简介

    查看全部
    0 采集 收起 来源:Linux链接命令

    2018-04-25

  • 目录

    查看全部
  • cd的用法  简述

    查看全部
  • Shell基础(linux外壳)

    1.      Shell概述:

    .Shell是一个命令解释器,它为用户提供了一个向linux内核发送请求以便运行程序的界面系统级程序,用户可以用shell来启动、挂起、停止甚至是编写一些程序。

    .Shell还是一个功能相当强大的编程语言,易编写,易调试,灵活性较强。Shell是解释执行的的脚本语言,在shell中可以直接调用linux系统命令。

    .Shell的分类

    .Bourne shell:从1979起Unix就开始使用Bourne shell,Bourne shell的主文件为sh。(在shell编程方便相当优秀,但处理与用户的交互方便作得不如其他几种shell)

    .C shell:C shell主要在BSD版本(伯克利软件套件)的Unix系统中使用,其语法和c语言相类似而得名。

    .shell的两种主要语法类型有Bourne和C,这两种语法彼此不兼容。Bourne家族主要包括sh(unix最初使用的shell,而且在每种unix上都可以使用)、ksh、Bash(LinuxOS默认的,它是Bourne shell的扩展)、ksh(全称korn shell,集合C shell和Bourne shell的优点并且和Bourne shell完全兼容)、psh、zsh;c家族主要包括:csh、tcsh(linux提供的C shell的一个扩展版本,包括命令行编辑,可编程单词补全,拼写校正,历史命令替换,作业控制和类似c语言的语法,不仅和Bash shell提示符兼容,而且还提供比Bash shell更多的提示符参数)

    .Linux支持的shell

    ./etc/shells

    .Bash(现使用的):Bash与sh兼容,现在使用的Linux就是使用Bash作为用户的基本shell。

    如:判断当前计算机的shell是哪个版本(当前是bash)

    [root@localhost liu]# echo $SHELL

    /bin/bash

    如:查看Linux当中有哪些shell

    [root@localhost liu]# vi /etc/shells

     

    /bin/sh

    /bin/bash

    /sbin/nologin

    /bin/tcsh

    /bin/csh

    ~                                                                                      

    ~                                                                                      

    ~                                                                                       

    ~                                                                                      

    ~                                                                                      

    ~                                                                                       

    ~                                                                                      

    ~                                                                                      

    ~                                                                                       

    ~                                                                                      

    ~                                                                                      

    ~                                                                                       

    ~                                                                                      

    ~                                                                                      

    ~                                                                                       

    ~                                                                                      

    ~                                                                                      

    ~                                                                                       

    ~                                                                                      

    ~                                                                                      

    "/etc/shells" 5L, 51C

    如:使用不同shell方法,sh是调用系统资源比较少,[root@localhost liu]# bash系统本身就是bash,所以没必要再exit

     

    [root@localhost liu]# sh

    sh-4.1# exit

    exit

    [root@localhost liu]# bash

    [root@localhost liu]# tcsh

    [liu@localhost liu]# exit

    exit

    [root@localhost liu]# csh

    [liu@localhost liu]# exit

    exit

    2.Shell脚本执行方式

    文本框: 用户

      Shell 

      应用程序  

    椭圆: 内核 (硬件)spacer.gif3.bash的基本功能



    查看全部
    0 采集 收起 来源:shell概述

    2018-04-25

  • 常用命令

    .linux使用系统命令来挂载盘符,windows是字母挂载盘符。

    .查询与自动挂载

    #查询系统中已经挂载的设备

    .[root@localhost ~]#mount

    #依据配置文件/etc/fstab的内容,自动挂载

    .[root@localhost ~]#mount -a

    .挂载命令格式

    .[root@localhost ~]#mount[-t 文件系统] [-o 特殊选项] 设备 文件名 挂载点

    .选项:

    .-t文件系统:加入文件系统类型来指定挂载的类型,可以ext3、ext4、ios9660等文件系统(默认centos7是xfs)

    .-o 特殊选项:可以指定挂载的额外选项

     

    .[root@localhost ~]#mount -o remount,noexec/home

    #重新挂载/boot分区,并使用noexec权限

    #记得改回来啊,要不然会影响系统启动

    .[root@localhost ~]#cd/home

    .[root@localhost ~]#vi hello.sh

    .[root@localhost ~]# chmod 755 hello.sh

    .[root@localhost ~]#./hello.sh

    .[root@localhost ~]#mount -o remount,exec/home

    .光盘挂载

    #建立挂载点

    .[root@localhost ~]#mkdir /mnt/cdrom/

    #挂载光盘

    .[root@localhost ~]#mount –t ios9660 /dev/cdrom /mnt/cdrom/

    .[root@localhost ~]#mount /dev/sr0 /mnt/cdrom/

    #卸载挂载

    #设备文件名或挂载点

    .[root@localhost ~]#umount

    .[root@localhost ~]#umount /mnt/cdrom

    .u盘挂载

    注:Linux默认是不支持ntfs文件系统的(需要使用ntfs-3g工具或编译内核,网络数据传递才是linux重点)

    #查看u盘设备文件名

    .[root@localhost ~]#fdisk -l

    .[root@localhost ~]#mount -t vfat/dev/sdb1 /mnt/usb

    如:[root@localhost liu]# fdisk –l

     

    Disk /dev/sda: 11.8 GB, 11811160064 bytes

    255 heads, 63 sectors/track, 1435 cylinders

    Units = cylinders of 16065 * 512 = 8225280 bytes

    Sector size (logical/physical): 512 bytes / 512 bytes

    I/O size (minimum/optimal): 512 bytes / 512 bytes

    Disk identifier: 0x000f3b0a

    理解:查看系统挂载的设备

    如:.[root@localhost ~]#mount -t vfat/dev/sdb1 /mnt/usb

    理解:sdb1在dev后面写sdb1,sdb2在dev后面写sdb2,vfat是windows的fast32

     

       Device Boot      Start         End      Blocks   Id  System

    /dev/sda1   *           1          26      204800   83  Linux

    Partition 1 does not end on cylinder boundary.

    /dev/sda2              26         222     1572864   83  Linux

    Partition 2 does not end on cylinder boundary.

    /dev/sda3             222        1436     9755648   83  Linux

    .查看用户登录

    .w:用户名(查看登录用户信息)

    命令输出:

    .USER:登录的用户名

    .TTY:登录终端

    .FROM:从哪个IP地址登录

    .LOGIN@:登录时间

    IDLE:用户闲置时间

    JCPU:指的是和该终端连接的所有进程占用的时间。这个时间里并不包括过去的后台作业时间,但却包括当前正在运行的后台作业所占用的时间

    PCPU:是指当前进程所占用的时间

    WHAT:当前正在运行的命令

    如;[root@localhost liu]# w

     02:01:16 up 34 min,  2 users,  load average: 0.00, 0.00, 0.07

    USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT

    liu      tty1     :0               01:28     ?     1.56s  0.06s pam: gdm-password

    liu      pts/0    192.168.189.1    01:31    0.00s  0.04s  0.03s sshd: liu [priv]

    .who:用户名(查看登录信息)

    .命令输出:

    -用户名

    -登录终端

    -登录时间(登录来源ip地址)

    如:[root@localhost liu]# who

    liu      tty1         2018-04-25 01:28 (:0)

    liu      pts/0        2018-04-25 01:31 (192.168.189.1)

    .last:查询当前登录和过去登录的用户信息

    .last命令默认是读取/var/log/wtmp文件数据(直接vi打开/var/log/wtmp路径文件为二进制文件,不能直接vi操作,last命令显示正常,防止被恶意篡改)

    .命令输出

    -用户名

    -登录终端

    -登录ip

    -登录时间

    -退出时间(在线时间)

    如:[root@localhost liu]# last

    liu      pts/0        192.168.189.1    Wed Apr 25 01:31   still logged in  

    liu      tty1         :0               Wed Apr 25 01:28   still logged in  

    reboot   system boot  2.6.32-71.el6.x8 Wed Apr 25 01:26 - 02:03  (00:36)   

    liu      pts/0        192.168.189.1    Tue Apr 24 08:37 - 10:04  (01:26)   

    liu      pts/0        192.168.189.1    Tue Apr 24 08:28 - 08:37  (00:09)   

    liu      pts/0        :0.0             Tue Apr 24 08:28 - 08:28  (00:00)   

    liu      tty1         :0               Tue Apr 24 08:26 - 10:04  (01:38)   

    reboot   system boot  2.6.32-71.el6.x8 Tue Apr 24 08:25 - 10:05  (01:39)   

    liu      pts/0        192.168.189.1    Tue Apr 24 07:53 - down   (00:00)   

    liu      tty1         :0               Tue Apr 24 07:41 - down   (00:11)   

    reboot   system boot  2.6.32-71.el6.x8 Tue Apr 24 07:41 - 07:53  (00:11)   

    liu      pts/0        192.168.189.1    Tue Apr 24 06:59 - 07:40  (00:41)   

    liu      pts/3        192.168.189.1    Tue Apr 24 05:55 - 07:40  (01:45)   

    liu      pts/2        192.168.189.1    Tue Apr 24 05:03 - 07:40  (02:37)   

    liu      pts/1        192.168.189.1    Tue Apr 24 03:49 - 07:08  (03:19)   

    liu      pts/0        192.168.189.1    Tue Apr 24 03:25 - 05:58  (02:33)   

    liu      tty1         :0               Tue Apr 24 03:23 - 07:40  (04:16)   

    reboot   system boot  2.6.32-71.el6.x8 Tue Apr 24 03:22 - 07:40  (04:18)    

    liu      pts/1        :0.0             Mon Apr 23 10:27 - 11:14  (00:47)   

    liu      pts/0        :0.0             Mon Apr 23 10:21 - 11:14  (00:53)   

    liu      pts/0        :0.0             Mon Apr 23 10:20 - 10:20  (00:00)   

    liu      pts/0        :0.0             Mon Apr 23 10:20 - 10:20  (00:00)   

    liu      pts/0        :0.0             Mon Apr 23 10:19 - 10:20  (00:01)   

    liu      pts/0        :0.0             Mon Apr 23 10:18 - 10:18  (00:00)   

    liu      pts/0        :0.0             Mon Apr 23 10:16 - 10:16  (00:00)   

    liu      pts/1        :0.0             Mon Apr 23 10:15 - 10:15  (00:00)   

    liu      pts/0        :0.0             Mon Apr 23 10:15 - 10:16  (00:00)   

    liu      pts/3        192.168.189.1    Mon Apr 23 07:56 - 11:13  (03:17)    

    liu      pts/2        192.168.189.1    Mon Apr 23 07:51 - 07:56  (00:04)   

    liu      pts/0        192.168.189.1    Mon Apr 23 06:56 - 09:29  (02:32)   

    liu      pts/4        :0.0             Mon Apr 23 04:56 - 06:55  (01:59)   

    liu      pts/3        :0.0             Mon Apr 23 04:55 - 06:56  (02:00)   

    liu      pts/2        :0.0             Mon Apr 23 04:54 - 06:56  (02:01)   

    liu      pts/1        192.168.189.1    Mon Apr 23 03:26 - 08:08  (04:41)   

    liu      pts/0        :0.0             Mon Apr 23 03:25 - 06:56  (03:30)   

    liu      tty1         :0               Mon Apr 23 03:20 - 11:14  (07:53)   

    reboot   system boot  2.6.32-71.el6.x8 Mon Apr 23 03:13 - 11:14  (08:00)   

    liu      tty1         :0               Mon Apr 23 03:01 - 03:09  (00:07)   

    reboot   system boot  2.6.32-71.el6.x8 Mon Apr 23 02:57 - 03:09  (00:12)   

    liu      pts/1        192.168.248.1    Sat Apr 21 11:06 - 11:25  (00:18)   

    liu      pts/1        192.168.248.1    Sat Apr 21 10:00 - 10:57  (00:57)   

    liu      pts/5        192.168.248.1    Sat Apr 21 07:09 - 09:25  (02:15)   

    liu      pts/4        :0.0             Sat Apr 21 06:20 - 11:25  (05:04)   

    liu      pts/3        :0.0             Sat Apr 21 06:20 - 06:20  (00:00)   

    liu      pts/0        :0.0             Sat Apr 21 06:18 - 11:25  (05:06)   

    liu      pts/2        192.168.248.1    Sat Apr 21 05:41 - 09:17  (03:35)   

    liu      pts/1        192.168.248.1    Sat Apr 21 05:11 - 07:35  (02:24)    

    liu      pts/0        :0.0             Sat Apr 21 05:07 - 06:18  (01:11)   

    liu      tty1         :0               Sat Apr 21 05:06 - 11:25  (06:19)   

    reboot   system boot  2.6.32-71.el6.x8 Sat Apr 21 05:05 - 11:25  (06:20)   

    reboot   system boot  2.6.32-71.el6.x8 Sat Apr 21 05:03 - 11:25  (06:22)   

    liu      pts/1        :0.0             Sat Apr 21 04:27 - crash  (00:36)   

    liu      pts/2        192.168.248.1    Sat Apr 21 04:11 - crash  (00:51)   

    liu      pts/1        192.168.248.1    Sat Apr 21 04:10 - 04:11  (00:00)   

    liu      pts/1        192.168.248.1    Sat Apr 21 03:56 - 04:10  (00:14)   

    liu      pts/0        :0.0             Sat Apr 21 03:55 - crash  (01:08)   

    liu      tty1         :0               Sat Apr 21 03:42 - crash  (01:21)    

    reboot   system boot  2.6.32-71.el6.x8 Sat Apr 21 03:38 - 11:25  (07:47)   

    liu      pts/0        :0.0             Fri Apr 20 12:17 - 12:18  (00:00)   

    liu      pts/0        :0.0             Fri Apr 20 12:16 - 12:16  (00:00)   

    liu      pts/3        :0.0             Fri Apr 20 11:35 - 11:35  (00:00)   

    liu      pts/2        192.168.248.1    Fri Apr 20 11:22 - 12:23  (01:00)   

    liu      pts/1        192.168.248.1    Fri Apr 20 09:00 - 11:37  (02:37)   

    liu      pts/4        :0.0             Fri Apr 20 08:45 - 11:55  (03:09)   

    liu      pts/1        192.168.248.1    Fri Apr 20 08:00 - 08:59  (00:59)   

    liu      pts/3        192.168.248.1    Fri Apr 20 06:48 - 09:32  (02:44)   

    liu      pts/2        192.168.248.1    Fri Apr 20 06:15 - 09:33  (03:18)   

    liu      pts/1        192.168.248.1    Fri Apr 20 05:26 - 07:46  (02:20)   

    liu      pts/1        192.168.248.1    Fri Apr 20 04:43 - 04:59  (00:16)   

    liu      pts/0        :0.0             Fri Apr 20 04:42 - 11:55  (07:13)   

    liu      tty1         :0               Fri Apr 20 04:38 - 12:23  (07:44)   

    reboot   system boot  2.6.32-71.el6.x8 Fri Apr 20 04:37 - 12:23  (07:46)   

    liu      pts/0        :0.0             Thu Apr 19 13:12 - 13:12  (00:00)   

    liu      pts/0        192.168.248.1    Thu Apr 19 13:07 - 13:11  (00:03)   

    liu      pts/0        192.168.248.1    Thu Apr 19 12:50 - 13:07  (00:17)   

    liu      pts/0        :0.0             Thu Apr 19 12:47 - 12:47  (00:00)    

    liu      pts/1        192.168.248.1    Thu Apr 19 12:15 - 12:50  (00:35)   

    liu      pts/0        :0.0             Thu Apr 19 12:08 - 12:32  (00:24)   

    liu      tty1         :0               Thu Apr 19 12:07 - 13:13  (01:06)   

    reboot   system boot  2.6.32-71.el6.x8 Thu Apr 19 12:06 - 13:13  (01:06)   

    liu      tty1         :0               Thu Apr 19 11:58 - 11:59  (00:01)   

    reboot   system boot  2.6.32-71.el6.x8 Thu Apr 19 11:57 - 11:59  (00:02)   

    liu      pts/0        :0.0             Thu Apr 19 11:56 - 11:56  (00:00)   

    liu      tty1         :0               Thu Apr 19 11:54 - 11:56  (00:02)   

    reboot   system boot  2.6.32-71.el6.x8 Thu Apr 19 11:39 - 11:56  (00:16)   

    liu      tty1         :0               Thu Apr 19 11:35 - 11:37  (00:02)    

    reboot   system boot  2.6.32-71.el6.x8 Thu Apr 19 11:34 - 11:37  (00:02)   

    liu      pts/0        :0.0             Thu Apr 19 11:31 - 11:33  (00:02)   

    liu      pts/0        :0.0             Thu Apr 19 08:06 - 11:21  (03:15)   

    liu      tty1         :0               Thu Apr 19 07:49 - 11:33  (03:44)   

    reboot   system boot  2.6.32-71.el6.x8 Thu Apr 19 07:48 - 11:33  (03:45)   

    liu      pts/0        :0.0             Wed Apr 18 14:03 - 14:52  (00:49)   

    liu      pts/1        :0.0             Wed Apr 18 12:23 - 14:03  (01:40)   

    liu      pts/0        :0.0             Wed Apr 18 12:19 - 12:23  (00:04)   

    liu      pts/1        :0.0             Wed Apr 18 11:27 - 12:18  (00:51)   

    liu      pts/0        :0.0             Wed Apr 18 11:21 - 11:27  (00:05)   

    liu      pts/0        :0.0             Wed Apr 18 11:21 - 11:21  (00:00)   

    liu      pts/0        :0.0             Wed Apr 18 10:58 - 11:21  (00:22)   

    liu      tty1         :0               Wed Apr 18 10:48 - 14:53  (04:04)   

    reboot   system boot  2.6.32-71.el6.x8 Wed Apr 18 10:47 - 14:53  (04:05)   

    liu      pts/0        :0.0             Sun Dec 31 00:05 - 00:05  (00:00)   

    liu      tty1         :0               Sun Dec 31 00:02 - 00:06  (00:03)   

    reboot   system boot  2.6.32-71.el6.x8 Sun Dec 31 00:00 - 00:06  (00:05)   

     

    wtmp begins Sun Dec 31 00:00:54 2017

    .lastlog:查看所有用户的最后一次登录时间

    .lastlog命令默认是读取/var/log/lastlog文件内容

    .命令输出

    -用户名

    -登录终端

    -登录ip

    -最后一次登录时间

    如:[root@localhost liu]# lastlog

    用户名           端口     来自             最后登陆时间

    root                                       **从未登录过**

    bin                                        **从未登录过**

    daemon                                     **从未登录过**

    adm                                        **从未登录过**

    lp                                         **从未登录过**

    sync                                       **从未登录过**

    shutdown                                   **从未登录过**

    halt                                       **从未登录过**

    mail                                       **从未登录过**

    uucp                                       **从未登录过**

    operator                                   **从未登录过**

    games                                      **从未登录过**

    gopher                                     **从未登录过**

    ftp                                        **从未登录过**

    nobody                                     **从未登录过**

    dbus                                       **从未登录过**

    usbmuxd                                    **从未登录过**

    avahi-autoipd                              **从未登录过**

    vcsa                                       **从未登录过**

    rpc                                        **从未登录过**

    rtkit                                      **从未登录过**

    abrt                                       **从未登录过**

    nscd                                       **从未登录过**

    haldaemon                                  **从未登录过**

    apache                                     **从未登录过**

    nslcd                                      **从未登录过**

    saslauth                                   **从未登录过**

    postfix                                    **从未登录过**

    avahi                                      **从未登录过**

    ntp                                        **从未登录过**

    rpcuser                                    **从未登录过**

    nfsnobody                                  **从未登录过**

    pulse                                      **从未登录过**

    gdm                                        **从未登录过**

    sshd                                       **从未登录过**

    tcpdump                                    **从未登录过**

    liu              pts/0    192.168.189.1    三 4月 25 01:31:15 +0800 2018


    查看全部
  • 输入重定向
    查看全部
    0 采集 收起 来源:输出重定向

    2018-04-25

  • 正确输出和错误输出同时保存
    查看全部
    0 采集 收起 来源:输出重定向

    2018-04-25

  • 输出重定向
    查看全部
    0 采集 收起 来源:输出重定向

    2018-04-25

  • 标准输入输出
    查看全部
    0 采集 收起 来源:输出重定向

    2018-04-24

  • 文件权限

    查看全部
    0 采集 收起 来源:Linux命令格式

    2018-04-24

  • 命令提示符

    查看全部
    0 采集 收起 来源:Linux命令格式

    2018-04-24

  • 软链接相当于win的快捷方式,其i节点记录的是真实文件的i节点

    查看全部
    0 采集 收起 来源:Linux链接命令

    2018-04-24

  • VMware虚拟机

    查看全部
    0 采集 收起 来源:虚拟机的安装

    2018-04-24

举报

0/150
提交
取消
课程须知
本课程作为Linux的入门课程,适合所有对Linux感兴趣的小伙伴们。零基础学习!还等什么,赶快来加入吧!
老师告诉你能学到什么?
通过学习本门课程,您将有如下收获: 1、全面了解Linux的前世今生 2、能够独立安装Linux操作系统 3、从对Linux常用命令的一无所知,到运用自如 4、与shell编程基础亲密接触
友情提示:

您好,此课程属于迁移课程,您已购买该课程,无需重复购买,感谢您对慕课网的支持!