Linux入门(五)
本篇文章主要讲述下文件处理相关的命令
1: 显示权限
ls -lh
ls -lh是一个常用的Linux命令,用于列出目录下的文件和文件夹,并显示它们的详细信息,包括文件大小、权限、所有者等。其中,参数-l表示以长格式显示,参数-h表示以人类可读的方式显示文件大小。
总用量 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
文件权限:包括读、写、执行权限,分别用r、w、x表示。
硬链接数:表示有多少个文件名指向该文件。
所有者:表示文件的所有者。
所属组:表示文件所属的用户组。
文件大小:以人类可读的方式显示,如1K、2M等。
修改时间:表示文件的最后修改时间。
文件名:表示文件或文件夹的名称。
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: 文件内容查找
grep命令是一个强大的文本搜索工具,用于在文件中查找指定的模式
-i:忽略大小写进行匹配。
-r:递归地搜索目录下的所有文件。
-v:反向匹配,只打印不匹配的行。
-n:显示匹配行的行号。
-l:只打印包含匹配项的文件名。
-w:只匹配整个单词,而不是部分匹配。
下面是一些简单的例子:
在文件中查找关键词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);