字符集、特殊符号和通配符

在这里插入图片描述

Linux下面修改字符集

1. 什么是字符集

字符集:文字符号在计算机中标识方法

2.常见字符集
    GBK 国标
    UTF8 万国码
3.修改字符集
        查看
            查看:$LANG (language语言)
            echo $LANG 
                查看字符集
            en_US.UTF-8    \\语言.字符集  英文
            zh_CN.UTF-8
                中文
修改-临时:
            export LANG='zh_CH.UTF-8'
            重新登录之后失效
        修改-永久:
            vim /etc/locale.conf (CentOS 7)
            vim /etc/sysconfig/i18n(CentOS 6)
        生效
            source /etc/locale.conf
            
修改-临时永久同时修改
            localectl 
            修改
                localectl set-locale LANG=en_US.utf-8
            生效
                source /etc/locale.conf                         
查看
        cat /etc/locale.conf 
        一条命令设置字符集
    

修改永久-生效-查看

[✡root@lcx ~]# localectl set-locale LANG=en_US.UTF-8
[✡root@lcx ~]# source /etc/locale.conf 
[✡root@lcx ~]# cat /etc/locale.conf 
LANG=en_US.UTF-8
故障案例-中文乱码排查流程
        原因
            
        排查
            查看xshell字符集
            查看系统字符集
            是否一致↑↑↑
        解决
            方法1
                修改xshell字符集(不通用)
            方法2
                修改Linux字符集

※特殊符号

引号相关
' '   单引号,所见即所得
    echo '$LANG {1..5}'
" "  双引号,解析命令,但是需要与` `或$( )结合
    echo "$LANG {1..5}"
    不加引号
    与双引号类似,支持花括号(通配符)
` `    反引号,==$( )与后者作用相同,与双引号类似解析命令
        echo $LANG {1..5}
        优先执行里面的命令
重定向符号

含义
改变数据流向
箭头的方向就是水流方向

    >或1>
                标准输出重定向
                先清空文件内容再写入
    >>或1>>
                标准输出追加重定向
                追加内容到文件尾部
    2>
                标准错误输出重定向
                先清空文件然后把错误信息写入文件中
    2>>
                标准追加错误输出重定向
                把错误信息追加到文件结尾
    2>&1
                同时把错误信息或正确信息都记录到文件中
                alex >>lcx.txt  2>>lcx.txt
    < 或者0<
                标准输入重定向
                用来指引命令从哪里读取数据
                用到小于号的命令 tr  xargs
    << 或者0<<
                标准追加输入重定向
                只用来和cat配合 向文件中追加多行内容
    cat >>lcx.txt<<EOF
    
标准输出 数字1    把正确信息写入文件中
错误输出 数字2  命令的错误提示写入到文件,定向任务会用到
 数字0 用于和特定命令配合

我们看一下2>&1↓↓↓↓↓↓

[✡root@lcx /tmp]# alex   >>lcx.txt    2>&1
[✡root@lcx /tmp]# echo alex lcx  >>lcx.txt    2>&1
[✡root@lcx /tmp]# cat lcx.txt 
-bash: alex: command not found
alex lcx

| 管道符

含义
把前一个命令的结果通过管道传递给后面命令
管道默认传递的是文字符号

find和|xargs配合 
                |xargs 把管道传递的内容从文字符号---->文件名(参数)
                |xargs 后面不支持别名
例子
                find后的 -exec
                把前面的命令依次执行到后面的命令中
找出/lcx下以.txt结尾的文件并把他们显示(ls -l)
    方法一:反引号
            ls -l `find /lcx/ -type f -name '*.txt'`
    方法二:管道
            find /lcx/ -type f -name '*.txt'|xargs ls -l
    方法三: -exec
            find lcx/ -type f -name '*.txt' -exec ls -l {} \;

测试 --创建环境(三种方法)

找出/lcx下面以.txt结尾的文件把他们显示(ls -l)

创建环境 
mkdir -p /lcx/lidao 
touch /lcx/lcx{01..5}.txt  /lcx/lidao/alex{01..5}.txt 

1.反引号

[✡root@lcx ~]# ls -l $(find lcx -type f -name '*.txt')
-rw-r--r-- 1 root root 0 Apr 16 11:00 lcx/lidao/alex01.txt
-rw-r--r-- 1 root root 0 Apr 16 11:00 lcx/lidao/alex02.txt
-rw-r--r-- 1 root root 0 Apr 16 11:00 lcx/lidao/alex03.txt
-rw-r--r-- 1 root root 0 Apr 16 11:00 lcx/lidao/alex04.txt
-rw-r--r-- 1 root root 0 Apr 16 11:00 lcx/lidao/alex05.txt
-rw-r--r-- 1 root root 0 Apr 16 11:00 lcx/lcx01.txt
-rw-r--r-- 1 root root 0 Apr 16 11:00 lcx/lcx02.txt
-rw-r--r-- 1 root root 0 Apr 16 11:00 lcx/lcx03.txt
-rw-r--r-- 1 root root 0 Apr 16 11:00 lcx/lcx04.txt
-rw-r--r-- 1 root root 0 Apr 16 11:00 lcx/lcx05.txt

