This document relates to MEGAcmd version 0.9.9. It contains introductory information and the [Command Summary](#command-summary), with links to detailed command descriptions.
### What is it
A command line tool to work with your MEGA account and files. The intent is to offer all the MEGA account functionality via command line. You can run it in [interactive](#interactive) mode where it processes all commands directly, or you can run its [scriptable](#scriptable) commands from your favourite Linux or Mac shell such as bash, or you can even run its commands in a Windows command prompt. And of course you can write scripts using those scriptable commands.
Here is an example of downloading a file using MEGAcmd. In this case we are downloading a file specified by a public link, which does not require being logged in: <p>
mega-export -a /exportedstuff/temporary_resource --expire=10M | awk '{print $4}'
```
And here is an example of the power of using [scriptable](#scriptable) MEGAcmd commands in bash. In this case we are going to share some promotional videos previously uploaded to MEGA: <p>
```
for i in $(mega-find /enterprise/video/promotional2015/may --pattern="*mpeg")
do
mega-export -a $i | awk '{print $4}';
done
```
In addition to running commands on request, MEGAcmd can also be configured to [synchronise](#synchronisation-configurations) folders between your local device and your MEGA account, or perform regular [backups](#backup-configurations) from your device to your MEGA account.
In order to enable synchronisation and backup features, and for efficiency running commands, MEGAcmd runs a server process in the background which the MEGAcmd shell or the script commands forward requests to. The server keeps running in the background until it is told to close with the [`quit`](#quit) command. If you want it to keep running when you quit the interactive shell (to keep sync and backup runnign for example), use `quit --only-shell`.
Working with your MEGA account requires signing in with your email and password using the [`login`](#login) command, though you can download public links or upload to public folders without logging in. Logging in with your username and password starts a [Session](#session), and causes some of your account such as the folder structure to be downloaded to your [Local Cache](#local-cache).
### Where can you get it
For Linux, Mac, or Windows: Download it from the MEGA.nz website: https://mega.nz/cmd <p>
We are also building it for some NAS systems, please check your provider's App Store.
### What can you do with it
The major features are
* Move files around inside your MEGA account or between MEGA and your PC using command line tools.
* Use those same commands in scripts to manage your files.
* Set up synchronization or a backup schedule between a folder on your machine, and a folder on your MEGA account. (use the [`sync`](#sync) or [`backup`](#backup) commands)
* Set up WebDAV access to files in your MEGA account (use the [`webdav`](#webdav) command)
See our Help Centre pages for the basics of getting started, and friendly examples of common usages with plenty of pictures: https://mega.nz/help
## Terminology and Descriptions
### Interactive
Interactive refers to running the MEGAcmd shell which only processes MEGA commands. You invoke commands by typing and pressing Enter. MEGAcmd shell provides a lot of feedback about what it's doing. You can start the MEGAcmd shell with `mega-cmd` (or `MEGAcmd` on Windows). You can then issue commands like `ls` directly: <p>
`ls /my/account/folder`<p>
or you can get a list of available commands with: <p>
`help`<p>
or you can get detailed information about any particular command by using the `--help` flag with that command:<p>
`ls --help`<p>
Autocompletion (pressing tab to fill in the remainder of a command) is available in interactive mode.
### Scriptable
Scriptable refers to running the MEGAcmd commands from a shell such as bash or the windows powershell. If the PATH to the MEGAcmd commands are not yet on the PATH in that shell, you'll need to add it. You can then issue commands like `ls` by prefixing them with the `mega-` prefix: <p>
`mega-ls /my/account/folder`<p>
or you can get a list of available commands with: <p>
`mega-help`<p>
or you can get detailed information about any particular command by using the `--help` flag with that command:<p>
`mega-ls --help`<p>
Scriptable commands can of course be used in scripts to achieve a lot in a short space of time, using loops or preparing all the desired commands ahead of time.
If you are using bash as your shell, the MEGAcmd commands support auto-completion.
### Contact
A contact is someone (identified by their email address) that also has a MEGA account, who you can share files or folders with, and can chat with on MEGAchat.
### Remote Path
This refers to a file or a folder stored in your MEGA account, or a publicly available file or folder in the MEGA cloud. Remote paths always use the '/' character as the separator between folder and file elements.
Some MEGAcmd commands allow the use of regular expressions in remote paths. You can check if the command supports those by using the `--help` flag with the command. If you use these in the [scriptable](#scriptable) way, you need to escape characters that would otherwise be intercepted and interpreted by the shell.
This refers to a file or folder on the PC or device that MEGAcmd is running in.
### Session
When you log in with your email and MEGA account password, that creates a session. The session exists until you log out of it or kill it from another client. In MEGAcmd, use `whoami -l` to see all your open sessions across all devices, and use `killsession` to close them. You can use other MEGA clients such as the phone app, or webclient to close these also. Devices that were using a killed session will have their connection to MEGA closed immediately and will no longer have access to your account, until you log in on them again. Syncs, backups, and webdavs are specific to a session, so logging out will cause them to be cancelled.
### Local Cache
Logging in with MEGAcmd creates your Local Cache, a subfolder of your home folder. MEGAcmd downloads and stores some data in your Local Cache relating to your account, such as folder structure and contacts, for performance reasons. The MEGAcmd background server keeps the local cache up to date when changes to your account occur from other clients. The cache does contain a way for MEGAcmd to access your MEGA account when it starts up again if you have not specifically logged out. The Local Cache also contains information from your Session, including sync, backup, and webdav configurations. Logging out cleans the Local Cache, but also closes your session and the sync, backup, and webdav configurations are wiped.
### Synchronisation configurations
MEGAcmd can set up a synchronisation between a folder on your local machine and a folder in your MEGA account, using the [`sync`](#sync) command. This is the same mechanism that MEGAsync uses. The synchronisation is two-way: the folders you nominate to be synced will mirror any action! Whatever you add or delete in your sync folder on your device gets added or deleted in your sync folder in your MEGA account. And additions or deletions in your synced folder in your MEGA account will similarly be applied to your local synced folder. Files that are removed from sync folders are moved to a hidden local folder (Rubbish/.debris inside your local sync folder, or SyncDebris folder in the Rubbish Bin of your MEGA account).
Here is a very simple example of setting up a synchronisation with MEGAcmd: <p>
```
sync /path/to/local/folder /folder/in/mega
```
You can set up more than one pair or folders to be synced, and you can also set a sync from another device to the same folder, to achieve folder synchronisations between different devices. The changes are sent via your MEGA account rather than directly between the devices in that case.
Additional information about synchronising folders is available in our Help Centre: https://mega.nz/help/client/megasync/syncing
### Backup configurations
MEGAcmd can set up a periodic copy of a local folder to your MEGA account using the [`backup`](#backup) command. Here is a simple example that will back up a folder immediately and then at 4am each day, keeping the 10 most recent backups: <p>
For further information on backups, please see the [`backup`](#backup) command and the [tutorial](contrib/docs/BACKUPS.md).
### WebDAV configurations
MEGAcmd can set up access to folders or files in your MEGA account as if they were local folders and files on your device using the [`webdav`](#webdav) command. For example making the folder appear like a local drive on your PC, or providing a hyperlink a browser can access, where the hyperlink is to your PC.
For further information on WebDAV, please see the [`webdav`](#webdav) command and the [tutorial](contrib/docs/WEBDAV.md).
### Linux
On Linux, MEGAcmd commands are installed at /usr/bin and so will already be on your PATH. The interactive shell is `mega-cmd` and the background server is `mega-cmd-server`, which will be automatically started on demand. The various scriptable commands are installed at the same location, and invoke `mega-exec` to send the command to `mega-cmd-server`.
If you are using the scriptable commands in bash (or using the interactive commands in mega-cmd), the commands will auto-complete.
### Macintosh
For MacOS, after installing the dmg, you can launch the server using **MEGAcmd** in Applications. If you wish to use the client commands from MacOS Terminal, open the Terminal and include the installation folder in the PATH.<p>
Once you have MEGAcmd installed, you can start the [interactive](#interactive) shell from the Start Menu or desktop icon. On windows the interactive shell executable is called `MEGAcmdShell.exe` and the server is `MEGAcmdServer.exe`.
On Windows 7, we recommend using the MEGAcmd shell from inside PowerShell for a better user experience (and you can do this on other Windows platforms also). You can start powershell from the Start Menu and then execute these commands to start it:
```
$env:PATH += ";$env:LOCALAPPDATA\MEGAcmd"
MEGAcmdShell
```
For [scriptable](#scriptable) usage, the MEGAcmd commands are provided via installed .bat files which pass the command to the MEGAcmdServer.exe. Provided you have set the PATH as above, you can use these like normal command line tools in PowerShell:
```
$env:PATH += ";$env:LOCALAPPDATA\MEGAcmd"
mega-cd /my/favourite/folder
mega-ls
```
Or in Command Prompt:
```
set PATH=%LOCALAPPDATA%\MEGAcmd;%PATH%
mega-cd /my/favourite/folder
mega-ls
```
And of course those can be invoked in your own .bat or .cmd files.
Autocompletion is not available for the scriptable commands, but is in the interactive shell.
Unicode is supported though it currently in the interactive shell it needs to be switched on, and to have a suitable font selected; please execute `help --unicode` for the latest information. There are plans to improve this. Please report any issues experienced to our support team.
We have released packages for QNAP and Synology, which you can download and install from the App Center in QNAP, and the Package Center in Synology. In QNAP, please make sure to turn on "Enable home folder for all users" from the control panel, and set HOME=/share/homes/<username> before starting any MEGA commands, and in Synology, 'Enable user home service', so that the `mega-cmd-server` creates the `.megaCmd` local cache folder there (as the default HOME location may be erased on restart).
These summaries use the usual conventions - `[]` indicates its content is optional, `|` indicates you should choose either the item on the left or the one on the right (but not both)
Each command is described as it would be used in the [interactive](#interactive) MEGAcmd shell, and the corresponding [scriptable](#scriptable) command (which must be prefixed with `mega-`) works in the same way.
Commands referring to a [remote path](#remote-path) are talking about a file in your MEGA account online, whereas a [local path](#local-path) refers to a file or folder on your local device where MEGAcmd is running.
Verbosity: You can increase the amount of information given by any command by passing `-v` (`-vv`, `-vvv`, ...)
### Account / Contacts
* [`signup`](#signup)`email [password] [--name="Your Name"]` Register as user with a given email.
* [`confirm`](#confirm)`link email [password]` Confirm an account using the link provided after the "signup" process.
* [`invite`](#invite)`[-d|-r] dstemail [--message="MESSAGE"]` Invites a contact / deletes an invitation.
* [`showpcr`](#showpcr)`[--in | --out]` Shows incoming and outgoing contact requests.
* [`exclude`](#exclude)`[(-a|-d) pattern1 pattern2 pattern3 [--restart-syncs]]` Manages exclusions in syncs.
* [`backup`](#backup)`localpath remotepath --period="PERIODSTRING" --num-backups=N` Set up a new backup folder and/or schedule
* [`backup`](#backup)`[-lhda] [TAG|localpath] [--period="PERIODSTRING"] [--num-backups=N])` View/Modify an existing backup schedule
### Sharing (your own files, of course, without infringing any copyright)
* [`cp`](#cp)`srcremotepath dstremotepath|dstemail` Moves a file/folder into a new location (all remotes)
* [`export`](#export)`[-d|-a [--expire=TIMEDELAY]] [remotepath]` Prints/Modifies the status of current exports
* [`import`](#import)`exportedfilelink#key [remotepath]` Imports the contents of a remote link into your account
* [`share`](#share)`[-p] [-d|-a --with=user@email.com [--level=LEVEL]] [remotepath]` Prints/Modifies the status of current shares
* [`webdav`](#webdav)`[ [-d] remotepath [--port=PORT] [--public] [--tls --certificate=/path/to/certificate.pem --key=/path/to/certificate.key]]` Sets up the ability to download a file from your MEGA account via your PC/device.
### Misc
* [`version`](#version)`[-l][-c]` Prints MEGAcmd versioning and extra info
* [`deleteversions`](#deleteversions)` [-f] (--all | remotepath1 remotepath2 ...)` Delete prior versions of files to save space.
* [`unicode`](#unicode) Toggle unicode input enabled/disabled in interactive shell
* [`reload`](#reload) Forces a reload of the remote files of the user
* [`help`](#help)`[-f]` Prints list of commands
* [`https`](#https)`[on|off]` Shows if HTTPS is used for transfers. Use `https on` to enable it.
* [`clear`](#clear) Clear screen
* [`log`](#log)`[-sc] level` Prints/Modifies the current logs level
This command can be used to configure which folders to back up, and how often to do so.
If no argument is given it will list the configured backups.
To get extra info on backups use -l or -h (see Options below)
When a backup of a folder (localfolder) is established in a remote folder (remotepath)
MEGAcmd will create subfolder within the remote path with names like: "localfoldername_bk_TIME"
which shall contain a backup of the local folder at that specific time
In order to configure a backup you need to specify the local and remote paths,
the period and max number of backups to store (see Configuration Options below).
Once configured, you can see extended info asociated to the backup (See Display Options)
Notice that MEGAcmd server need to be running for backups to be created.
Display Options:
-l Show extended info: period, max number, next scheduled backup
or the status of current/last backup
-h Show history of created backups
Backup states:
While a backup is being performed, the backup will be considered and labeled as ONGOING
If a transfer is cancelled or fails, the backup will be considered INCOMPLETE
If a backup is aborted (see -a), all the transfers will be canceled and the backup be ABORTED
If MEGAcmd server stops during a transfer, it will be considered MISCARRIED
Notice that currently when MEGAcmd server is restarted, ongoing and scheduled transfers
will be carried out nevertheless.
If MEGAcmd server is not running when a backup is scheduled and the time for the next one has already arrived, an empty BACKUP will be created with state SKIPPED
If a backup(1) is ONGOING and the time for the next backup(2) arrives, it won't start untill the previous one(1)
is completed, and if by the time the first one(1) ends the time for the next one(3) has already arrived,
an empty BACKUP(2) will be created with state SKIPPED
--path-display-size=N Use a fixed size of N characters for paths
Configuration Options:
--period="PERIODSTRING" Period: either time in TIMEFORMAT (see below) or a cron like expresisions
Cron like period is formatted as follows
- - - - - -
| | | | | |
| | | | | |
| | | | | +---- Day of the Week (range: 1-7, 1 standing for Monday)
| | | | +------ Month of the Year (range: 1-12)
| | | +-------- Day of the Month (range: 1-31)
| | +---------- Hour (range: 0-23)
| +------------ Minute (range: 0-59)
+-------------- Second (range: 0-59)
examples:
- daily at 04:00:00 (UTC): "0 0 4 * * *"
- every 15th day at 00:00:00 (UTC) "0 0 0 15 * *"
- mondays at 04.30.00 (UTC): "0 30 4 * * 1"
TIMEFORMAT can be expressed in hours(h), days(d),
minutes(M), seconds(s), months(m) or years(y)
e.g. "1m12d3h" indicates 1 month, 12 days and 3 hours
Notice that this is an uncertain measure since not all months
last the same and Daylight saving time changes are not considered
If possible use a cron like expresion
Notice: regardless of the period expresion, the first time you establish a backup,
-f Implicitly accepts copyright terms (only shown the first time an export is made).
MEGA respects the copyrights of others and requires that users of the MEGA cloud service comply with the laws of copyright.
You are strictly prohibited from using the MEGA cloud service to infringe copyright.
You may not upload, download, store, share, display, stream, distribute, email, link to, transmit or otherwise make available any files, data or content that infringes any copyright or other proprietary rights of any person or entity.
If the remotepath is a file, it will be downloaded to folder specified in localpath (or to the current folder if not specified).
If the localpath (destination) already exists and is the same (by content) then nothing will be done. If it differs, it will create a new file appending " (NUM)".
If the remotepath or exportedlink is a folder, the folder and its entire contents will be downloaded into the destination folder.
Options:
-q queue download: execute in the background.
-m if the folder already exists, the contents will be merged with the downloaded one (preserving the existing files)
--ignore-quota-warn ignore quota surpassing warning. The download will be attempted anyway.
</pre>
### help
Prints list of commands
Usage: `help [-f]`
<pre>
Options:
-f Include a brief description of the commands
</pre>
### https
Shows if HTTPS is used for transfers. Use `https on` to enable it.
Usage: `https [on|off]`
<pre>
HTTPS is not necesary since all data is already encrypted before being stored or transfered anyway.
Enabling it will increase CPU usage and add network overhead.
This setting is ephemeral: it will reset for the next time you open MEGAcmd
</pre>
### import
Imports the contents of a remote link into your MEGA account or to a local folder. ([example](#export-import-example))
Usage: `import exportedfilelink#key [remotepath]`
<pre>
If no remote path is provided, the current local folder will be used
</pre>
### invite
Invites a contact / deletes an invitation ([example](#signup-confirm-invite-showpcr-ipc-users-userattr-example))
-i Ignores invitation [WARNING: do not use unless you know what you are doing]
</pre>
### killsession
Kills a session of current user.
Usage: killsession [-a|sessionid]
<pre>
Options:
-a kills all sessions except the current one
To see all sessions use "whoami -l"
</pre>
### lcd
Changes the current local folder for the interactive console
Usage: lcd [localpath]
<pre>
It will be used for uploads and downloads
If not using interactive console, the current local folder will be that of the shell executing mega comands
</pre>
### log
Prints/Modifies the setting for how detailed log output is.
Usage: log [-sc] level
<pre>
Options:
-c CMD log level (higher level messages).
Messages captured by MEGAcmd server.
-s SDK log level (lower level messages).
Messages captured by the engine and libs
Regardless of the log level of the interactive shell, you can increase the amount of information given by any command by passing `-v` (`-vv`, `-vvv`, ...)
</pre>
### login
Log into your MEGA account ([example](#login-logout-whoami-mkdir-cd-get-put-du-mount-example))
You can log in either with email and password, with session ID, or into a folder (an exported/public folder).
If logging into a folder indicate url#key
</pre>
### logout
Closes your session for security or to allow subsequently logging into a different account. ([example](#login-logout-whoami-mkdir-cd-get-put-du-mount-example))
Usage: logout [--keep-session]
<pre>
Options:
--keep-session The current session is not closed, allowing logging back into it later using the session ID rather than email/password.
MEGAcmd will still log back into your account automatically on restart if you specify --keep-session, similar to exiting it without logging out.
</pre>
### lpwd
Prints the current local folder for the interactive console
Usage: `lpwd`
<pre>
It will be used for uploads and downloads
If not using interactive console, the current local folder will be
that of the shell executing mega comands
</pre>
### ls
Usage: `ls [-halRr] [--versions] [remotepath]`
Lists files in a remote path
<pre>
remotepath can be a pattern (it accepts wildcards: ? and *. e.g.: f*00?.txt)
Also, constructions like /PATTERN1/PATTERN2/PATTERN3 are allowed
Options:
-R|-r list folders recursively
-l print summary
SUMMARY contents:
FLAGS: Indicate type/status of an element:
xxxx
|||+---- Sharing status: (s)hared, (i)n share or not shared(-)
||+----- if exported, whether it is (p)ermanent or (t)temporal
--with=email Determines the email of the user to [no longer] share with
-d Stop sharing with the selected user
-a Adds a share (or modifies it if existing)
--level=LEVEL Level of acces given to the user
0: Read access
1: Read and write
2: Full access
3: Owner access
If a remote path is given it'll be used to add/delete or in case of no option selected, it will display all the shares existing in the tree of that path
When sharing a folder with a user that is not a contact (see "users --help") the share will be in a pending state. You can list pending shares with `share -p`. Your contact will need to accept your invitation (see [`ipc`](#ipc))
If someone has shared something with you, it will be listed as a root folder.
Use [`mount`](#mount) to list folders shared with you
</pre>
### showpcr
Shows incoming and outgoing contact requests. ([example](#signup-confirm-invite-showpcr-ipc-users-userattr-example))
Usage: `showpcr [--in | --out]`
<pre>
Options:
--in Shows incoming requests
--out Shows outgoing invitations
</pre>
### signup
Register as user with a given email ([example](#signup-confirm-invite-showpcr-ipc-users-userattr-example))
List contacts ([example](#signup-confirm-invite-showpcr-ipc-users-userattr-example))
Usage: `users [-s] [-h] [-n] [-d contact@email]`
<pre>
Options:
-s Show shared folders with listed contacts
-h Show all contacts (hidden, blocked, ...)
-n Show users names
-d contact@email Deletes the specified contact
</pre>
### version
Prints MEGAcmd versioning and extra info
Usage: `version [-l][-c]`
<pre>
Options:
-c Shows changelog for the current version
-l Show extended info: MEGA SDK version and features enabled
</pre>
### webdav
Configures a WEBDAV server to serve a location in MEGA. You can use feature to make a folder in your MEGA account appear as a virtual drive, or to stream files.
This can also be used for streaming files. The server will be running as long as MEGAcmd Server is.
If no argument is given, it will list the webdav enabled locations.
Options:
--d Stops serving that location
--public *Allow access from outside localhost
--port=PORT *Port to serve. DEFAULT= 4443
--tls *Serve with TLS (HTTPS)
--certificate=/path/to/certificate.pem *Path to PEM formated certificate
--key=/path/to/certificate.key *Path to PEM formated key
*If you serve more than one location, these parameters will be ignored and use those of the first location served.
Webdav setup is associated with your Session, so logging out will cancel them.
Caveat: This functionality is in BETA state. If you experience any issue with this, please contact: support@mega.nz
</pre>
### whoami
Print account information ([example](#login-logout-whoami-mkdir-cd-get-put-du-mount-example))
Usage: `whoami [-l]`
<pre>
Options:
-l Show extended info: total storage used, storage per main folder
(see mount), pro level, account balance, and also the active sessions
</pre>
## Examples
### signup confirm invite showpcr ipc users userattr example
<pre>
MEGA CMD> <b>signup eg.email_1@example.co.nz --name="test1"</b>
New Password:
Retype New Password:
Account <eg.email_1@example.co.nz> created succesfully. You will receive a confirmation link. Use "confirm" with the provided link to confirm that account
MEGA CMD> <b>confirm https://mega.nz/#confirmQFSfjtUkExc5M2Us6q5d-klx60Rfx<REDACTED>Vbxjhk eg.email_1@example.co.nz</b>
Password:
Account eg.email_1@example.co.nz confirmed succesfully. You can login with it now
MEGA CMD> <b>signup eg.email_2@example.co.nz --name="test2"</b>
New Password:
Retype New Password:
Account <eg.email_2@example.co.nz> created succesfully. You will receive a confirmation link. Use "confirm" with the provided link to confirm that account
MEGA CMD> <b>confirm https://mega.nz/#confirmcz7Ss68ChhMKk8WEFTQCqLMHJg8es<REDACTED>AEEpQE eg.email_2@example.co.nz</b>
Password:
Account eg.email_2@example.co.nz confirmed succesfully. You can login with it now
MEGA CMD> <b>login eg.email_1@example.co.nz</b>
Password:
[API:info: 23:19:14] Fetching nodes ...
[API:info: 23:19:17] Loading transfers from local cache
[API:info: 23:19:17] Login complete as eg.email_1@example.co.nz
eg.email_1@example.co.nz:/$ <b>export -a Pictures/</b>
MEGA respects the copyrights of others and requires that users of the MEGA cloud service comply with the laws of copyright.
You are strictly prohibited from using the MEGA cloud service to infringe copyrights.
You may not upload, download, store, share, display, stream, distribute, email, link to, transmit or otherwise make available any files, data or content that infringes any copyright or other proprietary rights of any person or entity. Do you accept this terms? (Yes/No): Yes
Session closed but not deleted. Warning: it will be restored the next time you execute the application. Execute "logout" to delete the session permanently.
You can also login with the session id: ARo7aiLAxK-jseOdVBYhj285Twb06ivWsFmT4XAnkTsiaDRRbm5oYS1zRm-V3I0FHHOvwj7P2RPvrSw_
MEGA CMD> <b>login eg.email_2@example.co.nz</b>
Password:
[API:info: 01:55:04] Fetching nodes ...
[API:info: 01:55:05] Loading transfers from local cache
[API:info: 01:55:05] Login complete as eg.email_2@example.co.nz