Where to start First steps track · 15 stages
Linux Labs

cp — copy files and directories

cheat sheet · Ubuntu 24.04 · GNU coreutils 9.4 https://lab.dimsanych.ru/en/wiki/cp/

Cheat sheet

  • cp app.conf app.conf.bak a copy next to it, another name
  • cp app.conf /tmp/ into a directory, same name
  • cp a.txt b.txt docs/ several files into a directory
  • cp -r project project-copy a whole directory
  • cp -a /etc/nginx ~/nginx-backup keep permissions, owner, times
  • cp -i app.conf /etc/app.conf ask before overwriting
  • cp -n app.conf /etc/app.conf never overwrite an existing file
  • cp -u *.conf /srv/conf/ only if the source is newer
  • cp -v a.txt b.txt print what gets copied
  • cp -r project/. backup/ a directory's contents, not itself

Options

cp and mv share many options: -i, -n, -u, -v, -b, -t. Full list — man cp.

Loading…