2.管道

[?root@lcx ~]# find lcx/ -type f -name '*.txt'|xargs ls -l
-rw-r--r-- 1 root root 0 Apr 16 11:00 lcx/lidao/alex01.txt
-rw-r--r-- 1 root root 0 Apr 16 11:00 lcx/lidao/alex02.txt
-rw-r--r-- 1 root root 0 Apr 16 11:00 lcx/lidao/alex03.txt
-rw-r--r-- 1 root root 0 Apr 16 11:00 lcx/lidao/alex04.txt
-rw-r--r-- 1 root root 0 Apr 16 11:00 lcx/lidao/alex05.txt
-rw-r--r-- 1 root root 0 Apr 16 11:00 lcx/lcx01.txt
-rw-r--r-- 1 root root 0 Apr 16 11:00 lcx/lcx02.txt
-rw-r--r-- 1 root root 0 Apr 16 11:00 lcx/lcx03.txt
-rw-r--r-- 1 root root 0 Apr 16 11:00 lcx/lcx04.txt
-rw-r--r-- 1 root root 0 Apr 16 11:00 lcx/lcx05.txt

如果管道后不加xargs的话
[✡root@lcx ~]# find lcx/ -type f -name '*.txt'|ls -l
total 36
-rw-------.  1 root root 1505 Mar 26 14:05 anaconda-ks.cfg
-rw-r--r--   1 root root  686 Mar 28 19:05 bashrc
-rw-r--r--   1 root root 2523 Apr 15 11:54 Centos-7_(1).repo
drwxr-xr-x   3 root root   18 Apr  6 19:20 data
-rw-r--r--   1 root root  712 Apr  7 22:59 day08vim
drwxr-xr-x  81 root root 8192 Apr 10 12:31 etc
drwxr-xr-x   3 root root  119 Apr 16 11:00 lcx
-rw-r--r--   1 root root   10 Apr 16 10:33 lcx.txt
-rw-r--r--   1 root root  970 Apr  4 16:13 passwd.bak

3.-exec

[✡root@lcx ~]# find lcx/ -type f -name '*.txt' -exec ls -l {} \;
-rw-r--r-- 1 root root 0 Apr 16 11:00 lcx/lidao/alex01.txt
-rw-r--r-- 1 root root 0 Apr 16 11:00 lcx/lidao/alex02.txt
-rw-r--r-- 1 root root 0 Apr 16 11:00 lcx/lidao/alex03.txt
-rw-r--r-- 1 root root 0 Apr 16 11:00 lcx/lidao/alex04.txt
-rw-r--r-- 1 root root 0 Apr 16 11:00 lcx/lidao/alex05.txt
-rw-r--r-- 1 root root 0 Apr 16 11:00 lcx/lcx01.txt
-rw-r--r-- 1 root root 0 Apr 16 11:00 lcx/lcx02.txt
-rw-r--r-- 1 root root 0 Apr 16 11:00 lcx/lcx03.txt
-rw-r--r-- 1 root root 0 Apr 16 11:00 lcx/lcx04.txt
-rw-r--r-- 1 root root 0 Apr 16 11:00 lcx/lcx05.txt
表示位置
    ~   用户的家目录
    ..  当前目录的上级目录
    .   点开头的隐藏文件  一个点当前目录
    -   切换上一次的目录  cd -  su -
表示简单判断
    &&   and 并且,当前一个指令执行成功时,执行后一个指令
    ||   or  或者,当前一个指令执行失败后,执行后一个指令
表示判断
    #   
        配置文件注释
        root用户命令提示符
        
    $  
        变量前需要加的符号
        取变量内容 $LANG $PATH
        
    $( ) ==`` 反引号
    
    ;    
        命令结束,连续不同命令的分隔符
        
    !    
        逻辑运算中的“非”(not)
        
    !ls  
        找出最近一次使用过的以ls开头的命令并执行
        
    history |grep ls
        利用管道筛选历史记录
        

※通配符

    作用
        方便我们查找想要的文件或目录
        通==通用 Linux下面大部分命令可以使用
        *.txt  *.log  *.conf
[✡root@lcx /tmp]# echo A{A,B}
AA AB
[✡root@lcx /tmp]# echo A{,B}
A AB
[✡root@lcx /tmp]# cp lcx.txt lcx.txt {,.bak}
cp: target ‘.备份’ is not a directory
[✡root@lcx /tmp]# cp lcx.txt lcx.txt{,.bak}
cp: target ‘lcx.txt.bak’ is not a directory
[✡root@lcx /tmp]# cp lcx.txt{,.bak}

符号

    *       所有任何
    { }     生成序列 
    ?       代表任意一个单个字符,有几个问号代表几个字符
    [ ]
    [^]

小扩展

题目

未完待续......

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 217,509评论 6 504
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,806评论 3 394
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 163,875评论 0 354
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,441评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,488评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,365评论 1 302
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,190评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,062评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,500评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,706评论 3 335
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,834评论 1 347
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,559评论 5 345
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,167评论 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,779评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,912评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,958评论 2 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,779评论 2 354

推荐阅读更多精彩内容