Linux入門(五)

夏沫琅琊發表於2024-03-05

Linux入門(五)

本篇文章主要講述下檔案處理相關的命令

1: 顯示許可權

ls -lh

總用量 36K
drwxrwxr-x 5 zh zh 4.0K 2月  28 16:47 app
-rw-rw-r-- 1 zh zh  530 2月  22 18:25 build.gradle
drwxrwxr-x 3 zh zh 4.0K 2月  22 18:25 gradle
-rw-rw-r-- 1 zh zh 1.1K 2月  26 08:58 gradle.properties
-rwxrw-r-- 1 zh zh 5.2K 2月  22 18:25 gradlew
-rw-rw-r-- 1 zh zh 2.3K 2月  22 18:25 gradlew.bat
-rw-rw-r-- 1 zh zh  452 2月  22 18:25 local.properties
-rw-rw-r-- 1 zh zh   43 2月  22 18:25 settings.gradle

2: 檢視檔案內容(一)

cat命令檢視檔案內容:

cat build.gradle

可以看到build.gradle的內容從第一個位元組開始正常輸出.

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.1.2"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

而tac命令可以從最後一行反向檢視.

tac build.gradle

}    delete rootProject.buildDir
task clean(type: Delete) {

}
    }
        jcenter()
        google()
    repositories {
allprojects {

}
    }
        // in the individual module build.gradle files
        // NOTE: Do not place your application dependencies here; they belong

        classpath "com.android.tools.build:gradle:4.1.2"
    dependencies {
    }
        jcenter()
        google()
    repositories {
buildscript {
// Top-level build file where you can add configuration options common to all sub-projects/modules.

3: 檢視檔案內容(二)

使用more命令檢視檔案內容:

more build.gradle

4: 按行檢視檔案內容

檢視一個檔案的前幾行可以使用head命令:

head -5 build.gradle

執行結果輸出build.gradle的前5行資料.

使用tail命令可以檢視檔案的最後幾行:

tail -5 build.gradle

5: 實時檢視檔案內容

tail -f 命令可以實時的監測檔案變動

tail -f settings.gradle 
include ':app'
rootProject.name = "WebTest"tail: settings.gradle:檔案已截斷
include ':app'
rootProject.name = "WebTest"
rootProject.name = "WebTest"tail: settings.gradle:檔案已截斷
include ':app'
rootProject.name = "WebTest"
rootProject.name = "WebTest"rootProject.name = "WebTest"tail: settings.gradle:檔案已截斷
include ':app'
rootProject.name = "WebTest"

6: 檔案內容查詢

在檔案中查詢關鍵詞app:

grep app settings.gradle

在檔案中查詢以rootProject開始的詞彙:

grep ^rootProject settings.gradle

在檔案查詢所有包含數字的行:

grep [0-9] settings.gradle

忽略大小寫查詢:

grep -i "web" settings.gradle

查詢多個檔案:

grep -i "rootProject" settings.gradle build.gradle 

settings.gradle:rootProject.name = "WebTest"
settings.gradle:    delete rootProject.buildDir
build.gradle:    delete rootProject.buildDir

指定目錄查詢(包含子目錄並且遞迴查詢):

grep -r "xxxxx" app/

匹配到二進位制檔案 app/build/intermediates/dex/debug/mergeDexDebug/classes.dex
匹配到二進位制檔案 app/build/intermediates/javac/debug/classes/com/test/webtest/MainActivity.class
匹配到二進位制檔案 app/build/intermediates/javac/debug/classes/com/test/webtest/WebActivity$1.class
匹配到二進位制檔案 app/build/intermediates/javac/debug/classes/com/test/webtest/WebActivity.class
匹配到二進位制檔案 app/build/intermediates/external_libs_dex/debug/mergeExtDexDebug/classes.dex
匹配到二進位制檔案 app/build/intermediates/project_dex_archive/debug/out/com/test/webtest/MainActivity.dex
匹配到二進位制檔案 app/build/intermediates/project_dex_archive/debug/out/com/test/webtest/WebActivity.dex
匹配到二進位制檔案 app/build/intermediates/project_dex_archive/debug/out/com/test/webtest/WebActivity$1.dex
app/src/main/java/com/test/webtest/MainActivity.java:        Log.i("xxxxx", "changeScreenOffTime: "+System.currentTimeMillis());
app/src/main/java/com/test/webtest/MainActivity.java:            Log.i("xxxxx", "changeScreenOffTime: "+anInt);
app/src/main/java/com/test/webtest/WebActivity.java:            Log.i("xxxxx", "handleMessage: " + num++);
app/src/main/java/com/test/webtest/WebActivity.java:        Log.i("xxxxx", "getRandom: "+index);

本文由部落格一文多發平臺 OpenWrite 釋出!

相關文章