101 Ubuntu

作者: z嘉嘉嘉 | 来源:发表于2016-12-10 14:30 被阅读14次

    思沃学院第一期学习任务 101 总结

    Ubuntu历史

    Ubuntu是世界最受欢迎完全开源的操作系统之一
    详细描述 : ubuntu维基百科

    快捷键学习

    常用快捷键

    Ctrl+Alt+F1:进入终端界面。
    Ctrl+Alt+F7:回到图形界面。
    Ctrl+Alt+T:进入伪终端,当然我们的大部分操作只需要在伪终端下操作即可。
    Ctrl+D:关闭伪终端。
    Ctrl+Alt+L:锁屏。

    终端常用快捷键

    Shift+Pageup/Page down:向上向下翻页
    Tab:命令补全功能
    Ctrl+Shift+c:复制
    Ctrl+Shift+v:粘贴
    Ctrl+a:移动到当前行开始位置
    Ctrl+e:移动到当前行结尾
    Ctrl+k:删除此处至末尾所有内容
    Ctrl+u:删除此处至开始所有内容
    Ctrl+l:刷新屏幕
    Ctrl+c:杀死当前任务
    Ctrl+s:挂起当前shell
    Ctrl+q:重新启用挂起的shell
    Alt+u:把当前词转化为大写
    Alt+l:把当前词转化为小写
    Alt+c:把当前词变成首字母大写
    [参考]:文/TW安洋(简书作者)

    常用命令学习

    • ls - List
      ls列出当前工作目录内容
    ➜  ~ ls
    Book       examples.desktop    Music           Public            wince3+1
    Desktop    gradle-2.9-bin.zip  newRamlProject  Templates
    Documents  IdeaProjects        pdf             Videos
    Downloads  logs                Pictures        WebstormProjects
    
    • mkdir - Make Directory
      mkdir <new-directory-name> 创建一个新的文件夹
    ➜  ~ mkdir newDir
    ➜  ~ ls
    Book       examples.desktop    Music           Public            wince3+1
    Desktop    gradle-2.9-bin.zip  newRamlProject  Templates           newDir
    Documents  IdeaProjects        pdf             Videos
    Downloads  logs                Pictures        WebstormProjects
    
    
    • pwd – Print Working Directory
      pwd 显示当前工作目录
    ➜  ~ pwd
    /home/zhyingjia
    
    
    • cd – Change Directory
      cd <directory-name>进入某一文件目录
    ➜  ~ cd newDir 
    ➜  newDir pwd
    /home/zhyingjia/newDir
    
    
    • rmdir – Remove Directory
      rmdir <directory-name>删除给定的目录
    ➜  ~ rmdir newDir 
    ➜  ~ ls
    Book       examples.desktop    Music           Public            wince3+1
    Desktop    gradle-2.9-bin.zip  newRamlProject  Templates
    Documents  IdeaProjects        pdf             Videos
    Downloads  logs                Pictures        WebstormProjects
    
    • rm – Remove
      rm <file-name>删除给定的文件或文件夹
      rm -r <directory-name>递归删除文件夹
    ➜  newDir mkdir content
    ➜  newDir ls
    content
    ➜  newDir cd ../
    ➜  ~ rmdir newDir 
    rmdir: failed to remove 'newDir': Directory not empty
    ➜  ~ rm newDir 
    rm: cannot remove 'newDir': Is a directory
    ➜  ~ rm -r newDir 
    ➜  ~ ls
    Book       examples.desktop    Music           Public            wince3+1
    Desktop    gradle-2.9-bin.zip  newRamlProject  Templates
    Documents  IdeaProjects        pdf             Videos
    Downloads  logs                Pictures        WebstormProjects
    
    
    • cp – Copy
      cp <source-file> <destination-file>对文件进行复制
      cp -r <source-folder> <destination-folder> 对文件夹进行递归复制
    ➜  newDir touch file1.txt
    ➜  newDir ls
    content  file1.txt
    ➜  newDir cp file1.txt file2.txt
    ➜  newDir ls
    content  file1.txt  file2.txt
    
    ➜  newDir ls
    content  file1.txt  file2.txt
    ➜  newDir cp file2.txt content 
    ➜  newDir ls
    content  file1.txt  file2.txt
    ➜  newDir cd content 
    ➜  content ls
    file2.txt
    
    • mv – MoVe
      mv <source> <destination> 对文件或文件夹进行移动 / 重命名
    ➜  newDir ls
    content  file2.txt
    ➜  newDir cd content 
    ➜  content ls
    ➜  content cd ../
    
    //  重命名
    ➜  newDir mv file2.txt file.txt
    ➜  newDir ls
    content  file.txt
    
    //  移动
    ➜  newDir mv file.txt content 
    ➜  newDir ls
    content
    ➜  newDir cd content 
    ➜  content ls
    file.txt
    
    • cat – concatenate and print files
      cat <file>用于在标准输出(监控器或屏幕)上查看文件内容
      Shift + PgUp 向上翻页
      Shift + PgDn 向下翻页
    ➜  content ls            
    file.txt
    ➜  content cat file.txt 
    0 file test data
    1 file test data
    2 file test data
    3 file test data
    4 file test data
    5 file test data
    6 file test data
    7 file test data
    8 file test data
    9 file test data
    10 file test data
    11 file test data
    12 file test data
    13 file test data
    
    
    
    • 10.tail – print TAIL (from last) >
      tail <file-name>默认在标准输出上显示给定文件的最后10行内容
      tail -n N <file-name>指定在标准输出上显示文件的最后N行内容
    ➜  content tail file.txt 
    4 file test data
    5 file test data
    6 file test data
    7 file test data
    8 file test data
    9 file test data
    10 file test data
    11 file test data
    12 file test data
    13 file test data
    ➜  content tail file.txt -n 3
    11 file test data
    12 file test data
    13 file test data
    
    
    • less – print LESS
      less <file-name>按页或按窗口打印文件内容。在查看包含大量文本数据的大文件时是非常有用和高效的。
      Ctrl+F向前翻页
      Ctrl+B向后翻页

    • grep
      grep "<string>" <file-name>在给定的文件中搜寻指定的字符串
      grep -i "<string>" <file-name>在搜寻时会忽略字符串的大小写
      grep -r "<string>" <file-name>在当前工作目录的文件中递归搜寻指定的字符串

    ➜  ~ grep "1 f" newDir/content/file.txt
    1 file test data
    11 file test data
    
    ➜  ~ grep "0 File" newDir/content/file.txt
    
    ➜  ~ grep "0 File" -i newDir/content/file.txt
    0 file test data
    10 file test data
    ➜  ~ cd newDir 
    
    ➜  newDir grep "0 File" -i -r 
    content/file.txt:0 file test data
    content/file.txt:10 file test data
    
    • Find
      find <folder-to-search> -name <file-name>在给定位置搜寻与条件匹配的文件(区分大小写)
      find <folder-to-search> -iname <file-name>在给定位置搜寻与条件匹配的文件(不区分大小写)
    ➜  ~ find newDir -name content
    newDir/content
    ➜  ~ find newDir -iname Content
    newDir/content
    
    
    • tar(打包)
      tar -cvf <archive-name.tar> <file1-OR-file2-OR-both-to-archive>打包对应文件/目录
      tar -tvf <archive-to-view.tar>来查看打包文件的内容
      tar -xvf <archive-to-extract.tar>来提取对应打包文件内容
    ➜  newDir ls
    content
    ➜  newDir tar -cvf content.tar content 
    content/
    content/file.txt
    ➜  newDir ls
    content  content.tar
    
    ➜  newDir tar -tvf content.tar
    drwxrwxr-x zhyingjia/zhyingjia 0 2016-12-09 22:22 content/
    -rw-rw-r-- zhyingjia/zhyingjia 242 2016-12-09 22:22 content/file.txt
    
    ➜  newDir rm -rf content
    ➜  newDir ls
    content.tar
    ➜  newDir tar -xvf content.tar 
    content/
    content/file.txt
    ➜  newDir ls
    content  content.tar
    
    • gzip(压缩)
      gzip <filename>创建压缩文件
      gzip -d <filename>提取压缩文件
    ➜  content ls
    file.txt
    ➜  content gzip file.txt 
    ➜  content ls
    file.txt.gz
    ➜  content gzip -d file.txt.gz 
    ➜  content ls
    file.txt
    
    
    • zip(压缩)
      zip archive-name.zip filename 压缩一个文件
      zip -r archive-name.zip directory-name递归压缩一个目录
    ➜  content zip file.zip file.txt 
      adding: file.txt (deflated 100%)
    ➜  content ls
    file.txt  file.zip
    ➜  content cd ../
    ➜  newDir ls
    content
    ➜  newDir zip -r content.zip content 
      adding: content/ (stored 0%)
      adding: content/file.zip (stored 0%)
      adding: content/file.txt (deflated 100%)
    ➜  newDir ls
    content  content.zip
    
    • unzip(解压缩)
      unzip <archive-to-extract.zip>对.zip文档进行解压
      在解压之前,可以使用unzip -l <archive-to-extract.zip>
      命令查看文件内容
    // 因为解压的时候会有命名冲突,因此将content.zip移动到content下进行操作
    ➜  newDir mv content.zip content/
    ➜  newDir ls
    content
    ➜  newDir cd content 
    ➜  content ls
    content.zip  file.txt  file.zip
    ➜  content unzip -l content.zip 
    Archive:  content.zip
      Length      Date    Time    Name
    ---------  ---------- -----   ----
            0  2016-12-10 13:20   content/
          193  2016-12-10 13:20   content/file.zip
        10240  2016-12-10 13:05   content/file.txt
    ---------                     -------
        10433                     3 files
    ➜  content unzip content.zip 
    Archive:  content.zip
       creating: content/
     extracting: content/file.zip        
      inflating: content/file.txt        
    ➜  content ls
    content  content.zip  file.txt  file.zip
    
    
    • help
      help会在终端列出所有可用的命令
      <command-name> --help查看该命令的具体用法
    ➜  ~ bash
    zhyingjia@zhyingjia-Inspiron-5437:~$ help
    GNU bash, version 4.3.46(1)-release (x86_64-pc-linux-gnu)
    These shell commands are defined internally.  Type `help' to see this list.
    Type `help name' to find out more about the function `name'.
    Use `info bash' to find out more about the shell in general.
    Use `man -k' or `info' to find out more about commands not in this list.
    
    A star (*) next to a name means that the command is disabled.
    
     job_spec [&]                                                           history [-c] [-d offset] [n] or history -anrw [filename] or history>
     (( expression ))                                                       if COMMANDS; then COMMANDS; [ elif COMMANDS; then COMMANDS; ]... [ >
    ... ...
    
    zhyingjia@zhyingjia-Inspiron-5437:~$ ls --help
    Usage: ls [OPTION]... [FILE]...
    List information about the FILEs (the current directory by default).
    Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.
    
    Mandatory arguments to long options are mandatory for short options too.
      -a, --all                  do not ignore entries starting with .
      -A, --almost-all           do not list implied . and ..
          --author               with -l, print the author of each file
      -b, --escape               print C-style escapes for nongraphic characters
          --block-size=SIZE      scale sizes by SIZE before printing them; e.g.,
                                   '--block-size=M' prints sizes in units of
    ... ... 
    
    zhyingjia@zhyingjia-Inspiron-5437:~$ zsh
    ➜  ~ ls --help
    Usage: ls [OPTION]... [FILE]...
    List information about the FILEs (the current directory by default).
    Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.
    
    Mandatory arguments to long options are mandatory for short options too.
      -a, --all                  do not ignore entries starting with .
      -A, --almost-all           do not list implied . and ..
          --author               with -l, print the author of each file
      -b, --escape               print C-style escapes for nongraphic characters
          --block-size=SIZE      scale sizes by SIZE before printing them; e.g.,
    ... ...
    
    
    • whatis – What is this command
      whatis <command-name>会用单行来描述给定的命令。
    ➜  ~ whatis ls
    ls (1)               - list directory contents
    ➜  ~ whatis man
    man (7)              - macros to format man pages
    man (1)              - an interface to the on-line reference manuals
    
    
    • man – Manual
      man <command-name>会为给定的命令显示一个手册页面
    LS(1)                                                          User Commands                                                          LS(1)
    
    NAME
           ls - list directory contents
    
    SYNOPSIS
           ls [OPTION]... [FILE]...
    
    DESCRIPTION
           List information about the FILEs (the current directory by default).  Sort entries alphabetically if none of -cftuvSUX nor --sort is
           specified.
    
           Mandatory arguments to long options are mandatory for short options too.
    
           -a, --all
                  do not ignore entries starting with .
    
           -A, --almost-all
                  do not list implied . and ..
    ... ... 
    
    • exit
      exit用于结束当前的终端会话 : 即关闭当前终端
      Ctrl+D退出当前终端

    • ping
      ping <remote-host-address>通过发送数据包ping远程主机(服务器),常用与检测网络连接和服务器状态。

    ➜  ~ ping www.jianshu.com
    PING www.jianshu.com (106.75.2.241) 56(84) bytes of data.
    64 bytes from 106.75.2.241: icmp_seq=1 ttl=50 time=20.1 ms
    64 bytes from 106.75.2.241: icmp_seq=2 ttl=50 time=20.4 ms
    64 bytes from 106.75.2.241: icmp_seq=3 ttl=50 time=19.9 ms
    64 bytes from 106.75.2.241: icmp_seq=4 ttl=50 time=19.7 ms
    64 bytes from 106.75.2.241: icmp_seq=5 ttl=50 time=22.7 ms
    64 bytes from 106.75.2.241: icmp_seq=6 ttl=50 time=19.8 ms
    
    
    • who – Who Is logged in
      who列出当前登录的用户名
    ➜  ~ who
    zhyingjia tty7         2016-12-10 12:28 (:0)
    zhyingjia tty2         2016-12-10 13:44
    
    • su – Switch User
      su <username>用于切换不同的用户
      即使没有使用密码,超级用户也能切换到其它用户
    ➜  ~ su user1
    Password: 
    user1@zhyingjia-Inspiron-5437:/home/zhyingjia$ 
    
    • How to create a user?
    ➜  ~ sudo useradd user1      // 使用管理员权限,创建一个用户: sudo useradd <username>
    
    ➜  ~ sudo passwd user1       // 使用管理员权限,修改用户密码 sudo passwd <username>
    Enter new UNIX password: 
    Retype new UNIX password: 
    passwd: password updated successfully
    
    ➜  ~ cd ../                            // 在home目录下使用管理员创建对应工作目录sudo  mkdir <username>
    ➜  /home ls
    zhyingjia
    ➜  /home sudo mkdir user1
    ➜  /home ls
    user1  zhyingjia
    
    创建成功
    
    ➜  /home cd                        // 切换用户 su <username>
    ➜  ~ su user1
    Password: 
    user1@zhyingjia-Inspiron-5437:/home/zhyingjia$ 
    
    • How to delete a user?
    Ctrl + D 退出当前 user1 用户终端
    Ctrl + T 打开新终端
    
    ➜  ~ sudo userdel user1                 // 使用管理员权限删除指定用户 sudo userdel <username>
    [sudo] password for zhyingjia: 
    
    ➜  ~ cd ../                                        // 回到home目录下,使用管理员权限,删除对应用户目录  sudo rm -rf <delusername>
    ➜  /home ls
    user1  zhyingjia
    ➜  /home sudo rm -rf user1
    ➜  /home ls
    zhyingjia
    ➜  /home 
    
    删除完成
    
    • uname
      uname显示出关于系统的重要信息,如内核名称、主机名、内核版本、处理机类型等等
      uname -a可以查看所有信息
    ➜  ~ uname
    Linux
    ➜  ~ uname -a
    Linux zhyingjia-Inspiron-5437 4.4.0-47-generic #68-Ubuntu SMP Wed Oct 26 19:39:52 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
    
    • free – Free memory
      free 显示出系统的空闲内存、已经占用内存、可利用的交换内存等信息
      free -m 将结果中的单位转换成KB
      free –g 则转换成GB
    ➜  ~ free
                  total        used        free      shared  buff/cache   available
    Mem:        8077760     1424756     4778536      314972     1874468     6018344
    Swap:             0           0           0
    ➜  ~ free -m
                  total        used        free      shared  buff/cache   available
    Mem:           7888        1391        4667         306        1829        5877
    Swap:             0           0           0
    ➜  ~ free -g
                  total        used        free      shared  buff/cache   available
    Mem:              7           1           4           0           1           5
    Swap:             0           0        
    
    
    • df – Disk space Free
      df查看文件系统中磁盘的使用情况 : 硬盘已用、可用的存储空间以及其它存储设备
      df -h将结果以人类可读的方式显示
    ➜  ~ df
    Filesystem     1K-blocks     Used Available Use% Mounted on
    udev             4018760        0   4018760   0% /dev
    tmpfs             807776     9732    798044   2% /run
    /dev/sda1      144103744 27505216 109255224  21% /
    tmpfs            4038880    20352   4018528   1% /dev/shm
    tmpfs               5120        4      5116   1% /run/lock
    tmpfs            4038880        0   4038880   0% /sys/fs/cgroup
    tmpfs             807776       56    807720   1% /run/user/1000
    ➜  ~ df -h
    Filesystem      Size  Used Avail Use% Mounted on
    udev            3.9G     0  3.9G   0% /dev
    tmpfs           789M  9.6M  780M   2% /run
    /dev/sda1       138G   27G  105G  21% /
    tmpfs           3.9G   20M  3.9G   1% /dev/shm
    tmpfs           5.0M  4.0K  5.0M   1% /run/lock
    tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
    tmpfs           789M   56K  789M   1% /run/user/1000
    
    • ps – ProcesseS
      ps 显示系统的运行进程
    ➜  ~ ps
      PID TTY          TIME CMD
     9065 pts/4    00:00:00 zsh
     9902 pts/4    00:00:00 zsh
    10422 pts/4    00:00:00 ps
    
    • Top – TOP processes
      top 命令会默认按照CPU的占用情况,显示占用量较大的进程
      top -u <username> 查看某个用户的CPU使用排名情况
    ➜  ~ top
    
    top - 14:08:07 up  2:15,  2 users,  load average: 0.08, 0.14, 0.12
    Tasks: 242 total,   1 running, 241 sleeping,   0 stopped,   0 zombie
    %Cpu(s):  1.7 us,  0.9 sy,  0.0 ni, 97.2 id,  0.2 wa,  0.0 hi,  0.0 si,  0.0 st
    KiB Mem :  8077760 total,  4771916 free,  1435888 used,  1869956 buff/cache
    KiB Swap:        0 total,        0 free,        0 used.  6011856 avail Mem 
    
      PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND     
      934 root      20   0  377124  55856  41004 S   5.0  0.7   1:52.05 Xorg        
     9060 zhyingj+  20   0  588396  34860  27780 S   2.3  0.4   0:02.54 gnome-term+ 
     1885 zhyingj+  20   0 1542564 156032  73488 S   2.0  1.9   2:01.80 compiz      
     2528 zhyingj+  20   0  500092 122060  70992 S   0.3  1.5   1:38.04 chrome      
     4519 root      20   0       0      0      0 S   0.3  0.0   0:01.87 kworker/u8+ 
    10460 zhyingj+  20   0   48976   4240   3540 R   0.3  0.1   0:00.01 top         
        1 root      20   0  185488   6124   3984 S   0.0  0.1   0:01.63 systemd     
        2 root      20   0       0      0      0 S   0.0  0.0   0:00.00 kthreadd    
        3 root      20   0       0      0      0 S   0.0  0.0   0:00.04 ksoftirqd/0 
        5 root       0 -20       0      0      0 S   0.0  0.0   0:00.00 kworker/0:+ 
        7 root      20   0       0      0      0 S   0.0  0.0   0:05.16 rcu_sched  
    ... ...
    
    • shutdown
      shutdown 用于关闭计算机
      shutdown -r 用于重启计算机

    [参考]:29个你必须知道的Linux命令

    总结 + 感受

    • 快捷键比较方便,好好练习使用快捷键
    • 基本命令需要掌握参数含义
    • 有时间应该多了解一下Ubuntu操作系统吧 _

    参考

    • 参考出处已注明

    学习资料

    相关文章

      网友评论

      • 6d96978eeefb:很好,平时记着要多用,没事的时候过来查一查👍

      本文标题:101 Ubuntu

      本文链接:https://www.haomeiwen.com/subject/boqtmttx.html