Skip to content

Instantly share code, notes, and snippets.

@empjustine
Created November 16, 2025 18:02
Show Gist options
  • Select an option

  • Save empjustine/e977aeaeacf912371717271693ce71b5 to your computer and use it in GitHub Desktop.

Select an option

Save empjustine/e977aeaeacf912371717271693ce71b5 to your computer and use it in GitHub Desktop.
Usage: termux-saf-create [-t mime-type] folder-uri name
Creates a file in a folder managed by Termux:API.
Returns the URI you can use to read and write the file with termux-saf-read and termux-saf-write.
You can specify the mime type explicitly or let it be guessed based on the file extension.
As the folder URI you can use the URI of a directory listed by termux-saf-dirs or by termux-saf-ls.
Android doesn't allow creating files with the same name, so the name may be changed if a file or folder with that name already exists.
You can use termux-saf-stat with the returned URI to get the name it was really given.
-h show this help
-t specify the mime type of the file. The mime type is required for other apps to recognize the content as e.g. a video. If not specified, 'application/octet-stream' is assumed, that means raw binary data.
Usage: termux-saf-dirs
Lists all directories you gave Termux:API in the same format as termux-saf-ls.
That meas this lists the 'directory' that contains all directories you can access with the other termux-saf-* commands.
The URIs can be used with the other termux-saf-* commands to create files and folders and list the directory contents.
See termux-saf-managedir to give Termux:API access to a folder.
-h show this help
Usage: termux-saf-ls folder-uri
Lists the files and folders in a folder identified by a URI.
You can get a folder URI by:
- Listing folders with termux-saf-ls
- Giving Termux:API access to folders with termux-saf-managedir
- Listing the folders you gave Termux:API access to with termux-saf-dirs
- Creating a folder with termux-saf-mkdir
The list is returned as a JSON array with one JSON object per entry.
The objects have the keys:
- 'name' for the human-readable name
- 'uri' for URI you can use with the other termux-saf-* commands
- 'type' for the mime type
- 'length' for size in bytes if it's a file
You can recognize folders by the special mime type 'vnd.android.document/directory'.
-h show this help
Usage: termux-saf-managedir
Opens the system file explorer and lets you specify a folder Termux:API get access to.
You can then use the termux-saf-* utilities to manage the contents in that folder.
Returns a URI identifying the directory, this URI can be used with the other termux-saf-* commands to create files and folders and list the directory contents.
If you close the file manager instead, an empty string will be returned.
You can use termux-saf-dirs to list out all directories you gave Termux:API access to like this.
-h show this help
Usage: termux-saf-mkdir parent-uri name
Creates a directory via SAF.
This behaves like termux-saf-create, just for directories.
-h show this help
Usage: termux-saf-read uri
Reads from a file identified by a URI and writes the data to sstandard output.
You can use pipes to process the data or redirect it into a file to make a local copy.
See termux-saf-list to get the URIs to files.
-h show this help
Usage: termux-saf-rm uri
Removes the file or folder at the given URI. See other termux-saf-* commands for more info.
Returns 0 on success, 1 if the file or folder couldn't be deleted and 2 if another error occurred.
-h show this help
Usage: termux-saf-stat uri
Returns the file or folder info as a JSON object.
The format is the same as an entry from termux-saf-ls.
-h show this help
Usage: termux-saf-write uri
Writes the standard input into an existing file identified by a URI. The previous contents are erased. To create a new file, use termux-saf-create.
-h show this help
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment