1. 程式人生 > >Linux下又用得命令列彙總

Linux下又用得命令列彙總

原文:https://www.quora.com/What-are-the-most-useful-Swiss-army-knife-one-liners-on-Unix

A few simple but useful examples:

  • Set intersection, union, and difference of text files via sort/uniq: Suppose a and b are text files that are already uniqued. Note this is fast, and works on files of arbitrary size, up to many gigabytes. (Sort is not limited by memory, though you may need to use -T.) For comparison, see how many lines it is to write a disk-based merge sort in Java.
cat a b | sort | uniq > c   # c is a union b
cat a b | sort | uniq -d > c   # c is a intersect b
cat a b b | sort | uniq -u > c   # c is set difference a - b
  • Summing all numbers in the third column of a text file (this is probably 3X faster and 3X less code than equivalent Python):
awk '{ x += $3 } END { print x }' myfile
  • If want to see sizes/dates on a tree of files, this is like a recursive "ls -l" but is easier to read than "ls -lR":
find . -type f -ls
  • Use xargs. It's very powerful. Note you can control how many items execute per line (-L) as well as parallelism (-P). If you're not sure if it'll do the right thing, use xargs echo first. Also, -I{} is handy. Examples:
find . -name \*.py | xargs grep some_function
cat hosts | xargs -I{} ssh [email protected]{} hostname
  • Say you have a text file, like a web server log, and a certain value that appears on some lines, such as an acct_id parameter that is present in the URL. If you want a tally of how many requests for each acct_id:
cat access.log | egrep -o 'acct_id=[0-9]+' | cut -d= -f2 | sort | uniq -c | sort -rn

相關推薦

Linux命令彙總

原文:https://www.quora.com/What-are-the-most-useful-Swiss-army-knife-one-liners-on-Unix A few simple but useful examples: Set intersectio

LinuxMongodb安裝,命令操作和sql語句

--logappend --port=27017 --fork 5. 引數解釋: --dbpath 資料庫路徑(資料檔案)--logpath 日誌檔案路徑--master 指定為主機器--slave 指定為從機器--source 指定主機器的IP地址--pologSize 指定日誌檔案大小不超過64M.因為

linuxplink工具完全命令遠端批量關機

轉自http://19793580.blog.hexun.com/78309198_d.html 我的作業系統是centos6.4 作業系統:rhel 6.2 x86_64 下載並安裝putty軟體包,本人下載了putty-0.62-1.el6.rf.x86_64.rp

linux如何進行mysql命令 建立資料庫

我們除了可以在mysql資料庫或phpmyadmin中登陸資料庫我們還可以使用linux中命令進行建立,下面我來給大家介紹一個簡單的資料庫建立方法吧。 首選用putty連線linux伺服器,進行命令列 輸入mysql -u+資料庫使用者 -p+資料庫密碼 架設資料庫使用

LinuxSSHFTP命令上傳檔案至另一個FTP空間

如果沒有ftp 提示: -bash: ftp: command not found 請先安裝ftp應用程式: yum install ftp #ftp 127.0.0.1 21 輸入遠端空間的FTP IP和埠號,回車 然後根據提示輸入使用者名稱和密碼即可! ftp<

Linux常用命令彙總(2)

15、使用gnome-screenshot實現螢幕截圖 使用gnome-screenshot實現延時10秒螢幕截圖。輸入下面命令,然後開啟Applications/Accessories/Text Editor 方法:gnome-screenshot -d 10 16、使用

windowsgcc命令編譯並執行oc程式

首先,我的GNUstep安裝在D盤的GNUstep資料夾下,oc程式放在E盤的oc資料夾下,這裡以程式WordLength.c為例說明。 編譯oc程式: 開啟dos,然後將路徑定位到E盤的oc路徑下 命令列的寫法:E:         &nbs

安裝Redhat Linux 9.0 後,在命令中文顯示為亂碼的解決方案

