Linux入门(五)

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 发布!

posted @ 2024-03-05 15:02  夏沫琅琊  阅读(11)  评论(0编辑  收藏  举报