1. 程式人生 > >比 man 更強悍的命令列工具 cheat

比 man 更強悍的命令列工具 cheat

經常使用命令列,比如 curl 測試介面響應時間

for i in {1..10};do curl -o /dev/null -s   -w "$i | time_namelookup: %{time_namelookup} | time_connect: %{time_connect} | time_starttransfer: %{time_starttransfer} | time_total: %{time_total}\n" "http://httpbin.org/ip";done

1 | time_namelookup: 0.016000 | time_connect: 0.016000 | time_starttransfer: 0.125000 | time_total: 0.141000
2 | time_namelookup: 0.016000 | time_connect: 0.016000 | time_starttransfer: 0.094000 | time_total: 0.109000
3 | time_namelookup: 0.016000 | time_connect: 0.031000 | time_starttransfer: 0.109000 | time_total: 0.109000
4 | time_namelookup: 0.015000 | time_connect: 0.031000 | time_starttransfer: 0.109000 | time_total: 0.109000
5 | time_namelookup: 0.031000 | time_connect: 0.031000 | time_starttransfer: 0.109000 | time_total: 0.109000
6 | time_namelookup: 0.016000 | time_connect: 0.016000 | time_starttransfer: 0.094000 | time_total: 0.109000
7 | time_namelookup: 0.016000 | time_connect: 0.016000 | time_starttransfer: 0.125000 | time_total: 0.125000
8 | time_namelookup: 0.000001 | time_connect: 0.016000 | time_starttransfer: 0.141000 | time_total: 0.141000
9 | time_namelookup: 0.015000 | time_connect: 0.015000 | time_starttransfer: 0.093000 | time_total: 0.109000
10 | time_namelookup: 0.000001 | time_connect: 0.015000 | time_starttransfer: 0.109000 | time_total: 0.125000

奈何命令列引數太多,記不住怎麼辦?這時候你需要個男人,它就是 man

man

#man curl 
curl(1)                                      Curl Manual                                     curl(1)

NAME
       curl - transfer a URL

SYNOPSIS
       curl [options] [URL...]

DESCRIPTION
       curl  is  a  tool  to transfer data from or to a server, using one of the supported protocols
       (DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP,  LDAPS,  POP3,  POP3S,  RTMP,
       RTSP, SCP, SFTP, SMTP, SMTPS, TELNET and TFTP).  The command is designed to work without user
       interaction.

       curl offers a busload of useful tricks like proxy support, user authentication,  FTP  upload,
       HTTP  post,  SSL  connections, cookies, file transfer resume, Metalink, and more. As you will
       see below, the number of features will make your head spin!

       curl is powered by libcurl for all transfer-related features. See libcurl(3) for details.

URL
       The URL syntax is protocol-dependent. You'll find a detailed description in RFC 3986.

       You can specify multiple URLs or parts of URLs by writing part sets within braces as in:

        http://site.{one,two,three}.com

       or you can get sequences of alphanumeric series by using [] as in:

        ftp://ftp.numericals.com/file[1-100].txt
        ftp://ftp.numericals.com/file[001-100].txt    (with leading zeros)
        ftp://ftp.letters.com/file[a-z].txt

男人的確很強悍,給出了這麼多提示,但沒有我真正想要的。。。還是不知道怎麼用。

相信你在技術文章裡經常會看到 TL;DR 即Too Long; Didn’t Read. 太長不看, man curl 的內容就是太長了,我不看。

就是這個更強壯的男人 tldr,它一個命令列工具,直接使用 npm install -g tldr 來安裝。

tldr

[root@VM_0_14_centos ~]# npm install -g tldr
/usr/local/n/versions/node/11.4.0/bin/tldr -> /usr/local/n/versions/node/11.4.0/lib/node_modules/tldr/bin/tldr
+ [email protected]
added 113 packages from 103 contributors in 60.759s


   ╭───────────────────────────────────────────────────────────────╮
   │                                                               │
   │       New minor version of npm available! 6.4.1 → 6.9.0       │
   │   Changelog: https://github.com/npm/cli/releases/tag/v6.9.0   │
   │               Run npm install -g npm to update!               │
   │                                                               │
   ╰───────────────────────────────────────────────────────────────╯

