跳到主要內容

Ubuntu 常用指令

id - 查詢使用者權限

id jerry
uid=1003(jerry) gid=1004(jerry) groups=1004(jerry) ...

查詢檔案權限

getfacl

getfacl docker-compose
# file: docker-compose
# owner: root
# group: root
user::rw-
group::r--
other::r--

ls

ls -al
drwxr-xr-x  2 root root    4096 Jan 11 02:26 .
drwxr-xr-x 10 root root    4096 Dec 12 14:21 ..
-rw-r--r--  1 root root 8479184 Jan 11 02:26 docker-compose

chown - 更改檔案擁有者

chown UserName FileName

chgrp - 更改檔案群組

系統的群組都紀錄在 /etc/group 檔案內

chgrp UserName FileName

chmod - 修改權限


# a : 全部 user
# u : 目前檔案的 owner
# g : 目前檔案的 group
# o : 其他

# + : 給予
# - : 移除
# = : 設定

# r : 讀
# w : 寫
# x : 執行

chmod [a/u/g/o] [+/-/=] [r/w/x] FileName
# 讓所有 user 可以執行這個 File 
chmod a+x FileName

tar - 壓縮, 解壓縮

# -z : 透過 gzip  的支援進行壓縮/解壓縮:此時檔名最好為 *.tar.gz
# -cv : 建立打包檔案,可搭配 -v 來察看過程中被打包的檔名(filename)
# -f FileName : 後面要立刻接要被處理的檔名!建議 -f 單獨寫一個選項囉!(比較不會忘記)  
# -x : 解打包或解壓縮的功能,可以搭配 -C (大寫) 在特定目錄解開, -c, -t, -x 不可同時出現在一串指令列中。

壓縮

tar -zcv -f FileName.tar.gz DirName 

解壓縮

tar -zxv -f FileName.tar.gz

which - 查詢指令所在位置

which java
/usr/bin/java

ps - 查詢 process

ps aux | grep ProcessName 

apt 常用指令

詳細說明:http://nathan-inlinux.blogspot.tw/2013/05/apt-get.html

# 更新 /etc/apt/sources.list
apt-get update
# 套件升級, 找出 apt 管理的相關套件做升級 (有相依性問題, 不會升級, 建議使用)
apt-get upgrade
# 套件升級, 找出 apt 管理的相關套件做升級 (自動處理相依性問題, 風險高)
apt-get dist-upgrade
# 只升級 redis-server 套件
apt-get dselect-upgrade redis-server
# 安裝 redis-server 套件
apt-get install redis-server
# 移除下載的暫存檔, 安裝完套件建議執行一下
apt-get autoremove
# 移除套件的 .deb 安裝檔, 安裝完套件建議執行一下
apt-get autoclean
# 移除套件
apt-get remove
# 移除套件, 移除相關設定
apt-get -purge remove
# 檢查 apt-get 相關問題
apt-get check 

# 顯示套件相關資訊, 版本, md5 (安裝任何套件, 建議檢查一下)
apt-cache showpkg redis-server



Reference

  • 凍仁筆記 - http://note.drx.tw/2008/04/command.html
  • 鳥哥 - http://linux.vbird.org/linux_basic/
  • 阿舍 - http://www.arthurtoday.com/2013/10/ubuntu-ps-aux-vs-ef.html

留言

這個網誌中的熱門文章

Parse URI query string to Key Value

Parse URI query String to Map 做 urlDecode 處理 沒有任何 query String 回傳 Empty Map 確保只處理 key-value 結構的 query String package com.example.util; import lombok.extern.slf4j.Slf4j; import org.apache.http.client.utils.URIBuilder; import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URISyntaxException; import java.net.URLDecoder; import java.util.LinkedHashMap; import java.util.Map; import java.util.Objects; /** * Created by jerry on 2017/12/28. * * @author jerry */ @Slf4j public class UriUtil { private UriUtil() { } public static Map splitQuery(final String uri) { Map queryPairs = new LinkedHashMap (); try { final URI uri = new URIBuilder(uri).build(); final String rawQuery = uri.getRawQuery(); log.info("CurrentUrl Query: {}", rawQuery); // 過濾沒有 query string // 還有過濾無法成對 keyValue 的 query, e.g. http://host/path?123 if (Objects.isNull(rawQuery) |...

Google Compute Engine‎ - AccessDeniedExceptions 403

原因 打算從 instance 打包 logs 到 google cloud storage 發生了 AccessDeniedException: 403 Insufficient OAuth2 scope to perform this operation. , 看起來是 instance 沒有 storage 權限 解決 Reference: https://cloud.google.com/compute/docs/access/create-enable-service-accounts-for-instances#changeserviceaccountandscopes 重新設定 service account 權限 instance 上內建有 gcloud , 就直接用現有的工具查詢一下 instance 的 account. $ gsutil info 或者在本機直接 gcloud compute instances describe INSTANCE_NAMES Account: [alpha-number-compute@developer.gserviceaccount.com] Project: [our-project-name] 會看到 instance 的一些狀態, 接下來就簡單多了, 按照下列的說明, 要先 stop instance, 更改 storage scope 再重新 start 。 To change an instance's service account and access scopes, the instance must be temporarily stopped. To stop your instance, read the documentation for Stopping an instance. After changing the service account or access scopes, remember to restart the instance. # Stop Instance gcloud compute instances stop INSTANCE_NAMES # 設定 storage scope 為 full (Read, Write) gcloud co...

Spring-boot Thymeleaf Html5 SAXParseException 解析錯誤

thymeleaf 解析 html5 出錯 <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="description" content=""> <meta name="author" content=""> <title>SB Admin - Start Bootstrap Template</title> <!-- Bootstrap core CSS--> <link href="../static/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet"> <!-- Custom fonts for this template--> <link href="../static/vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css"> <!-- Page level plugin CSS--> <link href="../static/vendor/datatables/dataTables.bootstrap4.css" rel="stylesheet"> <!-- Custom styles for this template--> <li...