{
  "$type": "site.standard.document",
  "canonicalUrl": "https://rednafi.com/misc/install/",
  "description": "Replace mkdir, cp, and chmod with a single install command. Copy files, create directories, and set permissions in one step with GNU coreutils.",
  "path": "/misc/install/",
  "publishedAt": "2024-07-28T00:00:00.000Z",
  "site": "at://did:plc:fgtm2c26vfcj74rfmeggbyqj/site.standard.publication/3mnl6f7ob462z",
  "tags": [
    "Shell",
    "Unix",
    "TIL",
    "CLI"
  ],
  "textContent": "TIL about the install command on \\*nix systems. A quick [GitHub search for the term]\nbrought up a ton of matches. I'm surprised I just found out about it now.\n\nOften, in shell scripts I need to:\n\n- Create a directory hierarchy\n- Copy a config or binary file to the new directory\n- Set permissions on the file\n\nIt usually looks like this:\n\nTurns out, the install command in [GNU coreutils] can do all that in one line:\n\nYou can check the file status with:\n\nOn my machine, this prints:\n\nThe -D flag directs install to create the destination directories if they don't exist,\nand the -m flag sets file permissions. The result is the same as the three lines of\ncommands before.\n\nIt's common for Makefiles in C/C++ projects to install binaries like this:\n\nIt copies app_bin to /usr/local/bin, creates the parent directory hierarchy if\nnecessary, and sets permissions on the binary so only the current user has read, write, and\nexecute permissions, while others have read-only access.\n\nYou can also set directory permissions:\n\nThis creates the directory hierarchy first and then sets the permission. Here's how they\nlook:\n\nOutput:\n\nThen you can copy a file to the destination and set file permissions with another install\ncommand if needed.\n\nYou can also set user or group ownership while copying a file:\n\nThis command copies seed.db to the destination, creates the directory if needed, and gives\naccess to the root user and group with the -o and -g flags, respectively.\n\nThere are a few other options you can read about in the man pages, but I haven't needed\nanything beyond the above.\n\n\n\n\n[github search for the term]:\n    https://github.com/search?q=%22install+-D%22++language%3Ash+NOT+npm&type=code\n\n[gnu coreutils]:\n    https://www.gnu.org/software/coreutils/manual/html_node/install-invocation.html#install-invocation",
  "title": "The *nix install command"
}