Skip to content

MEGA CMD

Source: MEGAcmd/UserGuide.md · meganz/MEGAcmd

This document relates to MEGAcmd version 0.9.9. It contains introductory information and the Command Summary, with links to detailed command descriptions.

Contents

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 mode where it processes all commands directly, or you can run its 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:

mega-get https://mega.nz/#F!ABcD1E2F!gHiJ23k-LMno45PqrSTUvw /path/to/local/folder 

And here is an example of uploading a file using MEGAcmd, and making a link available to share it, that will expire after 10 minutes.

mega-put /path/to/my/temporary_resource /exportedstuff/
mega-export -a  /exportedstuff/temporary_resource --expire=10M | awk '{print $4}'

And here is an example of the power of using scriptable MEGAcmd commands in bash. In this case we are going to share some promotional videos previously uploaded to MEGA:

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 folders between your local device and your MEGA account, or perform regular backups 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 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 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, and causes some of your account such as the folder structure to be downloaded to your Local Cache.

Where can you get it

For Linux, Mac, or Windows: Download it from the MEGA.nz website: https://mega.nz/cmd

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 or backup commands)
  • Set up WebDAV access to files in your MEGA account (use the webdav command)

See our Help Center 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:

ls /my/account/folder

or you can get a list of available commands with:

help

or you can get detailed information about any particular command by using the --help flag with that command:

ls --help

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 2-Areas/MOCs/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:

mega-ls /my/account/folder

or you can get a list of available commands with:

mega-help

or you can get detailed information about any particular command by using the --help flag with that command:

mega-ls --help

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 way, you need to escape characters that would otherwise be intercepted and interpreted by the shell.

Paths to folders shared to you from another person start with their email and a : character, see the example at (example)

Local Path

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.

Synchronization configurations

MEGAcmd can set up a synchronization between a folder on your local machine and a folder in your MEGA account, using the 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 synchronization with MEGAcmd:

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 Center: 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 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:

backup /path/mega/folder /remote/path --period="0 0 4 * * *" --num-backups=10

For further information on backups, please see the backup command and the tutorial.

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 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 command and the tutorial.

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.

Typically:

export PATH=/Applications/MEGAcmd.app/Contents/MacOS:$PATH

And for bash completion, source megacmd_completion.sh :

source /Applications/MEGAcmd.app/Contents/MacOS/megacmd_completion.sh

Windows

Once you have MEGAcmd installed, you can start the 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 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.

Command Summary

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 MEGAcmd shell, and the corresponding scriptable command (which must be prefixed with mega-) works in the same way.

Commands referring to a remote path are talking about a file in your MEGA account online, whereas a 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

  • signupemail [password] [--name="Your Name"] Register as user with a given email.
  • confirmlink email [password] Confirm an account using the link provided after the “signup” process.
  • invite[-d|-r] dstemail [--message="MESSAGE"] Invites a contact / deletes an invitation.
  • showpcr[--in | --out] Shows incoming and outgoing contact requests.
  • ipcemail|handle -a|-d|-i Manages contact incoming invitations.
  • users[-s] [-h] [-n] [-d contact@email] List contacts
  • userattr[-s attribute value|attribute] [--user=user@email] Lists/updates user attributes
  • passwd[oldpassword newpassword] Modifies user password
  • masterkeypathtosave Shows your master key.

Login / Logout

  • login[email [password]] | exportedfolderurl#key | session Logs into MEGA
  • logout[--keep-session] Logs out
  • whoami[-l] Print info of the user
  • session Prints (secret) session ID
  • killsession[-a|sessionid] Kills a session of current user.

Browse

  • cd[remotepath] Changes the current remote folder
  • lcd[localpath] Changes the current local folder for the interactive console
  • ls[-lRr] [remotepath] Lists files in a remote path
  • pwd Prints the current remote folder
  • lpwd Prints the current local folder for the interactive console
  • attrremotepath [-s attribute value|-d attribute] Lists/updates node attributes
  • du[-h] [remotepath remotepath2 remotepath3 ... ] Prints size used by files/folders
  • find[remotepath] [-l] [--pattern=PATTERN] [--mtime=TIMECONSTRAIN] [--size=SIZECONSTRAIN] Find nodes matching a pattern
  • mount Lists all the main nodes

Moving/Copying Files

  • mkdir[-p] remotepath Creates a directory or a directory hierarchy
  • cpsrcremotepath dstremotepath|dstemail Copies a file/folder into a new location (all remotes)
  • put[-c] [-q] [--ignore-quota-warn] localfile [localfile2 localfile3 ...] [dstremotepath] Uploads files/folders to a remote folder
  • get[-m] [-q] [--ignore-quota-warn] exportedlink#key|remotepath [localpath] Downloads a remote file/folder or a public link
  • preview[-s] remotepath localpath To download/upload the preview of a file.
  • thumbnail[-s] remotepath localpath To download/upload the thumbnail of a file.
  • mvsrcremotepath [srcremotepath2 srcremotepath3 ..] dstremotepath Moves file(s)/folder(s) into a new location (all remotes)
  • rm[-r] [-f] remotepath Deletes a remote file/folder
  • transfers[-c TAG|-a] | [-r TAG|-a] | [-p TAG|-a] [--only-downloads | --only-uploads] [SHOWOPTIONS] List or operate with transfers
  • speedlimit[-u|-d] [-h] [NEWLIMIT] Displays/modifies upload/download rate limits
  • sync[localpath dstremotepath| [-dsr] [ID|localpath] Controls synchronizations
  • exclude[(-a|-d) pattern1 pattern2 pattern3 [--restart-syncs]] Manages exclusions in syncs.
  • backuplocalpath remotepath --period="PERIODSTRING" --num-backups=N Set up a new backup folder and/or schedule
  • backup[-lhda] [TAG|localpath] [--period="PERIODSTRING"] [--num-backups=N]) View/Modify an existing backup schedule
  • cpsrcremotepath dstremotepath|dstemail Moves a file/folder into a new location (all remotes)
  • export[-d|-a [--expire=TIMEDELAY]] [remotepath] Prints/Modifies the status of current exports
  • importexportedfilelink#key [remotepath] Imports the contents of a remote link into your account
  • share[-p] [-d|-a --with=user@email.com [--level=LEVEL]] [remotepath] Prints/Modifies the status of current shares
  • 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[-l][-c] Prints MEGAcmd versioning and extra info
  • deleteversions [-f] (--all | remotepath1 remotepath2 ...) Delete prior versions of files to save space.
  • unicode Toggle unicode input enabled/disabled in interactive shell
  • reload Forces a reload of the remote files of the user
  • help[-f] Prints list of commands
  • https[on|off] Shows if HTTPS is used for transfers. Use https on to enable it.
  • clear Clear screen
  • log[-sc] level Prints/Modifies the current logs level
  • debug Enters debugging mode (HIGHLY VERBOSE)
  • exit|quit [--only-shell] Quits MEGAcmd

Backlinks:

list from [[Tool-Template]] AND -"Changelog"