安裝完後先看看 tldr 自己怎麼用吧。

$ tldr tldr

  tldr

  Simplified man pages.
  More information: .

  - Get typical usages of a command (hint: this is how you got here!):
    tldr command

  - Show the tar tldr page for linux:
    tldr -p linux tar

  - Get help for a git subcommand:
    tldr git checkout

小試牛刀下

$ tldr -p linux tar

  tar

  Archiving utility.
  Often combined with a compression method, such as gzip or bzip.
  More information: .

  - Create an archive from files:
    tar -cf target.tar file1 file2 file3

  - Create a gzipped archive:
    tar -czf target.tar.gz file1 file2 file3

  - Extract an archive in a target directory:
    tar -xf source.tar -C directory

  - Extract a gzipped archive in the current directory:
    tar -xzf source.tar.gz

  - Extract a bzipped archive in the current directory:
    tar -xjf source.tar.bz2

  - Create a compressed archive, using archive suffix to determine the compression program:
    tar -caf target.tar.xz file1 file2 file3

  - List the contents of a tar file:
    tar -tvf source.tar

  - Extract files matching a pattern:
    tar -xf source.tar --wildcards "*.html"

嗯,很簡潔,直接給出了tar需要的引數,再來看curl

λ tldr curl

  curl

  Transfers data from or to a server.
  Supports most protocols, including HTTP, FTP, and POP3.

  - Download the contents of an URL to a file:
    curl http://example.com -o filename

  - Download a file, saving the output under the filename indicated by the URL:
    curl -O http://example.com/filename

  - Download a file, following [L]ocation redirects, and automatically [C]ontinuing (resuming) a previous file transfer:
    curl -O -L -C - http://example.com/filename

  - Send form-encoded data (POST request of type application/x-www-form-urlencoded):
    curl -d 'name=bob' http://example.com/form

  - Send a request with an extra header, using a custom HTTP method:
    curl -H 'X-My-Header: 123' -X PUT http://example.com

  - Send data in JSON format, specifying the appropriate content-type header:
    curl -d '{"name":"bob"}' -H 'Content-Type: application/json' http://example.com/users/1234

  - Pass a user name and password for server authentication:
    curl -u myusername:mypassword http://example.com

  - Pass client certificate and key for a resource, skipping certificate validation:
    curl --cert client.pem --key key.pem --insecure https://example.com

這個男人果然更強悍,常用的curl命令都包括了,我喜歡。

除了自帶的命令,安裝的命令也可以

[root@VM_0_14_centos ~]# tldr python

  python

  Python language interpreter.
  More information: https://www.python.org.

  - Call a Python interactive shell (REPL):
    python

  - Execute script in a given Python file:
    python script.py

  - Execute script as part of an interactive shell:
    python -i script.py

  - Execute a Python expression:
    python -c "expression"

  - Run library module as a script (terminates option list):
    python -m module arguments

  - Interactively debug a Python script:
    python -m pdb script.py

除了node 還有其他版本 https://github.com/tldr-pages/tldr 比如Python,直接pip install tldr安裝

如果你不想安裝tldr,也可以直接使用網頁線上檢視https://tldr.sh/ image.png 有了tldr,媽媽再也不用擔心我記不住命令列引數了,還有沒有比 tldr更強悍的男人呢,有,比如cheat https://github.com/cheat/cheat  直接使用pip install cheat安裝。

cheat

看看 cheat 怎麼用吧

$ cheat cheat
# To see example usage of a program:
cheat <command>

# To edit a cheatsheet
cheat -e <command>

# To list available cheatsheets
cheat -l

