Skip to content

Linux & shell: Create, copy, move, delete

13 Linux & shell commands: Create, copy, move, delete. Click a command to see what each part does.

Index
13 items
Click a command to see what each part does.

Create, copy, move, delete13

  • mkdir -p <path/to/dir>Create a folder (and parents) in one go

    What each part does

    1. mkdirmake directory
    2. -pcreate missing parent folders too; no error if it already exists
  • touch <file>Create an empty file / update its timestamp

    What each part does

    1. touchcreate the file if missing; if it exists, set its modified time to now
  • cp <src> <dest>Copy a file

    What each part does

    1. cpcopy
    2. <src>file to copy
    3. <dest>new file name, or a folder to copy into
  • cp -r <src-dir> <dest-dir>Copy a folder with everything in it

    What each part does

    1. -r--recursive: copy directories and their contents
  • cp -a <src> <dest>Copy keeping permissions, owner and times (backups)

    What each part does

    1. -a--archive: recursive + keep symlinks, permissions, ownership and timestamps
  • cp -i <src> <dest>Copy but ask before overwriting

    What each part does

    1. -i--interactive: prompt before overwriting an existing file
  • mv <old-name> <new-name>Rename a file or folder

    What each part does

    1. mvmove: within the same folder this is a rename
  • mv <file1> <file2> <dir>/Move files into a folder

    What each part does

    1. <file1> <file2>one or more sources
    2. <dir>/destination folder (the trailing / makes it clear it is a folder)

    Tip Add -i to be asked before overwriting, -n to never overwrite.

  • rm <file>Delete a fileCaution

    What each part does

    1. rmremove (no recycle bin: it is gone)
  • rm -i <files>Delete, but confirm each fileCaution

    What each part does

    1. -iprompt before every removal
  • rm -rf <dir>Delete a folder and everything in itDestructive

    What each part does

    1. -r--recursive: remove directories and their contents
    2. -f--force: never prompt, ignore files that don't exist
    3. <dir>double-check this path: there is no undo

    Tip Run ls <dir> first. Never run it with a variable that might be empty (rm -rf "$DIR/").

  • rmdir <dir>Delete an empty folder

    What each part does

    1. rmdirremove a directory only if it is empty (safe)
  • ln -s <target> <link-name>Create a symbolic link (shortcut)

    What each part does

    1. lnmake links
    2. -s--symbolic: a symlink pointing to <target> (without -s it makes a hard link)
    3. <target>the real file or folder
    4. <link-name>the shortcut to create

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…