Terminal Tip 🤩 fcopy, fcut, fpaste

Published: (March 14, 2026 at 10:47 PM EDT)
2 min read
Source: Dev.to

Source: Dev.to

Introduction

If you are like me and love the terminal, start using fcopy, fcut, fpaste. Instead of copying through a file explorer, you can do:

fcopy some/file/
fcopy other/file/image.png

Then open another terminal and run:

fpaste

Functions

fcopy

fcopy() {
  if [ "$#" -eq 0 ]; then
    echo "fcopy: nothing to copy"
    return 1
  fi

  tmp="$(mktemp)"
  printf 'copy\n' > "$tmp"

  for item in "$@"; do
    if [ -e "$item" ]; then
      abs="$(realpath "$item")"
      printf '%s\n' "$abs" >> "$tmp"
      echo "copied to clipboard: $abs"
    else
      echo "fcopy: not found: $item" >&2
    fi
  done

  mv "$tmp" ~/.fileclip
}

fcut

fcut() {
  if [ "$#" -eq 0 ]; then
    echo "fcut: nothing to cut"
    return 1
  fi

  tmp="$(mktemp)"
  printf 'move\n' > "$tmp"

  for item in "$@"; do
    if [ -e "$item" ]; then
      abs="$(realpath "$item")"
      printf '%s\n' "$abs" >> "$tmp"
      echo "cut to clipboard: $abs"
    else
      echo "fcut: not found: $item" >&2
    fi
  done

  mv "$tmp" ~/.fileclip
}

fpaste

fpaste() {
  [ -f ~/.fileclip ] || { echo "fpaste: file clipboard is empty"; return 1; }

  mode="$(head -n1 ~/.fileclip)"
  count=0

  while IFS= read -r src; do
    [ -n "$src" ] || continue

    if [ ! -e "$src" ]; then
      echo "fpaste: source no longer exists: $src" >&2
      continue
    fi

    if [ "$mode" = "move" ]; then
      if mv -- "$src" .; then
        echo "moved: $src -> $PWD/"
        count=$((count + 1))
      else
        echo "fpaste: failed to move: $src" >&2
      fi
    else
      if cp -a -- "$src" .; then
        echo "pasted: $src -> $PWD/"
        count=$((count + 1))
      else
        echo "fpaste: failed to paste: $src" >&2
      fi
    fi
  done
}

Usage Summary

  • fcopy – copies the specified files or directories to a temporary clipboard.
  • fcut – moves the specified files or directories to the clipboard (cut operation).
  • fpaste – pastes the items from the clipboard into the current directory. If the clipboard was created with fcut, the items are moved; otherwise they are copied.

Add the functions to your shell configuration (e.g., ~/.bashrc or ~/.zshrc) and reload the shell.

0 views
Back to Blog

Related posts

Read more »

Getting Started with tmux

Introduction An introduction to tmux, a terminal multiplexer. Session Management - Start tmux bash tmux or tmux new-session - Create a new session within a ses...