• Linux基本命令(一)


    Linux的命令(一) - 基本命令

    目录及文件操作

    pwd

    描述:显示当前工作目录的名称
    选项:

    • -p 显示链接的真实路径
    gene@gene-virtual-machine:~$ pwd
    /home/gene
    

    cd

    描述:切换当前工作目录
    选项:

    • . 当前目录
    • .. 返回上一级目录
    • - 返回上一级目录
    gene@gene-virtual-machine:~$ cd /usr/src        # 切换工作目录到/usr/src
    gene@gene-virtual-machine:/usr/src$ cd ..       # 返回到上一级目录
    gene@gene-virtual-machine:/usr$ cd -            # 显示当前目录
    /usr/src
    gene@gene-virtual-machine:/usr/src$ cd          # 返回home目录
    gene@gene-virtual-machine:~$ pwd
    /home/gene
    

    ls

    描述:显示目录与文件信息
    选项:

    • -a(--all) 显示所有,包括隐藏的文件与目录
    • -d(--directory) 显示目录本身的信息,而非文件下的文档信息
    • -h(--human-readable) 人性化显示容量信息,如(e.g., 1K 234M 2G)
    • -l 长格式显示文档的详细信息
    • -u 显示文件或目录最后访问的时间
    • -t 以修改时间排序
    gene@gene-virtual-machine:~$ ls -lu /etc/passwd
    -rw-r--r-- 1 root root 2287 12月 15 08:01 /etc/passwd
    gene@gene-virtual-machine:~$ ls -lhu /etc/passwd
    -rw-r--r-- 1 root root 2.3K 12月 15 08:01 /etc/passwd
    gene@gene-virtual-machine:~$ ls -lt
    total 244
    drwxrwxr-x 2 gene gene   4096 12月 14 15:44 test
    -rw-rw-r-- 1 gene gene     46 12月 14 12:09 test.txt
    -rw-rw-r-- 1 gene gene    101 12月 14 12:03 sample.txt
    -rw-rw-r-- 1 gene gene    365 12月 14 11:35 phonenumber.txt
    -rw-rw-r-- 1 gene gene  17920 12月 14 08:42 usr-bin-list.txt
    -rw-rw-r-- 1 gene gene   2534 12月 14 08:42 usr-sbin-list.txt
    -rw-rw-r-- 1 gene gene   1814 12月 14 08:42 sbin-list.txt
    -rw-rw-r-- 1 gene gene   1242 12月 14 08:40 bin-list.txt
    -rw-rw-r-- 1 gene gene     92 12月 14 07:50 test.py
    -rw-rw-r-- 1 gene gene  17920 12月 12 15:29 ls.txt
    -rw-rw-r-- 1 gene gene 110907 12月 12 15:28 ls-output.txt
    -rw-rw-r-- 1 gene gene      5 12月 12 15:23 lazy_dog.txt
    -rw-rw-r-- 1 gene gene     56 12月 12 15:18 ls-error.txt
    drwxrwxr-x 4 gene gene   4096 12月 12 15:08 playground
    drwxrwxr-x 2 gene gene   4096 12月  7 15:35 data
    drwxr-xr-x 3 gene gene   4096 12月  6 19:26 Desktop
    drwxr-xr-x 2 gene gene   4096 12月  6 19:20 Documents
    drwxr-xr-x 2 gene gene   4096 12月  6 19:20 Downloads
    drwxr-xr-x 2 gene gene   4096 12月  6 19:20 Music
    drwxr-xr-x 2 gene gene   4096 12月  6 19:20 Pictures
    drwxr-xr-x 2 gene gene   4096 12月  6 19:20 Public
    drwxr-xr-x 2 gene gene   4096 12月  6 19:20 Templates
    drwxr-xr-x 2 gene gene   4096 12月  6 19:20 Videos
    -rw-r--r-- 1 gene gene   8980 12月  6 19:13 examples.desktop
    

    touch

    描述:创建或修改文件时间

    gene@gene-virtual-machine:~$ touch hello.txt
    
    gene@gene-virtual-machine:~$ ls -lt hello.txt 
    -rw-rw-r-- 1 gene gene 0 12月 15 08:20 hello.txt
    

    如果hello.txt不存在,就创建;如果存在,则更新文件的时间为当前系统时间

    mkdir

    描述:创建目录
    选项:

    • -p 创建多级目录
    gene@gene-virtual-machine:~$ mkdir hello
    gene@gene-virtual-machine:~$ ls -d hello
    hello
    

    cp

    描述:复制文件与目录

    用法: cp [options] source destination

    选项:

      • r 递归复制目录
      • a 复制时候,保留源文档的所有属性
    gene@gene-virtual-machine:/tmp$ cp /etc/hosts /tmp
    gene@gene-virtual-machine:/tmp$ cp -r /var/log /tmp
    gene@gene-virtual-machine:/tmp$ cp -a /etc/passwd /tmp
    gene@gene-virtual-machine:/tmp$ ls /tmp
    
    gene@gene-virtual-machine:/tmp$ ls /tmp
    _cafenv-appconfig_
    config-err-fyIANa
    gnome-software-LYMQBZ
    hosts
    log
    passwd
    

    rm

    描述:删除文件或者目录

    用法:rm [options] files

    选项:

    • -f 不提示,强制删除
    • -i 删除前,提示是否删除
    • -r 递归删除,删除目录以及目录下的所有内容
    gene@gene-virtual-machine:/tmp$ touch readme.md
    gene@gene-virtual-machine:/tmp$ rm readme.md
    

    mv

    描述:移动或者重命名文件

    gene@gene-virtual-machine:/tmp$ mv readme.txt readme_rename.txt
    gene@gene-virtual-machine:/tmp$ mv readme_rename.txt ~/home
    
    

    find

    描述: 搜索文件或目录

    用法:find [options] [starting-points] [expression]

    选项:

    • -empty 查找空白文件或目录
    • -group 按组查找
    • -name 按文档名称查找
    • -inmae 按文档名称查找并且不区分大小写
    • -mtime 按修改时间查找
    • -size 按容量大小查找
    • -type 按文件类型查找,file(f),directory(d), device(b, c), link(l) 等
    • -user 按用户查找
    • -exec 对找到的文件,执行特定的命令
    • -a and,并
    • -o or,或
    gene@gene-virtual-machine:~$ find ./ -size +1M -exec ls -l {} ;     # 查找大于1MB的文件后列出文件的详细信息
    gene@gene-virtual-machine:~$ find  -name readme.txt                  # 查找当前文件下,名字是readme.txt的文件
    gene@gene-virtual-machine:~$ find / -name readme.txt                 # 查找当前计算机中所有readme.txt文件
    

    locate

    xargs

    du

    描述: 计算文件或者目录的容量

    用法: du [options] [file or directory]

    选项:

    • -h 人性化显示容量信息
    • -a 查看所有目录以及文件的容量信息
    • -s 仅显示总容量
    gene@gene-virtual-machine:~$ du /home           # 查看home目录及其子目录的容量信息
    gene@gene-virtual-machine:~$ du -sh /home       # 查看home目录所占的总空间
    181M	/home
    

    文件查看及处理

    cat

    查看文件内容,并可以编辑文件内容

    箭头朝向,数据朝哪留,必须

    print后面的信息

    • 打印信息
    echo "123"
    
    • 打印信息并使用重定向到指定文件,覆盖初始内容
    echo "123" > o.txt
    
    • 打印信息并使用重定向到指定文件,不覆盖,直接放在结尾
    echo "123" >> o.txt
    
    

    常用的快捷键

    • tab:自动补全
    • ctrl-d:退出当前的用户命令
  • 相关阅读:
    对称加密与非对称加密
    mysql 数据库备份
    Linux安装VM虚拟机
    Ubuntu安装桌面
    POM 总是提示找不到依赖
    Wine解决界面乱码
    There was an unexpected error (type=Not Found, status=404). /WEB-INF/views/login.jsp
    Linux打开chm文件
    vim 查找模式
    spring总结(02)注解
  • 原文地址:https://www.cnblogs.com/Tcorner/p/12896166.html
Copyright © 2020-2023  润新知