linux学习系列一 顶 原

1. 基本命令(注意参数的大小写)

学习linux如果使用的是windows  建议使用一个很好用的工具git,下载安装即可使用linux下的命令来操作windows

1.1目录及文件

注意/ 有表示根目录 无表示当前目录

    1. pwd 
        pwd    #显示当前工作目录的名称
        pwd -P    #显示连接的真是路径
    2. cd
        cd /usr/src    #切换到/usr/src下面的目录
        cd ..    #返回上级目录
        cd -     #返回上个目录
        cd ~    #返回用户的工作空前目录
    3. ls
        ls    #显示目录和文件信息
        ls -a    #显示所有的信息
        ls -d    #显示目录本身的信息
        ls -h    #人性化显示容量信息
        ls -c    #显示文件或目录属性最后修改的时间
        ls -u    #显示文件或目录最后被访问的时间
        ls -t    #以修改时间排序,默认按照文件名排序
    4. touch
        touch hello.txt    #创建或者修改文件,存在修改,不存在则创建
    5. mkdir
        mkdir test    #创建test目录
        mkdir -p    test/test/test    #创建多级目录
    6. cp
        cp /test/hello.txt /temp/    #将hello.txt文件复制到temp目录下
        cp /test/hello.txt /temp/hi.txt    #将文件复制到目录下并改名字为hi.txt
    7.rm
        rm hello.txt    #删除hello.txt文件
        rm -rf    test    #强制删除目录且不提示
    8. mv
        mv hello.txt hi.txt    #将hello.txt修改名字为hi.txt
        mv hello.txt /test/    #将hello.txt移动至test目录下
    9. find
        find -name hello.txt    #查找当前目录下名为hello.txt的文件
        find /root -name "*.log"    #查找/root目录下所有以.log结尾的文件
        find iname "hello"    #不区分大小写查找
        find / -empty    #查找所有的空文档
        find / -group tom    #查找所属组为tom的文件
        find /-mtime -3    #查找三天内被修改过的档案
        find /-mtime +4    #查找计算机中所有4天前被修改的文档
        find /mtime 2    #查找计算两天前的当天被修改的文档
        find / -size+10M    #查找当前目录下大于10M的文档
        find ./ -type f    #查找当前目录所有的普通文件
        find / -user tom   # 查找计算机中tom所拥有的文档
    10. du
        du -sh /test    #查看test所占的磁盘空间的综合

1.2 查看文件内容

    1. cat
        cat -b hello.txt    #显示hello.txt的内容并显示行号(空白行不显示行号)
        cat -h hello.txt    #显示内容和行号,空白行显示行号
        cat hello.txt    #显示文件内容
    2. more
        more hello.txt    #分页查看文件内容(空格 下一页,q键退出)
    3. less
        less hello.txt    #分页查看文件内容(空格 下一页,方向键 上下回翻,q键 退出)
    4. head
        head -c 2K hello.txt    #显示文件前2K的内容
        head -n20 hello.txt    #显示前20行的内容
    5. tail
        tail -c 2k hello.txt    #显示文件后2K的内容
        tail -n20 hello.txt    #显示文件后20行的内容
        tail -n20 hello.txt -f    #实时动态的显示hello.txt 后20行的内容
    6. wc
        wc hello.txt    #依次显示文件的行数,单词书,字节数
        wc -c hello.txt    #显示文件的字节信息
        wc -l hello.txt    #显示文件的行数
        wc -w hello.txt    #显示文件的单词个数
    7. grep
        grep th hello.txt    #在test.txt文件中过滤包含th的行
        grep --color th hello.txt    #对匹配的关键字显示颜色
        grep -i th hello.txt    #不匹配大小写
        grep -w th hello.txt    #过滤单词,单词为th的
        grep -v th hello.txt    #取反,过滤不好喊th的行
    8.  echo
        echo "test"    #显示test文本
        echo -e "\a"    #计算机蜂鸣器响

1.3 链接文件

有时间可以百度看看软连接和硬链接的区别

    1. 软连接(相当于快捷方式)
        ln -s /test/hello.txt /tmp/hi.txt
    2. 硬链接(可删除源文件)
        ln /test/hello.txt /tem/hi.txt

1.4 压缩及解压缩

    1. gzip 
        gzip hello.txt    #压缩文件,文件压缩后名字为hello.txt.gz
        gzip -d hello.txt.gz    #解压gz文件
    2. bzip2
        bzip2 hello.txt    #压缩文件,文件压缩后名字为 hello.txt.bz2
        bzip2 -d hello.txt.bz2    #解压bz2文件
    3. tar
        tar -cf etc.tar /etc/    #将etc目录打包保存谓etc.tar
        tar -xzf etc.rar    #解压 etc.rar文件

1.5 命令行使用技巧

    1. 善于使用tab键
    2. 善于使用上下键
    3. 查看名两行历史
    4. 清屏
        ctrl+l
        clear
    5. 查找常用命令存储位置
        which find    #查询find命令的存储位置

1.6 帮助

    1. man 
        man ls    #查ls命令手册
    2. info
        info ls    #查看ls命令信息
    3.help
        ls --help    #查看ls帮助
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章