import re


def clean_cmd(cmd):
    """Removes multiple spaces and whitespace at beginning or end of command.

    Args:
        cmd (str): A string containing the command to clean.

    Returns:
        A cleaned command string.
    """

    return re.sub(r'\s{2, }', ' ', cmd).strip(' \t\n\r')