# To search available cheatsheets
cheat -s <command>

# To get the current `cheat' version
cheat -v



試試 curl

$ cheat curl
# Download a single file
curl http://path.to.the/file

# Download a file and specify a new filename
curl http://example.com/file.zip -o new_file.zip

# Download multiple files
curl -O URLOfFirstFile -O URLOfSecondFile

# Download all sequentially numbered files (1-24)
curl http://example.com/pic[1-24].jpg

# Download a file and pass HTTP Authentication
curl -u username:password URL

# Download a file with a Proxy
curl -x proxysever.server.com:PORT http://addressiwantto.access

# Download a file from FTP
curl -u username:password -O ftp://example.com/pub/file.zip

# Get an FTP directory listing
curl ftp://username:[email protected]

# Resume a previously failed download
curl -C - -o partial_file.zip http://example.com/file.zip

# Fetch only the HTTP headers from a response
curl -I http://example.com

# Fetch your external IP and network info as JSON
curl http://ifconfig.me/all/json

# Limit the rate of a download
curl --limit-rate 1000B -O http://path.to.the/file

# Get your global IP
curl httpbin.org/ip

# Get only the HTTP status code
curl -o /dev/null -w '%{http_code}\n' -s -I URL

$ cheat python
# Desc: Python is a high-level programming language.

# Basic example of server with python
# Will start a Web Server in the current directory on port 8000
# go to http://127.0.0.1:8000

# Python v2.7
python -m SimpleHTTPServer
# Python 3
python -m http.server 8000

# SMTP-Server for debugging, messages will be discarded, and printed on stdout.
python -m smtpd -n -c DebuggingServer localhost:1025

# Pretty print a json
python -mjson.tool

比tldr更詳細,如果你也不想安裝可以直接使用curl

cht.sh

[root@VM_0_14_centos ~]# curl cht.sh/curl
# Download a single file
curl http://path.to.the/file

# Download a file and specify a new filename
curl http://example.com/file.zip -o new_file.zip

# Download multiple files
curl -O URLOfFirstFile -O URLOfSecondFile

# Download all sequentially numbered files (1-24)
curl http://example.com/pic[1-24].jpg

# Download a file and follow redirects
curl -L http://example.com/file

# Download a file and pass HTTP Authentication
curl -u username:password URL

# Download a file with a Proxy
curl -x proxysever.server.com:PORT http://addressiwantto.access

# Download a file from FTP
curl -u username:password -O ftp://example.com/pub/file.zip

# Get an FTP directory listing
curl ftp://username:[email protected]

# Resume a previously failed download
curl -C - -o partial_file.zip http://example.com/file.zip

# Fetch only the HTTP headers from a response
curl -I http://example.com

# Fetch your external IP and network info as JSON
curl http://ifconfig.me/all/json

# Limit the rate of a download
curl --limit-rate 1000B -O http://path.to.the/file

# POST to a form
curl -F "name=user" -F "password=test" http://example.com

# POST JSON Data
curl -H "Content-Type: application/json" -X POST -d '{"user":"bob","pass":"123"}' http://example.com

# POST data from the standard in / share data on sprunge.us
curl -F 'sprunge=<-' sprunge.us

看看Python的requests怎麼用

[root@VM_0_14_centos ~]# curl cheat.sh/python/requests
#  python-requests: Limit Number of Redirects Followed
#
#  You have to create Session (http://www.python-
#  requests.org/en/latest/api/requests.Session) object and set
#  max_redirects variable to 3

session = requests.Session()
session.max_redirects = 3
session.get(url)

#  TooManyRedirects exception will be raised if a requests exceeds
#  maximum number of redirects.
#
#  Related github issue discussing why you can not set max_redirects per
#  request https://github.com/kennethreitz/requests/issues/1300
#
#  [Alik] [so/q/31552627] [cc by-sa 3.0]

它也有網頁版 http://cht.sh/curl image.png 有了tldr和cheat,再也不用記那麼多命令列引數了。

win下我執行命令列的工具是cmder,如果你用的win10,可以嘗試下微軟最新發布的Terminal https://github.com/microsoft/Terminal

資源

微軟最爽命令列工具

Linux命令大全搜尋工具

Linux工具快速教程

有趣的Linux命令列工具

命令列的藝術

假裝很忙的三個命令列工具

28個UNIX/LINUX的命令列神器

命令列工具

PHPer 必知必會的 Linux 命令

推薦閱讀:

那些你可能不知道的瀏覽器奇技淫巧

那些你可能不知道的微信奇技淫巧

那些你可能不知道的微博奇技淫巧

那些你可能不知道的網易雲音樂奇技淫巧

那些你可能不知道的搜尋奇技淫巧

那些你可能不知道的視訊下載奇技淫巧

那些你可能不知道的免費觀看 VIP 視訊奇技淫巧

公眾號:蘇生不惑

掃   
 
 </div> 
 <div class=

相關推薦

man 強悍命令工具 cheat

經常使用命令列,比如 curl 測試介面響應時間 for i in {1..10};do curl -o /dev/null -s

iTerm--Terminal(終端)好用的命令工具

Terminal是Mac自帶的命令列工具,對於開發者來說,是不得不使用的開發工具之一。然而Terminal的外觀設定功能比較少,這對於每天都得跟它相處很久的我們來說,這是一個很大的悲傷。 當然,你也可

windows上好的命令工具軟體

windows自帶的console cmd用起來太不爽了,嘗試了一些其他的:看下來是powercmd和cmder比較好,而且兩個都可以和total commander結合起來,很不錯。 相比之下,

