zoukankan      html  css  js  c++  java
  • Linux基础命令(一)

    Linux 系统

    实验任务:

    一、了解Bash的特性

    1、Bash的特性:

    支持命令历史、命令补全、路径补全
    支持管道、重定向
    支持命令别名
    支持命令行编辑
    支持命令行展开
    支持文件名通配
    支持变量
    支持编程

    二、Bash的常用操作技巧及命令演示

    1、命令历史

    在键盘上输入history

    [root@localhost ~]# history 
        1 vi /etc/sysconfig/network-scripts/ifcfg-en33
        2 vi /etc/sysconfig/network-scripts/ifcfg-ens33
        3 ZZ
        4 s
        5 systemtl restart network
        6 ip a
        7 cd/root/Docements
        8 cd./path
        9 ls-a
       10 -a
       11 ip a
       12 history 
       13 ls 
       14 mkdir a
       15 ls
       16 mkdir -p {a{abc,def},b,c}
       17 ls a
       18 ls
       19 history 
       20 cd
       21 cd a
       22 cd a/
       23 ls
       24 cd
       25 ls
       26 ls a*
       27 move a hh
       28 mv a hh
       29 ls
       30 echo $a
       31 ench $shell
       32 ench $bash
       33 ench 
       34 mkdir a
       35 ls
       36 mkdir `b`
       37 history 
    [root@localhost ~]# 
    

    2、命令补全

    命令记不全的时候可以先输入一部分命令按键盘上的tab键,按一下能补全的就是唯一命令,按一下没反应就按两下,在陈列出来的命令中找到你要补全的命令

    [root@localhost ~]# w
    w watch wdctl whereis whiptail wipefs wpa_supplicant  
    wait watchgnupg weak-modules which who wpa_cli write           
    wall wc whatis while whoami wpa_passphrase  
    

    3、命令别名

    [root@localhost ~]# alias cdnet='cd/etc/sysconfig/network-scripts'
    [root@localhost ~]# alias
    alias cdnet='cd/etc/sysconfig/network-scripts'
    alias cp='cp -i'
    alias egrep='egrep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias grep='grep --color=auto'
    alias l.='ls -d .* --color=auto'
    alias ll='ls -l --color=auto'
    alias ls='ls --color=auto'
    alias mv='mv -i'
    alias rm='rm -i'
    alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
    

    4、命令行展开

    [root@localhost ~]# mkdir -p a/{b/{e,f},c/{g,h},d/{li}}
    

    5、文件名通配

    [root@localhost ~]# ls a*
    anaconda-ks.cfg
    
    a:
    b c d
    

    6、变量

    [root@localhost ~]# a=10
    [root@localhost ~]# echo $a
    10
    

    7、反引号,键盘左上角Esc下面的键,用于命令替换

    反引号里面只能放入命令,不然会报错,反引号也可以用 $() 替换

    [root@localhost ~]# echo `pwd`
    /root
    [root@localhost ~]# echo `jjyy`
    -bash: jjyy: 未找到命令
    
    [root@localhost ~]# echo $(pwd)
    /root
    

    8、单引号,强引用,不完成变量替换

    [root@localhost ~]# echo $a
    10
    [root@localhost ~]# echo '$a'
    $a
    

    9、双引号,弱引用,可以实现变量替换

    [root@localhost ~]# echo $a
    10
    [root@localhost ~]# echo "$a"
    10
    

    10、快捷键

    Ctrl+a 跳到命令行首
    Ctrl+e 跳到命令行尾
    Ctrl+u 删除光标至命令行首的内容
    Ctrl+k 删除光标至命令行尾的内容
    Ctrl+<-- 光标定位到离自己最近的一个单词前面
    Ctrl+l 清屏

    11、PATH:命令搜索的路径

    [root@localhost ~]# echo $PATH
    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
    

    12、HISTSIZE:定义命令历史最多能存多少条,默认为1000条

    [root@localhost ~]# echo $HISTSIZE 
    1000
    

    12、SHELL:当前系统使用的shell

    [root@localhost ~]# echo $SHELL
    /bin/bash
    

    13、ls命令

    ls命令常用选项有以下:
    -l:这里是小写的L,不是数字1,长格式显示
    -h:做单位转换
    -a:显示隐藏文件
    -d:显示目录自身的属性
    -t:以时间排序
    -r:逆序显示

    [root@localhost ~]# ls -l
    总用量 4
    drwxr-xr-x. 5 root root 33 9月 7 2019 a
    -rw-------. 1 root root 1451 9月 6 19:48 anaconda-ks.cfg
    [root@localhost ~]# ls -lh
    总用量 4.0K
    drwxr-xr-x. 5 root root 33 9月 7 2019 a
    -rw-------. 1 root root 1.5K 9月 6 19:48 anaconda-ks.cfg
    [root@localhost ~]# ls -la
    总用量 28
    dr-xr-x---. 3 root root 144 9月 7 2019 .
    dr-xr-xr-x. 17 root root 224 9月 6 19:48 ..
    drwxr-xr-x. 5 root root 33 9月 7 2019 a
    -rw-------. 1 root root 1451 9月 6 19:48 anaconda-ks.cfg
    -rw-------. 1 root root 293 9月 7 14:34 .bash_history
    -rw-r--r--. 1 root root 18 12月 29 2013 .bash_logout
    -rw-r--r--. 1 root root 176 12月 29 2013 .bash_profile
    -rw-r--r--. 1 root root 176 12月 29 2013 .bashrc
    -rw-r--r--. 1 root root 100 12月 29 2013 .cshrc
    -rw-r--r--. 1 root root 129 12月 29 2013 .tcshrc
    [root@localhost ~]# ls -ld
    dr-xr-x---. 3 root root 144 9月 7 2019 .
    [root@localhost ~]# ls -lt
    总用量 4
    drwxr-xr-x. 5 root root 33 9月 7 2019 a
    -rw-------. 1 root root 1451 9月 6 19:48 anaconda-ks.cfg
    [root@localhost ~]# ls -lr
    总用量 4
    -rw-------. 1 root root 1451 9月 6 19:48 anaconda-ks.cfg
    drwxr-xr-x. 5 root root 33 9月 7 2019 a
    
    

    14、命令cd:切换目录

    [root@localhost ~]# cd /etc/
    [root@localhost etc]# cd /etc/sysconfig/network-scripts/
    [root@localhost network-scripts]# cd -
    /etc
    [root@localhost etc]# pwd
    /etc
    [root@localhost etc]# cd-
    -bash: cd-: 未找到命令
    [root@localhost etc]# cd -
    /etc/sysconfig/network-scripts
    [root@localhost network-scripts]# pwd
    /etc/sysconfig/network-scripts
    

    15、命令pwd:打印当前工作目录

    [root@localhost ~]# pwd
    /root
    [root@localhost ~]# echo $PWD
    /root
    

    16、命令mkdir:创建目录

    -p:创建目录时若父目录不存在则自动创建
    -v:显示创建目录的过程

    [root@localhost ~]# mkdir -pv c/d/e/f/g/h
    mkdir: 已创建目录 "c"
    mkdir: 已创建目录 "c/d"
    mkdir: 已创建目录 "c/d/e"
    mkdir: 已创建目录 "c/d/e/f"
    mkdir: 已创建目录 "c/d/e/f/g"
    mkdir: 已创建目录 "c/d/e/f/g/h"
    

    17、命令stat:显示文件或文件系统的状态

    [root@localhost ~]# ls
    a anaconda-ks.cfg c
    [root@localhost ~]# stat a
      文件:"a"
      大小:33 块:0 IO 块:4096 目录
    设备:fd00h/64768d	Inode:50840617 硬链接:5
    权限:(0755/drwxr-xr-x) Uid:( 0/ root) Gid:( 0/ root)
    环境:unconfined_u:object_r:admin_home_t:s0
    最近访问:2019-09-07 14:01:17.832936441 +0800
    最近更改:2019-09-07 21:56:14.909569316 +0800
    最近改动:2019-09-07 21:56:14.909569316 +0800
    创建时间:-
    

    18、命令rm:删除文件

    -r:递归删除,删除目录时必须使用此选项
    -f:强制删除,不询问

    [root@localhost ~]# ls
    a anaconda-ks.cfg c
    [root@localhost ~]# rm -rf a
    [root@localhost ~]# ls
    anaconda-ks.cfg c
    

    19、命令touch:创建空文件或更新时间戳

    [root@localhost ~]# touch abc
    [root@localhost ~]# ls
    a abc anaconda-ks.cfg b.sql c c.sql d d.sql
    

    20、命令mv:移动文件

    [root@localhost ~]# ls
    a abc anaconda-ks.cfg b.sql c c.sql d d.sql
    [root@localhost ~]# mv b.sql c.sql 
    mv:是否覆盖"c.sql"? y
    [root@localhost ~]# ls
    a abc anaconda-ks.cfg c c.sql d d.sql
    [root@localhost ~]# mv c.sql a/
    [root@localhost ~]# ls
    a abc anaconda-ks.cfg c d d.sql
    [root@localhost ~]# la a
    -bash: la: 未找到命令
    [root@localhost ~]# ls a
    c.sql
    
  • 相关阅读:
    很多人都没用过的轻量级Oracle数据库数据导出工具SQLLDR2——性能超赞
    IT人员必备linux安全运维之Ssh用途、安全性、身份认证以及配置……【转】
    ps aux排序
    Oracle-AWR报告简介及如何生成【转】
    MySQL删除数据几种情况以及是否释放磁盘空间【转】
    MySQL登录问题1045 (28000)处理步骤【原创】
    nginx与PHP的关系和交互方式【转】
    MySQL常见错误代码说明
    xargs -i 和-I 的区别【转】
    linux中的计算【转】
  • 原文地址:https://www.cnblogs.com/liping0826/p/11527774.html
Copyright © 2011-2022 走看看