termux中的linux 访问termux文件

https://blog.csdn.net/qq_35425070/article/details/86040270讲了termux中安装linux,现在我们来分析一下它是如何实现的。查看安装linux的路径下的文件

ls

发现多了一个叫做ubuntu的文件夹(文件名跟安装的linux系统有关),cd进去后发现里面的文件与startubuntu命令进入的系统文件相同,可以看出,他就是我们安装的linux,改动这里的内容就会对安装的linux产生影响,因为安装的linux就是这个文件夹。

我们知道了我们安装的系统的位置后,来看一下startubuntu命令干了什么

执行

$ cd ~/../usr/bin/
$ cat startubuntu

查看输出

#!/data/data/com.termux/files/usr/bin/bash
cd ~
unset LD_PRELOAD
command="proot"
command+=" --link2symlink"
command+=" -S ubuntu"
command+=" -b /sdcard"
command+=" -b /dev/"
command+=" -b /proc/"
#uncomment the following line to have access to the home directory of termux
#command+=" -b /data/data/com.termux/files/home"
command+=" -w /root"
command+=" /usr/bin/env -i"
command+=" HOME=/root"
command+=" PATH=/bin:/usr/bin:/sbin:/usr/sbin"
command+=" TERM=xterm-256color"
command+=" /bin/bash --login"
export PROOT_NO_SECCOMP=1
com="$@"
if [ -z "$1" ];then
    exec $command
else
    $command -c "$com"
fi

发现,其实这个脚本是帮我们把运行时的环境设置为ubuntu的环境,并新开启了一个命令行bash。

仔细查看里面的内容,还有一行注释,这行注释的意思是取消下面一行的注释,就可以在安装的linux中访问到termux的home目录。

从前几行可以看出 -b的参数其实是相当于在linux中挂载这个目录,同理,我们如果要在linux中访问QQ的下载文件,可以加一条命令:(想访问其他目录类似)

command+=" -b /data/data/com.termux/files/home/storage/shared/tencent/QQfile_recv"

修改上述命令前确保在termux中执行过

termux-setup-storage

执行该命令termux会弹框确认是否授权,执行这条命令确保termux在最前端(当前Activity)成功拿到存储权限后会在家目录生成storage目录,并且生成若干目录,软连接都指向外置存储卡的相应目录

下一篇: termux中安装linux之后要做的事情

扫描二维码关注公众号,回复: 4958286 查看本文章

猜你喜欢

转载自blog.csdn.net/qq_35425070/article/details/86041193