centos安裝tldr神器(man還好用的工具

linux學習歷程先從github上把tldr克隆下來:git clone https://github.com/tldr-pages/tldr.git安裝需求:1、pip(需要Python2.7+或3.3+環境)我用的是centos6.5 Python默認版本2.6.6,(版本太低安裝不了pip)先更新下P

ionic4+angular6 混合移動開發 capacitor cordova Xcode 命令工具 Command Line Tools

首先要更新或者安裝 ionic cli npm install -g ionic 建立專案 ionic start ionic-angular tabs --type=angular   –type=angular 是需要多加的引數,現在官方只整合好了angua

Capacitor 新一代混合應用“神器” 會代替Cordova嗎?? Xcode 命令工具 Command Line Tools

      1.介紹or暢想   Capacitor是由ionic團隊最新開發維護的一個跨平臺的應用程式容器,可以輕鬆構建在iOS,Android,Electron 和 Web 上本機執行的Web應用程式。我們稱這些應用為“Native

Cygwin(類UNIX模擬環境)&CURL(強大的http命令工具

前言: 需要我用curl試下能否傳送post請求調起公司的模擬系統(目前) 跟著大佬的腳步,親測一把~ 感謝大佬的提供的部落格和指導 @咩神  個人部落格園及來源地址 Cygwin(類UNIX模擬環境) 一個可以讓你在windows下玩轉linux命令的工具 Cygwin官網下載安裝包:http

svn使用規範、在Windows下使用svn命令工具、svn命令的解釋

以前在公司一直使用git,現在公司有用svn,一時間還真的不知道如何下手,在網上搜尋了很多大神和官網文件的指導,總結了下面一份教程,希望能夠幫助大家快速上手,如果想更細緻的瞭解相關內容,可以點選每個小節裡提供的的連結。 1、Windows下命令列工具: 發現原來安裝的tortoisesvn已經整合到she

macOS 升級後重裝命令工具的問題

問題背景 最近升級個人macbook 從 10.13 到 10.14 在終端輸入 git 不能用了,發現是重灌作業系統後原來的 Command Line Tools 被自動解除安裝了, 採用 xcode-select --install 命令發現 currently unavailable. 解決方法

Sentry命令工具除錯資訊檔案

sentry-cli可用於驗證和上傳除錯資訊檔案(dSYM,Proguard檔案等)。 除錯資訊檔案是其他檔案,可幫助我們提供有關崩潰報告的更多資訊。我們目前支援以下格式: 適用於iOS,tvOS和macOS的dSYM檔案 適用於Linux和Android的ELF符號 適用

Sentry命令工具認證和登陸

對於大多數功能,您需要使用Sentry進行身份驗證。要通過CLI工具登入,您可以使用login命令來指導您完成: $ sentry-cli login 如果您想手動驗證sentry-cli,您可以轉到您的使用者帳戶(使用者圖示 - > API)中的身份驗證令牌設定,並生成至少包含以下範

Sentry命令工具安裝

根據您的平臺,有不同的方法可用於安裝sentry-cli。 一、手動下載 您可以在github釋出頁面上找到發行版列表。我們為Linux,OS X和Windows提供可執行檔案。這是單個檔案下載,收到檔案後,您可以將其重新命名為sentry-cli或sentry-cli.exe以使用它。

Sentry命令工具之Breakpad符號上傳

sentry-cli可以將dump_syms工具生成的Breakpad符號上傳到Sentry,以允許對Minidump崩潰報告進行符號化。 Breakpad使用獨立於平臺的ASCII格式來儲存除錯資訊。通常使用Breakpad,Crashpad或Electron Framework為應用程式生成此類

Sentry命令工具之PDB檔案上傳

Sentry尚不直接支援Microsoft PDB檔案。在我們提供官方支援之前,您可以將它們轉換為Breakpad符號並上傳它們: 獲取.pdb檔案並將其放在Windows計算機上 下載我們的Windows Breakpad Tools並解壓縮dump_syms.exe 執行d

Sentry命令工具之ELF符號上傳

sentry-cli可以將在各種Linux發行版上生成的ELF符號上傳到Sentry,以允許符號化Linux和Android應用程式崩潰。 ELF代表可執行檔案和可連結格式,這是Linux上用於二進位制檔案的檔案格式。 與其他平臺不同,除錯符號沒有標準化容器。它們是二進位制檔案(可執行檔案或庫)的一

Sentry命令工具之dSYM上傳

sentry-cli可以將dSYM檔案上傳到Sentry,以允許iOS應用程式崩潰的符號。如果您使用fastlane或構建系統整合等系統,它也會在幕後使用。 1、基本上傳 使用upload-dif上傳dSYM檔案並指定dsym型別。如果在Xcode構建步驟中呼叫,sentry-cli將自動獲

Sentry命令工具之釋出管理

sentry-cli工具可用於Sentry的釋出管理。它允許您建立,編輯和刪除版本以及為它們上載釋出工件。 一、建立版本 使用sentry-cli釋出新命令建立發行版。它至少需要一個唯一標識關係的版本識別符號。它可以是任意的,但對於某些平臺,建議存在: 對於移動裝置,請使用VERS

Sentry命令工具之傳送事件

sentry-cli工具也可用於傳送事件。如果要使用它,則需要匯出SENTRY_DSN環境變數並將其指向您的專案的DSN: $ export SENTRY_DSN=https://<key>:<secret>@sentry.io/<project> 完成後

Sentry命令工具之ProGuard對映上傳

sentry-cli可用於將proguard檔案上傳到Sentry,但在大多數情況下,您可以使用gradle外掛來執行此操作。在某些情況下,您可以手動上傳proguard檔案(例如,當您只發布一些正在建立的構建時)。 一、基本上傳 upload-proguard命令是用於上載proguard

在Mac下安裝和使用gcc命令工具

【原文:http://blog.163.com/chenchen..1986/blog/static/76063146201478104739289/】 這樣,就不用去windows下使用Visual C++了。 Apple在Xcod