在安裝Redhat Linux 9.0時,如果安裝中選擇的預設語言為簡體中文,則在安裝後,在命令列中的許多命令的執行結果顯示為亂碼。而且用redhat_config_language命令也無法將系統預設語言修改為英文。   對這一問題,我們可以修改 /etc/sysconf

Linux C 語言實現 ls 命令

這次主要的目的是用 C語言 實現 Linux 系統中的 ls 命令。 在編寫命令之前,需要介紹一下幾個結構體: 第一個 DIR: struct __dirstream { void *__fd; char *__data; in

AIX命令procstack hpux 對應的命令為pstack linux為gstack

通過PID列印程序堆疊情況,在看多執行緒死鎖的情況下真是很直觀。 [/_gx]procstack Usage: procstack [-F] PID ...   -F  Force procsta

Linux安裝軟件命令詳解

代碼包 相關信息 make bin 一個 軟件包 輸入 -i bin文件 Linux下軟件安裝方法總結:一、rpm包安裝方式步驟:1、找到相應的軟件包,比如soft.version.rpm,下載到本機某個目錄;2、打開一個終端,su -成root用戶;3、cd soft.v

linux mii-tool ethtool 命令簡單的使用

linux下mii-tool ethtool 命令簡單的使用################################################################通過命令查看linux網卡的物理信息,狀態:[[email protected]/* */ ~]# mii-

linux一些常用操作命令

linux 防火墻 端口 1、兩個服務器ssh免授權:ssh-keygen -t rsa 一直回車至結束ssh-copy-id -i /root/.ssh/id_rsa.pub 遠程ip 然後回車 輸入遠程ip密碼搞定,以後訪問就不用驗證密碼了2、壓縮和解壓縮命令: .tar

linux刪除戶腳本----不是userdel -r 那麽簡單

刪除用戶 linux 用戶 shell 自動刪除 linux下刪除用戶不僅僅是userdel -r 那麽簡單。如果你刪除用戶時,該用戶有許多進程正在進行,你是不是要一個個kill掉再刪除;如果你成功刪除該用戶後,系統中還有需要改用戶的文件是不是還要刪除。如上,豈不麻煩。下面的腳本可以幫你快

Linux戶添加到sudoers中

http his root密碼 配置 not in rep 希望 輸入密碼 -h Linux默認是沒有將用戶添加到sudoers列表中的,需要root手動將賬戶添加到sudoers列表中,才能讓普通賬戶執行sudo命令。 root 賬戶鍵入visudo即可進入sudo配置,

linux怎麽一個命令行統計出給定目錄中有多少個子目錄

linux怎麽用一個命令行統計出給定目錄中有多少個子目錄查看某目錄下文件的個數 ls -l |grep "^-"|wc -l 或 find ./company -type f | wc -l 查看某目錄下文件的個數,包括子目錄裏的。 ls -lR|grep "^-"|wc -l 查看某

linux各種解壓命令

好用 ast 網絡 所有 備份 pm2 文件壓縮 註意 詳細 .tar 解包:tar xvf FileName.tar打包:tar cvf FileName.tar DirName(註:tar是打包,不是壓縮!)———————————————.gz解壓1:gunzip Fi

Linux獲取消息隊的信息

cell cpp container eat comm lin containe code ron 在程序中想要獲取消息隊列長度可使用消息隊列的屬性這個數據結構: 需要#include <sys/msg.h> /* one msqid

Linux密碼文件首尾調換

linux 畫圖 三劍客總結:將第一列與最後一列調換的方法有很多,只要找準規律就會發現三劍客做這種題目的無窮樂趣。本文出自 “我思故我在” 博客,謝絕轉載!Linux下密碼文件首尾列調換

linuxbinary方式安裝mysql步驟

glibc zxvf sql 創建用戶 啟動服務 star 安裝mysql mysql目錄 初始化 1、下載binary文件   在http://dev.mysql.com/downloads/mysql/官網上下載 mysql-5.6.36-linux-glibc2.5-