{
    "mode": "man",
    "parameter": "sg",
    "section": "1",
    "url": "https://www.chedong.com/phpMan.php/man/sg/1/json",
    "generated": "2026-06-12T03:13:08Z",
    "synopsis": "sg [-] [group [-c ] command]",
    "sections": {
        "NAME": {
            "content": "sg - execute command as different group ID\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "sg [-] [group [-c ] command]\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "The sg command works similar to newgrp but accepts a command. The command will be executed\nwith the /bin/sh shell. With most shells you may run sg from, you need to enclose multi-word\ncommands in quotes. Another difference between newgrp and sg is that some shells treat newgrp\nspecially, replacing themselves with a new instance of a shell that newgrp creates. This\ndoesn't happen with sg, so upon exit from a sg command you are returned to your previous\ngroup ID.\n",
            "subsections": []
        },
        "CONFIGURATION": {
            "content": "The following configuration variables in /etc/login.defs change the behavior of this tool:\n",
            "subsections": [
                {
                    "name": "SYSLOG___SG___ENAB (boolean)",
                    "content": "Enable \"syslog\" logging of sg activity.\n"
                }
            ]
        },
        "FILES": {
            "content": "/etc/passwd\nUser account information.\n\n/etc/shadow\nSecure user account information.\n\n/etc/group\nGroup account information.\n\n/etc/gshadow\nSecure group account information.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "id(1), login(1), newgrp(1), su(1), gpasswd(1), group(5), gshadow(5).\n\n\n\nshadow-utils 4.8.1                           02/06/2024                                        SG(1)",
            "subsections": []
        }
    },
    "summary": "sg - execute command as different group ID",
    "flags": [],
    "examples": [],
    "see_also": [
        {
            "name": "id",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/id/1/json"
        },
        {
            "name": "login",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/login/1/json"
        },
        {
            "name": "newgrp",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/newgrp/1/json"
        },
        {
            "name": "su",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/su/1/json"
        },
        {
            "name": "gpasswd",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/gpasswd/1/json"
        },
        {
            "name": "group",
            "section": "5",
            "url": "https://www.chedong.com/phpMan.php/man/group/5/json"
        },
        {
            "name": "gshadow",
            "section": "5",
            "url": "https://www.chedong.com/phpMan.php/man/gshadow/5/json"
        }
    ],
    "tldr": {
        "source": "official",
        "description": "Ast-grep is a tool for code structural search, lint, and rewriting.",
        "examples": [
            {
                "description": "Scan for possible queries using interactive mode",
                "command": "sg scan --interactive"
            },
            {
                "description": "Rewrite code in the current directory using patterns",
                "command": "sg run --pattern '{{foo}}' --rewrite '{{bar}}' --lang {{python}}"
            },
            {
                "description": "Visualize possible changes without applying them",
                "command": "sg run --pattern '{{useState<number>($A)}}' --rewrite '{{useState($A)}}' --lang {{typescript}}"
            },
            {
                "description": "Output results as JSON, extract information using `jq` and interactively view it using `jless`",
                "command": "sg run --pattern '{{Some($A)}}' --rewrite '{{None}}' --json | jq '{{.[].replacement}}' | jless"
            }
        ]
    }
}