linux 学习笔记3


man help info baidu ...
ls cd touch rm mkdir rmdir
cp -r
mv
cat tac more less head tail
grep cut uniq sort wc tr

ping showmount mount umount

|

/etc/passwd : 用户帐号信息文件
cat /etc/passwd | cut -d : -f 7 | sort | uniq | grep -v  ^$ | wc -l
======================
linux 操作文件只有两种方式
    1 文件指针       C c++ java php ...
    2 文件描述符    sys API
                                文件指针   文件描述符
    标准输入:键盘 鼠标            stdin        0
    标准输出:显示器 打印机        stdout        1
    错误输出: 显示器 打印机        stderr        2


重定向:
    输出重定向:
        清空重定向:
        > : 正确输出重定向
            案例:
                [root@localhost test]# echo hello
                hello
                [root@localhost test]# echo hello > a.txt
                [root@localhost test]# cat a.txt
                hello
        2> : 错误输出重定向
            案例
                [root@localhost test]# ls /kjhjgf
                ls: /kjhjgf: 没有那个文件或目录
                [root@localhost test]# ls /kjhjgf 2> a.txt

        &> : 表示正确和错误重定向到一个文件中
            案例
                [root@localhost test]# ls / /khjdf &> a.txt
                [root@localhost test]# cat a.txt
                ls: /khjdf: 没有那个文件或目录
                /:
                254_张三
                59_homework
                59_team
                60_homework
                60_team

        追加重定向:
        >> : 正确追加重定向:
            案例:
                [root@localhost test]# echo hello >> a.txt
                [root@localhost test]# echo hello >> a.txt
                [root@localhost test]# echo hello >> a.txt
                [root@localhost test]# cat a.txt
                hello
                hello
                hello
                hello

        黑洞文件:/dev/null
            
                
    输入重定向:
        < : 出入重定向
            案例:
                [root@localhost test]# passwd < a.txt
                Changing password for user root.
                New UNIX password: BAD PASSWORD: it is too simplistic/systematic
                Retype new UNIX password: passwd: all authentication tokens updated successfully.

        << : 表示结束标记
            案例:
                [root@localhost test]# cat << AAA
                > hello world
                > tihs is my test
                > AAA
                hello world
                tihs is my test

================================================
vim : 编辑器 程序开发器
gcc : 编译器


案例:实现C语言开发流程
    1 先创建.c的源文件
        touch hello.c
    2 实现.c功能
        vim hello.c
    3 编译
        gcc hello.c
    4 执行
        [root@localhost test]# ./a.out
        hello world!
    
=============================================
vim :
    三种模式:
        1 一般模式:就是vim直接打开文件模式
        2 编辑模式:就是文件左下角有"插入"字样模式
        3 命令行模式:就是文件左下角有":"字样模式
    
    模式之间切换
        一般模式 => 编辑模式
            i I o O a A s S
        编辑模式 => 命令行模式
            ESC键 => : => wq
========================================
一般模式:
    删除:
        dd    :    删除一行
        u    :    表示撤销上次操作
        ndd    :    表示删除n行

        dw    :    删除一个单词 (字母首位)
        ndw    :    删除n个单词
        daw    :    表示光标在单词任意位置都可以删除
        
        d$    :    表示从光标位置删除到行尾
        d^    :    表示从光标位置删除到行首
        dgg    :    表示删除从光标所在行到文件开头
        dG    :    表示删除从光标所在行到文件结尾

    拷贝:
        yy    :    复制一行
        p    :    表示粘贴
        nyy    :    复制n行
    
    可视化操作
        可视化字符:
            v => 方向键选中 => y  => p
        可视化行:
            shift + v => 方向键 => y => p
        可视化块:
            ctrl + v => 方向键 => y => p
    剪贴:
        dd => p

    移动:
        h    :    左移
        j    :    下移
        k    :    上移
        l    :    右移
    
        ngg    :    表示第n行
        gg    :    表示第一行
        g    :    表示最后一行
        H    :    表示屏幕顶部
        L    :    表示屏幕底部
        M    :    表示屏幕中间
        50% :    表示文件中间

        $    :    表示行尾
        ^    :    表示行首 表示第一个有效字符
        0    :    表示行首 表示第一列
        J    :    表示合并两行
============================================
编辑模式:
    i    :    表示光标前面插入
    I    :    表示行首插入
    o    :    下一行的插入
    O    :    上一行的插入
    a    :    光标后面的插入
    A    :    行尾插入
    s    :    删除光标所在字符插入
    S    :    删除光标所在行的插入

=============================================
命令行模式:
    :w         表示保存
    :q        表示退出
    :wq        表示保存并退出
    :q!        表示强制退出
    :wq!    表示强制保存并退出
        
    另存为
    :w filename : 表示另存为

    :r filename : 表示把filename文件的所有内容读到当前文件中
    
    可以读物外部所有命令
        format :r !cmd

        案例:
            :r !head -n 10 /etc/passwd    表示读取/etc/passwd前面10行
            :r !ls /    表示把所有/目录名保存到当前文件中
            :r !sed -n "5,8p" /etc/passwd    获取/etc/passwd地5行到第8行
    
    临时有效
        显示行号
            :set nu
        取消行号
            :set nonu
    永久有效:
        vim ~/.vimrc

    整体代码偏移:
        shift + v
            左移:shift + <
            右移:shift + >
    
    范文:
        "表示显示行号
        "set number
        set nu
        "表示tab键位宽
        set ts=4
        "表示shift键位宽
        set shiftwidth=4
        "表示跟上一行对齐
        set ai

        "表示设定快捷键
        nmap ,ma i#include <stdio.h><CR><CR>int main(int argc, char *argv[])<CR>{<CR>return 0;<CR>}<ESC>=kko

==========================
分屏显示:
    水平切割:
        :split filename
        vim -o filename1 filename2 ... filenamen

    垂直切割:
        :vsplit filename
        vim -O filename1 filename2 ... filenamen

    文件之间切换
        ctrl + w : 2次
    
    退出所有文件
        :wqa


    鼠标有效:
        :set mouse=a
====================================


        

  • 7
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值