YiHsin Chang
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- tags: Linux --- # Command 所有命令都是由C写出来的可执行程序,运行时不需加./ ## 最高权限(root) :::success Linux的用户里,root为用户管理员,有最高的权限 不建议直接切换到root用户去操作 Ubuntu(其他版本沒有)提供sudo,在任何命令前加sudo表示以root权限操作此命令 ::: ## Linux命令格式 :::success command [-option] parameter1 ... > command:使用的命令 > [-option]:选项,可用来对命令进行控制,[]代表可省 > parameter1:传递命令的参数,可以是零个、一个或多个 ::: ## 查看帮助文档 :::success command --help > 注意:并不是所用命令都有附带--help的选项 ::: :::success man [section number] command > 注意:man包含了几乎所有的命令操作说明,推荐用这个 > 若没输入section number,则默认section number为1,也就是视为命令 > ![](https://i.imgur.com/7FS0Bel.png) > 有时命令和函数会重名,不加section number会是为命令,所以应该养成要加section number的习惯 > 命令 > ![](https://i.imgur.com/y8Pcc9h.png) > 函数 > ![](https://i.imgur.com/QDskj0k.png) > 也可以输入man 1 man来查看man这个命令的使用方法 ::: :::success history > 作用:列出从以前到现在所打过的指令 ::: ## 磁盘管理 :::success [ls [-alrtAFR] [name...]](https://www.runoob.com/linux/linux-comm-ls.html) > 作用:查看当前目录下的信息 > > 参数: >> ls -l:以列表的方式显示 >> ls -a:显示时包含隐藏文件(以「.」开头的文件) >> ls -h:以更人性化的方式显示(原本查看文件的大小是以字节为单位,加了h参数后会以K, M, G, ...来显示) > > 有时ls -ah会被写为ll或ls -ll,大致都相同,但并非完全等价 > 以列表形式列出项目所显示的值的意义 > 目录文件的3代表此文件夹下还有3个文件夹(包含「.」、「..」) > ![](https://i.imgur.com/yK6WPKn.png) > 直接查找文件是否存在,若存在则显示出来(可使用通配符 eg.\*, ?, [A-Z]) > 若档名用了通配符所使用的字(eg. \*.c),则要在\*前加上\\以表示这是档名中的字 > ![](https://i.imgur.com/xF8nzcz.png) ::: :::success [pwd [--help][--version]](https://www.runoob.com/linux/linux-comm-pwd.html) > 作用:显示目前所在的路径 ::: ## 系统管理 :::success [whoami [--help][--version]](https://www.runoob.com/linux/linux-comm-whoami.html) > 作用:显示目前的用户 ::: **查看进程:静态(ps)、动态(top)** :::success 进程:一个在运行的程序 ```cpp= ps -aux //-可不加 // 参数a:显示所有进程,包括其他用户的进程 // 参数u:显示进程的详细状态 // 参数x:显示没有终端控制的进程(像是服务器的进程,不能被关掉) ``` ::: **终止进程(kill)** :::success kill [-signal] ProcessID // signal=9:强制进程终止,用于有些不能终止的进程 ::: ## 文件管理 **重定向**:把terminal显示的东西以档案的形式输出 :::success ls > text.txt > 把ls显示的东西输出到text.txt里(如果text.txt还不存在就新建一个,存在的话覆盖写入) ls >> text.txt > 把ls显示的东西输出到text.txt里(如果text.txt还不存在就新建一个,存在的话**不覆盖**写入) ::: **管道(|)**:左边的是原本要输出的东西 | 右边的是从左边取出后的东西 :::success ls | grep std > grep是用来查找文件的指令 > ls原本会列出所有指令,借由**管道**搭配grep来限定列出的命令(以std为开头的文件) ::: **清屏** :::success 命令:clear 快捷键:Ctrl+l ::: **新建文件夹(mkdir)、删除文件夹(rmdir)、万能删除(rm)** :::success ```cpp= mkdir abc //普通创建文件夹 mkdir ./a/b //在当前目录的下一层a里创建b文件夹(如果a不存在会报错) mkdir ./a/b -p //a不存在的话也会创建a ``` ```cpp= rmdir abc //仅能删除下层没东西的文件夹 rmdir ./a //因为a的下层还有b文件夹,所以无法删除 ``` ```cpp= rm text.txt //删除档案直接删即可 rm ./a -r //加个r参数表示删除的是文件夹,不管下层有没有档案都可以删 rm aaa.c -f //f参数表示不提示任何信息 rm aaa.c -i //会再一次确认是不是要删除 //注意 rm * .png -rf //*和.png中间加了空格表示删除*(所有名称)和.png档案 //所以目录下的档案都会被删除 ``` ::: **建立链接** :::success Linux有分为硬链接、软链接,Windows只有软链接 ```c= // 硬链接: // 没啥用,相当于copy一份文档(链接站空间) // 只是会互相关联(删除其中一个档案,另一个还会在) // 还不能链接文件夹 ln 源文件 链接文件 ``` ```c= // 软链接:链接几乎不占空间,可以链接文件夹(名称后要加/ 来说明是文件夹) ln -s 源文件 链接文件 ``` ::: **查找文件** :::success **grep**: 当前目录查找 ```c= grep [-选项] ‘搜索内容串’文件名 ``` **find**:指定目录和其子目录都找 ```c= find 指定目录 -name 查找文件名 ``` ::: **複製(cp)、移动(mv)** :::success ```c= cp original.txt new.txt cp folder/ newfolder -r //r参数表示是要copy文件夹 ``` ```c= //移动文件夹也不用加r参数 //也可用于改名 mv file ~/path/ mv file ~/path/newname ``` ::: **查看档案类型(find)** :::success 因为在Linux下不太重视后缀,所以Linux提供find命令来查看是什么类型的文件 ```cpp= find 文件名 ``` ::: **查看目录大小(du)** :::success 用ls -l显示的不准确,因为如果遇到文件夹只会计算文件夹本身的大小(不含文件夹里的文件) ```cpp= du ./目录 -h ``` ::: **查看磁盘大小(df)** :::success Linux是没有磁盘的概念的,讲磁盘只是便于理解 ```cpp= df -h //all df ./目录 -h //目录所在处的空间 ``` ::: **打解包(tar)、压缩(gzip, bzip2)** :::success **打包**:仅把档案、文件夹打包成一个.tar档案,不进行压缩 ```cpp= tar -cvf 打包档名.tar 要打包的各个档案或文件夹 tar -cvf pack.tar ./folder/ 1.c 2.c tar -cvf pack.tar * //当前目录下的所有文件 tar -xvf pack.tar //在当前路径解包 tar -xvf pack.tar -C path //指定路径解包 //参数:tar的参数可以不用加-,但是建议加 //c:create,创建包 //x:解包 //v:显示进度条 //f:后面接文档,所以参数一定要放最后 //C:表示要指定路径 ``` **压缩** gzip ```cpp= gzip pack.tar //会生成一个pack.tar.gz在当前路径 gzip -r pack.tar pack.tar.gz //r参数可不加,加了要指定输出名称 gzip -d pack.tar.gz //解压成pack.tar gzip -d pack.tar.gz -C PATH //一步到位(打包+压缩,解包+解压) // 参数z表示调用gzip tar -czvf pack.tar.gz 所需文档 tar -xzvf pack.tar.gz ``` bzip2 ```cpp= bzip2 pack.tar //会生成一个pack.tar.bz2在当前路径 bzip2 -d pack.tar.bz2 //解压成pack.tar //一步到位(打包+压缩,解包+解压) // 参数j表示调用gzip tar -cjvf pack.tar.bz2 所需文档 tar -xjvf pack.tar.bz2 ``` zip, unzip:为了配合windows,Linux很少用zip ```cpp= zip -r pack[.zip] 档案或文件夹 //zip的r参数一定要加,.zip可省,生成后会自动补上 unzip -d PATH pack.zip //PATH一定要写,就算是再当前目录也一样 ``` ::: **查看工具所在的目录(which)** :::success ```cpp= which 工具(ls, gcc, man, ...) ``` ::: :::success [cat [-AbeEnstTuv] [--help] [--version] fileName](https://www.runoob.com/linux/linux-comm-cat.html) > 作用:把所指定的文件内容显示在terminal ::: :::success [chmod [-cfvR] [--help] [--version] mode file...](https://www.runoob.com/linux/linux-comm-chmod.html) > 作用:修改文件权限 ::: :::success [touch [-acfm][-d<日期时间>][-r<参考文件或目录>] [-t<日期时间>][--help][--version][文件或目录…]](https://www.runoob.com/linux/linux-comm-touch.html) > 作用:修改文件或者目录的时间属性,包括存取时间和更改时间。若文件不存在,系统会建立一个新的文件。 > 把文件的修改时间变成现在 > ![](https://i.imgur.com/1CpDsiA.png) > > 因为文件不存在,所以直接创立文件 > ![](https://i.imgur.com/wloqH3q.png) ::: **修改文件权限(chmod)** :::success 方法1:指定用户组,给与权限 方法2:直接使用二级制给与权限(rwx) ```cpp= // 方法1 // 参数u g o a 分别代表 文件所有者,用户组,其他使用者,全部 // 参数+ - = 分别代表 新增,删减,有(直接设定权限) chmod u/g/o/a +/-/= rwx 文件 // 方法2 // 777代表代表三组权限都全开 111 111 111(二进制) chmod 777 文件 chmod 777 文件 -R // 参数R代表连带把文件夹下的所有子文件、孙文件都设为777 ``` ::: **修改文件所有者(chown)、所在用户组(chgrp)** :::success ```cpp= sudo chown 新所有者 文件 sudo chgrp 新所在用户组 文件 ``` ::: **识别文件类型(file)** :::success [file [-bcLvz][-f <名称文件>][-m <魔法数字文件>...][文件或目录...]](https://www.runoob.com/linux/linux-comm-file.html) ::: ## 用户管理 **查看用户(whoami, who, w)** :::success 查看当前用户:whoami 查看之前登录的用户:who, w ::: **退出用户(exit)** :::success 如果是切换后的登录用户,推出则返回到上一个登录用户 如果无上级登录用户、是使用SSH远程登陆,则推出登录账户 如果无上级登录用户、是用图形界面,则推出当前终端 ::: **切换用户(su)** :::success ```cpp= su USER // 切换到非root的用户,其路径和原先保持一样 su - USER // 切换到非root的用户,其路径为用户的suo sudo su // 切换到root用户,root可以省略 sudo su root sudo su - root ``` ::: **用户组新增(groupadd)、删除(groupdel)、改变用户所在的用户组(usermod)** :::success ```cpp= // 通常新增用户组需要root权限,所以要再加sudo sudo groupadd newgroup cat /etc/group //可以到/edu里查找用户组信息文件(group) ``` ```cpp= // 通常删除用户组需要root权限,所以要再加sudo sudo groupdel newgroup //用户组里有用户时无法删除 ``` ```cpp= // 通常改变用户所在的用户组需要root权限,所以要再加sudo sudo usermod -g group user cat /etc/passwd //可以到/edu里查找用户信息文件(passwd) ``` ::: **新增用户(adduser/useradd)、删除用户(userdel)、设置用户密码(passwd)** :::success 每个用户都要有一个主目录 创建一个用户就需要指定他的主目录,否则系统会自行创建 ```cpp= // useradd跟adduser是等价的 sudo useradd -d /home/newusr newusr -m sudo useradd -d /home/newusr newusr -g group -m // 参数d代表指用户登陆时的主目录,不加的话会自动建立主目录在/home // 参数m代表如果指定的文件夹不存在就新建一个 // 因为新增用户,系统会自动新增同名的用户组,参数g表示指定用户所属的用户组 ``` ```cpp= sudo userdel newusr // 删了用户,但是主目录还是存在 sudo userdel -r newusr // 参数r表示会连同主目录一起删 ``` ```cpp= sudo passwd newusr ``` ::: ## 软件安装 **Ubuntu的在线软件安装** :::success ```c= sudo apt-get update //获得最新的软件包列表 sudo apt-get install XXX //从源中安装软件 sudo apt-get remove XXX //删除XXX软件 ``` ::: **安装包(rpm)** :::success *.rpm相当于Windows的*.exe ```c= //安装命令 rpm -ivh xxx.rpm ``` ::: ## 网络 **查看、设定网络信息(ifconfig -> ip a)** :::success 在Windows下叫做ipconfig 原本是ifconfig,现在已经改成ip a了 文章1:[ifconfig command not found](https://unix.stackexchange.com/questions/145447/ifconfig-command-not-found) 文章2:[ifconfig vs ip](https://www.tecmint.com/ifconfig-vs-ip-command-comparing-network-configuration/) ```cpp= //旧版本 ifconfig //新版本 ip -s -c -h a ``` ::: **ping** :::success 确认网络能否传送封包给指定的地址 能够传送封包给对方不代表对方也能传封包给你,所以两边都要ping ```c= ping 127.0.0.1 ``` ::: ## 前台、后台 **运行程序** :::success ```c= // 在当前路径运行 ./filename // 一定要加./,不然会被认为是命令 // 不在绝对路径 filename // ./filename & // &代表让程序在后台执行(服务器常用),会显示进程id,之后可以继续在终端输入其他命令 // 终止程序运行 Ctrl + C ``` ::: **程序前后台切换** :::success ```cpp= Ctrl + Z // 让程序在后台执行 jobs // 查看后台有哪些程序在运行,并且每个后台程序会有编号 fg n // 让编号为n的后台程序跑到前台运行 ``` :::

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully