Hi, I saw that micropython REPl has a %cd command, what are the other commands starting…
- User
Hi, I saw that micropython REPl has a %cd command, what are the other commands starting with % ?
- Assistant
In MicroPython's REPL, especially on some ports like the ESP32 or Unix port, there are "magic commands" starting with
%that provide handy functions to interact with the filesystem or the environment more easily. These magic commands behave somewhat like shell commands integrated into the REPL.Common
%Magic Commands in MicroPython REPL:-
%cd [path]
Change the current working directory topath. Without arguments, it shows the current directory. -
%ls [path]
List files and directories in the given directory (or current directory if none specified). -
%cp src dest
Copy a file fromsrctodest. -
%mv src dest
Move or rename a file fromsrctodest. -
%rm path
Remove/delete the file atpath. -
%mkdir path
Create a new directory atpath. -
%rmdir path
Remove the directory atpath(usually must be empty). -
%pwd
Show the current working directory.
Notes:
-
These commands are not part of the core MicroPython language, but rather helper commands implemented in some ports/repls or can be added via tools like
mpy-utilsor customized REPL environments. -
Not all MicroPython ports support them by default.
-
The exact list may vary depending on the MicroPython port and the firmware build.
How to check available magic commands in your MicroPython REPL?
If your firmware supports them, typing
%followed by pressingTabmight show hints/autocompletions of available magic commands.Alternatively, check the documentation for your specific MicroPython port or firmware.
If you want, I can help you write code that implements your own magic commands inside the REPL!
-
- User
please show micropython documentation for this
- Assistant
MicroPython itself does not officially document
%-prefixed "magic" commands like%cd,%ls, etc. as part of its core language or REPL interface.These commands are typically provided by extended REPL environments, tools, or specific port implementations, and are .
- User
yes please
- Assistant