Source From Here
Preface
How do I sort all *.avi or *.py files in $HOME/Download/ directory by file size using Linux ls command line utility?
The ls command is used to list directory contents under Linux and Unix like operating systems. If no options or operands are given, the contents of the current directory are displayed on the screen. By default entries are sorted alphabetically if none of the -cftuvSUX nor --sort option passed to the ls command.
The default output (sort by alphabetically)
Type the following command:
Sample outputs:
Force sort by size option
You need to pass the -S or --sort=size option as follows:
Sample outputs:
You will see largest file first before sorting the operands in lexicographical order. The following command will sort file size in reverse order:
OR try (see comments below, thanks!):
Sample Output:
Sort output and print sizes in human readable format (e.g., 1K 234M 2G)
Pass the -h option to the ls command as follows:
Supplement
* Linux/Unix Command - sort
This is a blog to track what I had learned and share knowledge with all who can take advantage of them
標籤
- [ 英文學習 ]
- [ 計算機概論 ]
- [ 深入雲計算 ]
- [ 雜七雜八 ]
- [ Algorithm in Java ]
- [ Data Structures with Java ]
- [ IR Class ]
- [ Java 文章收集 ]
- [ Java 代碼範本 ]
- [ Java 套件 ]
- [ JVM 應用 ]
- [ LFD Note ]
- [ MangoDB ]
- [ Math CC ]
- [ MongoDB ]
- [ MySQL 小學堂 ]
- [ Python 考題 ]
- [ Python 常見問題 ]
- [ Python 範例代碼 ]
- [心得扎記]
- [網路教學]
- [C 常見考題]
- [C 範例代碼]
- [C/C++ 範例代碼]
- [Intro Alg]
- [Java 代碼範本]
- [Java 套件]
- [Linux 小技巧]
- [Linux 小學堂]
- [Linux 命令]
- [ML In Action]
- [ML]
- [MLP]
- [Postgres]
- [Python 學習筆記]
- [Quick Python]
- [Software Engineering]
- [The python tutorial]
- 工具收集
- 設計模式
- 資料結構
- ActiveMQ In Action
- AI
- Algorithm
- Android
- Ansible
- AWS
- Big Data 研究
- C/C++
- C++
- CCDH
- CI/CD
- Coursera
- Database
- DB
- Design Pattern
- Device Driver Programming
- Docker
- Docker 工具
- Docker Practice
- Eclipse
- English Writing
- ExtJS 3.x
- FP
- Fraud Prevention
- FreeBSD
- GCC
- Git
- Git Pro
- GNU
- Golang
- Gradle
- Groovy
- Hadoop
- Hadoop. Hadoop Ecosystem
- Java
- Java Framework
- Java UI
- JavaIDE
- JavaScript
- Jenkins
- JFreeChart
- Kaggle
- Kali/Metasploit
- Keras
- KVM
- Learn Spark
- LeetCode
- Linux
- Lucene
- Math
- ML
- ML Udemy
- Mockito
- MPI
- Nachos
- Network
- NLP
- node js
- OO
- OpenCL
- OpenMP
- OSC
- OSGi
- Pandas
- Perl
- PostgreSQL
- Py DS
- Python
- Python 自製工具
- Python Std Library
- Python tools
- QEMU
- R
- Real Python
- RIA
- RTC
- Ruby
- Ruby Packages
- Scala
- ScalaIA
- SQLAlchemy
- TensorFlow
- Tools
- UML
- Unix
- Verilog
- Vmware
- Windows 技巧
- wxPython
2014年9月30日 星期二
[ Ruby Gossip ] Basic : 基本指令與觀念 - irb 與 ruby 指令
Source From Here
Preface
你 可以至 Ruby 的官方網站 下載安裝 Ruby (JRuby),初學 Ruby,可以執行Ruby安裝目錄中的 irb 指令,啟動指令互動環 境來作些簡單的程式練習,可以自行進入文字模式,設定 PATH 中包括Ruby安裝目錄的bin目錄,再執行 irb 指令以進入指令互動環境:
這是Ruby的指令互動環境,可以讓你很快地撰寫一些小指令進行測試(經常的,你只是要看看某個指令這麼用對不對,或會有什麼結果),上例執行 1 + 2,=> 3 表示結果為3,如果想離開irb,可以輸入exit。預設irb提示(Prompt)較為冗長,可以執行irb時加上 --simple-prompt,顯示簡單提示字元,順便來看幾個簡單的互動:
這執行了 1 + 2,顯示結果為3,_ 代表了互動環境中上一次運算結果,方便你在下一次的運算中直接取用上一次的運算結果。最後一次執行了 print,這個方法可顯示指定的文字,print 不會換行,所以字串最後加上 \n 表示要換行,最後 => nil 表示 print 執行結束沒有傳回結果,這是蠻有用的資訊,如果真的不想看到,可以在執行 irb 時加上 --noecho,不過這也就不會顯示如 1+2 的執行結果:
More Example
再來看看其它的一些互動:
你可以在互動中直接觀察程式碼的執行結果,Ruby 的許多定義都是以 end 結尾,如果在 irb 中輸入錯誤了,可以嘗試輸入 end 回到正常提示字元。
你可以撰寫一個純文字檔案,建議副檔名為 .rb,在當中撰寫 Ruby 程式碼:
- hello.rb
程式中 puts 會將指定的文字輸出後換行,接著如下執行 ruby 指令啟動 Ruby 直譯器,載入指令稿直譯並執行:
如果只是要測試一小段簡單的指令稿,不一定要寫 .rb 檔案,也不一定要進入 irb,可以在執行 ruby 指令時,於 -e 之後用單引號括住指令稿,多行程式碼時以分號區隔。例如:
在執行 ruby 指令時,可以指定 -c 僅檢查語法但不執行程式,指定 -w 顯示額外警訊,由於 -c、-w 經常一起指定,所以有個 -cw 可以達到分別指定 -c、-w 的效果。例如:
由於 Ruby 在呼叫方法時可以省略括號,上例第二個指令稿中,(1 + x) 的括號被直譯器解釋為優先執行 1 + x,而不會是 print 方法的括號,雖然就這個例子而言,哪個解釋的執行結果都相同,但有些情況下這類的解釋可能不是你想要的,於是直譯器提出了警告訊息。
以上是常用的 ruby 指令選項,如果想知道更多選項,可以執行 ruby 時鍵入 --help 或 -h 顯示說明清單:
Supplement:
* Next Basic : 基本指令與觀念 - load 與 require
* JRuby API
* Ruby 使用手冊
Preface
你 可以至 Ruby 的官方網站 下載安裝 Ruby (JRuby),初學 Ruby,可以執行Ruby安裝目錄中的 irb 指令,啟動指令互動環 境來作些簡單的程式練習,可以自行進入文字模式,設定 PATH 中包括Ruby安裝目錄的bin目錄,再執行 irb 指令以進入指令互動環境:
# irb
...
irb(main):001:0> 1 + 2
=> 3
irb(main):002:0>
這是Ruby的指令互動環境,可以讓你很快地撰寫一些小指令進行測試(經常的,你只是要看看某個指令這麼用對不對,或會有什麼結果),上例執行 1 + 2,=> 3 表示結果為3,如果想離開irb,可以輸入exit。預設irb提示(Prompt)較為冗長,可以執行irb時加上 --simple-prompt,顯示簡單提示字元,順便來看幾個簡單的互動:
>> 1 + 2
=> 3
>> _
=> 3
>> 1 + _
=> 4
>> _
=> 4
>> print "Hello! Ruby!\n"
Hello! Ruby!
=> nil
這執行了 1 + 2,顯示結果為3,_ 代表了互動環境中上一次運算結果,方便你在下一次的運算中直接取用上一次的運算結果。最後一次執行了 print,這個方法可顯示指定的文字,print 不會換行,所以字串最後加上 \n 表示要換行,最後 => nil 表示 print 執行結束沒有傳回結果,這是蠻有用的資訊,如果真的不想看到,可以在執行 irb 時加上 --noecho,不過這也就不會顯示如 1+2 的執行結果:
# irb --simple-prompt --noecho
>> print "Hello! Ruby!\n"
Hello! Ruby!
>> 1 + 2
>>
More Example
再來看看其它的一些互動:
你可以在互動中直接觀察程式碼的執行結果,Ruby 的許多定義都是以 end 結尾,如果在 irb 中輸入錯誤了,可以嘗試輸入 end 回到正常提示字元。
你可以撰寫一個純文字檔案,建議副檔名為 .rb,在當中撰寫 Ruby 程式碼:
- hello.rb
- puts "Hello! Ruby!"
# ruby hello.rb
Hello!Ruby!
如果只是要測試一小段簡單的指令稿,不一定要寫 .rb 檔案,也不一定要進入 irb,可以在執行 ruby 指令時,於 -e 之後用單引號括住指令稿,多行程式碼時以分號區隔。例如:
# jruby -e 'print "Hello! Ruby!\n"; puts "Hello! Ruby"'
Hello! Ruby!
Hello! Ruby
在執行 ruby 指令時,可以指定 -c 僅檢查語法但不執行程式,指定 -w 顯示額外警訊,由於 -c、-w 經常一起指定,所以有個 -cw 可以達到分別指定 -c、-w 的效果。例如:
# ruby -c -w hello.rb
Syntax OK
# ruby -cw -e 'x = 10; print (1 + x)'
-e:1: warning: (...) interpreted as grouped expression
Syntax OK
由於 Ruby 在呼叫方法時可以省略括號,上例第二個指令稿中,(1 + x) 的括號被直譯器解釋為優先執行 1 + x,而不會是 print 方法的括號,雖然就這個例子而言,哪個解釋的執行結果都相同,但有些情況下這類的解釋可能不是你想要的,於是直譯器提出了警告訊息。
以上是常用的 ruby 指令選項,如果想知道更多選項,可以執行 ruby 時鍵入 --help 或 -h 顯示說明清單:
Supplement:
* Next Basic : 基本指令與觀念 - load 與 require
* JRuby API
* Ruby 使用手冊
2014年9月28日 星期日
[ Groovy Doc ] AST : Singleton transformation
Source From Here
Whether the singleton is pattern or an anti-pattern, there are still some cases where we need to create singletons. We're used to create a private constructor, a getInstance() method for a static field or even an initialized public static final field. So instead of writing code like this in Java:
You just need to annotate your type with the @Singleton annotation:
The singleton instance can then simply be accessed with T.instance (direct public field access). You can also have the lazy loading approach with an additional annotation parameter:
Would become more or less equivalent to this Groovy class:
Lazy or not, once again, to access the instance, simply do T.instance (property access, shorcut for T.getInstance()).
Below is the singleton usage example:
Execution Result:
Supplement
* Compile-time Metaprogramming - AST Transformations
Whether the singleton is pattern or an anti-pattern, there are still some cases where we need to create singletons. We're used to create a private constructor, a getInstance() method for a static field or even an initialized public static final field. So instead of writing code like this in Java:
- public class T {
- public static final T instance = new T();
- private T() {}
- }
- @Singleton class T {}
- @Singleton(lazy = true) class T {}
- class T {
- private static volatile T instance
- private T() {}
- static T getInstance () {
- if (instance) {
- instance
- } else {
- synchronized(T) {
- if (instance) {
- instance
- } else {
- instance = new T ()
- }
- }
- }
- }
- }
Below is the singleton usage example:
- @Singleton(strict=false,lazy=true)
- class T {
- static int i=0
- public T(){i++}
- }
- printf("T.i=%d\n", T.i) // lazy=false:1, lazy=true:0
- printf("T.instance.i=%d\n", T.instance.i)
- printf("T.instance.i=%d\n", T.instance.i)
- T t = new T() // Not access T object through T.instance
- printf("T.instance.i=%d\n", T.instance.i)
T.i=0
T.instance.i=1
T.instance.i=1
T.instance.i=2
Supplement
* Compile-time Metaprogramming - AST Transformations
[ Groovy Doc ] Category and Mixin transformations
Source From Here
If you've been using Groovy for a while, you're certainly familiar with the concept of Categories. It's a mechanism to extend existing types (even final classes from the JDK or third-party libraries), to add new methods to them. This is also a technique which can be used when writing Domain-Specific Languages. Let's consider the example below:
We have a simplistic and fictive Distance class which may have been provided by a third-party, who had the bad idea of making the class final so that nobody could ever extend it in any way. But thanks to a Groovy Category, we are able to decorate the Distance type with additional methods. Here, we're going to add a getMeters() method to numbers, by actually decorating the Number type. By adding a getter to a number, you're able to reference it using the nice property syntax of Groovy. So instead of writing 300.getMeters(), you're able to write 300.meters.
The downside of this category system and notation is that to add instance methods to other types, you have to create static methods, and furthermore, there's a first argument which represents the instance of the type we're working on. The other arguments are the normal arguments the method will take as parameters. So it may be a bit less intuitive than a normal method definition we would have added to Distance, should we have had access to its source code for enhancing it. Here comes the @Categoryannotation, which transforms a class with instance methods into a Groovy category:
No need for declaring the methods static, and the this you use here is actually the number on which the category will apply, it's not the real this of the category instance should we create one. Then to use the category, you can continue to use the use(Category) {} construct. What you'll notice however is that these kind of categories only apply to one single type at a time, unlike classical categories which can be applied to any number of types.
Now, pair @Category extensions to the @Mixin transformation, and you can mix in various behavior in a class, with an approach similar to multiple inheritance:
You don't inherit from various interfaces and inject the same behavior in each subclass, instead you mixin the categories into your class. Here, our marvelous James Bond vehicle gets the flying and diving capabilities through mixins.
An important point to make here is that unlike @Delegate which can inject interfaces into the class in which the delegate is declared, @Mixin just does runtime mixing — as we shall see in the metaprogramming enhancements further down in this article.
Supplement
* Delegate Transformation
* Dynamic object orientation - Using power features
If you've been using Groovy for a while, you're certainly familiar with the concept of Categories. It's a mechanism to extend existing types (even final classes from the JDK or third-party libraries), to add new methods to them. This is also a technique which can be used when writing Domain-Specific Languages. Let's consider the example below:
- final class Distance {
- def number
- String toString() { "${number}m" }
- }
- class NumberCategory {
- static Distance getMeters(Number self) {
- new Distance(number: self)
- }
- }
- use(NumberCategory) {
- def dist = 300.meters
- assert dist instanceof Distance
- assert dist.toString() == "300m"
- }
The downside of this category system and notation is that to add instance methods to other types, you have to create static methods, and furthermore, there's a first argument which represents the instance of the type we're working on. The other arguments are the normal arguments the method will take as parameters. So it may be a bit less intuitive than a normal method definition we would have added to Distance, should we have had access to its source code for enhancing it. Here comes the @Categoryannotation, which transforms a class with instance methods into a Groovy category:
- @Category(Number)
- class NumberCategory {
- Distance getMeters() {
- new Distance(number: this)
- }
- }
Now, pair @Category extensions to the @Mixin transformation, and you can mix in various behavior in a class, with an approach similar to multiple inheritance:
- @Category(Vehicle) class FlyingAbility {
- def fly() { "I'm the ${name} and I fly!" }
- }
- @Category(Vehicle) class DivingAbility {
- def dive() { "I'm the ${name} and I dive!" }
- }
- interface Vehicle {
- String getName()
- }
- @Mixin(DivingAbility)
- class Submarine implements Vehicle {
- String getName() { "Yellow Submarine" }
- }
- @Mixin(FlyingAbility)
- class Plane implements Vehicle {
- String getName() { "Concorde" }
- }
- @Mixin([DivingAbility, FlyingAbility])
- class JamesBondVehicle implements Vehicle {
- String getName() { "James Bond's vehicle" }
- }
- assert new Plane().fly() ==
- "I'm the Concorde and I fly!"
- assert new Submarine().dive() ==
- "I'm the Yellow Submarine and I dive!"
- assert new JamesBondVehicle().fly() ==
- "I'm the James Bond's vehicle and I fly!"
- assert new JamesBondVehicle().dive() ==
- "I'm the James Bond's vehicle and I dive!"
An important point to make here is that unlike @Delegate which can inject interfaces into the class in which the delegate is declared, @Mixin just does runtime mixing — as we shall see in the metaprogramming enhancements further down in this article.
Supplement
* Delegate Transformation
Java doesn't provide any built-in delegation mechanism, and so far Groovy didn't either. But with the @Delegate transformation, a class field or property can be annotated and become an object to which method calls are delegated...
* Dynamic object orientation - Using power features
This section presents three power features that Groovy supports at the language level: GPath, the Spread operator, and the use keyword...
訂閱:
文章 (Atom)
[Git 常見問題] error: The following untracked working tree files would be overwritten by merge
Source From Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 # git clean -d -fx 方案2: 今天在服务器上 gi...
-
前言 : 為什麼程序管理這麼重要呢?這是因為: * 首先,本章一開始就談到的,我們在操作系統時的各項工作其實都是經過某個 PID 來達成的 (包括你的 bash 環境), 因此,能不能進行某項工作,就與該程序的權限有關了。 * 再來,如果您的 Linux 系統是個...
-
屬性 : 系統相關 - 檔案與目錄 語法 : du [參數] [檔案] 參數 | 功能 -a | 顯示目錄中個別檔案的大小 -b | 以bytes為單位顯示 -c | 顯示個別檔案大小與總和 -D | 顯示符號鏈結的來源檔大小 -h | Hum...
-
來源自 這裡 說明 : split 是 Perl 中非常有用的函式之一,它可以將一個字串分割並將之置於陣列中。若無特別的指定,該函式亦使用 RE 與 $_ 變數 語法 : * split /PATTERN/,EXPR,LIMIT * split /...