简体   繁体   English

如何获取带有文件名的文件的完整路径?

[英]How could I get the full path of a file with file name?

[ SOLUTION ] [ 解决方案 ]

Thanks to @oguzismail and @stylo I find the solution.感谢@oguzismail 和@stylo 我找到了解决方案。 In the find command I modified the 2>&1 for 2>/dev/null and deleted the grep command, but I found the problem that it retrieves me two different path (because Android studio it was generation two different apk with the same name in two different paths).在 find 命令中,我将2>&1修改为2>/dev/null并删除了 grep 命令,但我发现它检索到两个不同路径的问题(因为 Android studio 它在两条不同的路径)。

To only get the path of the apk I want, I add a "filter" for my find command so the solution is:为了只获取我想要的 apk 的路径,我为我的 find 命令添加了一个“过滤器”,因此解决方案是:

find / -path ./intermediates -prune -o -name app-ipd-debug.apk 2>/dev/null

with name of the folder ./intermediates and -prune -o I can get the path I wanted to.使用文件夹的名称./intermediates-prune -o我可以获得我想要的路径。

I saw the solution in this post在这篇文章中看到了解决方案

[ PROBLEM ] [ 问题 ]

I am doing a shell script that build an android project, install apk and do some more configurations in the device like set owner device owner (is a kiosk mode app) and some more stuff.我正在做一个 shell 脚本,该脚本构建一个 android 项目,安装 apk 并在设备中进行更多配置,例如设置所有者设备所有者(是一个信息亭模式应用程序)等等。

Now I am trying to dynamically build the project and get the apk file to install in the device but it doesn't work correctly.现在我正在尝试动态构建项目并获取 apk 文件以安装在设备中,但它无法正常工作。

I try putting the full path as a variable in my shell script and this works installing the app using the command adb install:我尝试将完整路径作为变量放在我的 shell 脚本中,这可以使用命令 adb install 安装应用程序:

adb install -t -r $APK_PATH

I have tried t get the APK_PATH with find command but it retrieves me a lot of output that I don't know how to handle it, the command is:我尝试使用find命令获取 APK_PATH,但它检索到很多我不知道如何处理的 output,命令是:

find / -name apk-file-name.apk

A lot of output with " Permission denied " and " Operation not permitted " is shown and in one line of those the apk path is shown (this is the one I don't know how to get it, only this result)显示了许多带有“ Permission denied ”和“ Operation not allowed ”的output,其中一行显示了apk路径(这是我不知道如何获得它的,只有这个结果)

I try to filter the results using grep but it doesn't work我尝试使用 grep 过滤结果,但它不起作用

find / -name apk-file-name.apk 2>&1 | grep -v "Operation not permitted"

and

find / -name apk-file-name.apk 2>&1 | grep -v "Operation not permitted"|"Permission denied"

any help?有什么帮助吗?

You can use the locate command to locate files in your file system.您可以使用locate命令在文件系统中定位文件。

if you haven't enabled it yet, you can do so by running the following command如果您还没有启用它,您可以通过运行以下命令来启用它

sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist

you won't be able to use it for a few minutes since it will index everything and later on you can use locate file_name.apk to find the file you're looking for.您将在几分钟内无法使用它,因为它将索引所有内容,稍后您可以使用locate file_name.apk查找您要查找的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM