60

The Termux app is a terminal emulator. If I create a file or a folder there, and then use another file explorer app to browse my device, where can I find these files?

4
  • 6
    /data/data/com.termux/files/home ??
    – beeshyams
    Commented Jan 11, 2017 at 9:11
  • If you're looking for other folders, they're probably in /storage/emulated/0. For example /storage/emulated/0/Download (no "s") for your downloads or /storage/emulated/0/DCIM for your images.
    – user242634
    Commented Jul 17, 2019 at 2:01
  • @beeshyams that is what I got from the pwd command, but is it mounted? I didn't think apps could get access to the root directory, and terminal would have to read it to find out its pos. I assumed that terms mounted the data folder somewhere and cannot see past the mount.
    – Nate T
    Commented Jan 2, 2021 at 5:22
  • I was right. data is mounted inside Android folder, accessible from inside the file explorer..
    – Nate T
    Commented Jan 2, 2021 at 6:47

8 Answers 8

72

You don't need to root your device. All you need to do is run the following command on a non-rooted (or rooted) device to allow termux to access your existing directories, particularly /storage/emulated/0:

termux-setup-storage

this creates a new directory in termux, ~/storage, which contains simlinks to /storage/emulated/0 and can be accessed by a standard gui file manager.

You will need to grant file access to termux when prompted after you run the command.

See here.

4
  • 3
    This worked! Though I'll just point out to anyone who didn't pick up on it, that it's not the ~/storage directory itself that is /storage/emulated/0, but that location is rather the symlink ~/storage/shared. Hence putting things into ~/storage directory wouldn't help you access the files. Commented Aug 27, 2019 at 6:10
  • Where can I access that file in USB mode? I need to edit the extra key config file. I don't have ctrl key now, can't do much via termux
    – otong
    Commented Aug 19, 2020 at 4:36
  • This worked for me also after I ran pkg install termux-am as mentioned from this issue. This comment also mentions another install that I believed I installed once too that has helped with this issue as well
    – kyrlon
    Commented Dec 29, 2023 at 16:32
  • The termux-setup-storage script fails on my newly-installed F-Droid Termux on a Pixel 8a. I get the error message /data/data/com.termux/files/usr/bin/termux-setup-storage: line 29: 16813 Aborted am broadcast --user 0 --es com.termux.app.reload_style storage -a com.termux.app.reload_style com.termux > /dev/null Is there a fix for this? Commented Jun 25 at 21:47
11

The default directory is: /data/data/com.termux/files/home.

Since Termux supports bash commands, user can run pwd to print current working directory.

Note: pwd is an acronym of print working directory.


Reference: Unix.SE - How to get current working directory?

6
  • 3
    Thanks... But my data directory is empty. My phone is not rooted... Does that matter?
    – Maxcot
    Commented Jan 11, 2017 at 9:22
  • 3
    @Maxcot Unfortunately, yes. The /data/ folder is only accessible to all if the phone is rooted. By default, only Termux can write & read that folder.
    – Andrew T.
    Commented Jan 11, 2017 at 9:26
  • 1
    @Maxcot you might want to copy (or move, but becareful) them to /sdcard if you want. Refer to this question on SO
    – Andrew T.
    Commented Jan 11, 2017 at 9:32
  • Termux help may provide a way out ( not tried by me)
    – beeshyams
    Commented Jan 11, 2017 at 11:44
  • What I don't understand is why I have access to the folders through termux, but not through any other app like ES File Explorer. It's like the permissions are dependant on the app, not the user.
    – Maxcot
    Commented Jan 11, 2017 at 19:24
9

Provided that you don't want to root your phone, it is possible to change permission for Termux (Settings->Applications->Termux->Permissions) and enable the Storage permission.

This way you are granted access to phone and sdcard storage and you can use it as superuser (mv, ls and other commands work as intended) in the application.

So, you can move or copy the files you need into internal storage.

2
  • 7
    You may also need to run termux-setup-storage in Termux to gain access to the SD Card or Internal Storage Commented Sep 13, 2017 at 5:42
  • This no longer works (on Pixel 8a) Settings->Applications->Termux->Permissions has no entry for Storage. The entry for Files doesn't appear to do anything useful. Has Storage been hidden somewhere else? Commented Jun 25 at 21:49
4

You can query the $HOME variable to find the "default folder" regardless of the terminal app you're using:

$ echo $HOME
/data/data/com.termux/files/home

screenshot

0
3

You can access the files inside the termux folder by simply doing this. (Without using any third-party app/rooting your device)

Step 1: Go to Downloads on your Device

Step 2: Go to the Appbar

Step 3: Scroll down till you find Termux

Step 4: Click on Termux and you can see your files

3

Termux has its default directory that's inaccessible to newbies. To verify this, on the CLI, type

$ pwd

and data/data/com.termux/files/home should appear.

To be able to manipulate your Android directory from Termux, on your Android device, go to Settings - Apps - Termux - Permissions - tap "Storage" on.

Now on the CLI, in Termux, type

$ cd /storage/emulated/0
$ pwd

and /storage/emulated/0 should appear.

You can as well create a new file in your local storage, type

$ echo hello world > MyFirstTermuxFile.txt

That's it. You can now play with your local device storage.

2

You can view it easily with Material file manager. https://www.learntermux.tech/2020/10/Termux-File-Manager.html Here is a guide I found useful to me.

2
  • Hi, whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. Consider editing to summarize the content and/or expand the answer.
    – Andrew T.
    Commented Apr 18, 2022 at 2:08
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
    – Chenmunka
    Commented Apr 18, 2022 at 7:05
1

You can touch it on data/data/com.termux/files/home. That's the default main directory of Termux.

It's impossible to find the file that you've created on Termux main directory as I mentioned above on your phone because it's not rooted on any device.

It works as sort of a server. By thereon data/data/com.texmux/files/home, which is the default main directory of Termux, you can already browse files, create files, manipulating them the same sort you're using your file manager

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .