What's the difference between 'cp -rvf /bin/ ./rmlater/' and 'cp -rvf /bin ./rmlater/'?

Say I’d like to copy the whole /bin into my ./rmlater folder

  • cp -rvf /bin/ ./rmalter works as what I want
  • But I just found, without the trailing slash of source, cp -rvf /bin ./rmalter gives only an empty folder
  • However when I tried another source folder without the trailing slash, cp -rvf ./Desktop ./rmlater/ and it still copys the files
debian$ cp -rvf /bin ./rmlater/
'/bin' -> './rmlater/bin'
debian$ find ./rmlater/
./rmlater/
./rmlater/bin
debian$ rm -rvf rmlater/*
removed 'rmlater/bin'
debian$ cp -rvf ./Desktop ./rmlater/
'./Desktop' -> './rmlater/Desktop'
'./Desktop/chrome_via_proxy.desktop' -> './rmlater/Desktop/chrome_via_proxy.desktop'
'./Desktop/chrome.desktop' -> './rmlater/Desktop/chrome.desktop'
...

So any expert could let me know what’s the matter?

Asked By: Qiu Yangfan

||

/bin is a symlink to /usr/bin. /bin with no trailing slash corresponds to the symlink itself, /bin/ with a trailing slash corresponds to the target directory.

On top of that, by default cp doesn’t follow symlinks when recursing by default. So

cp -rvf /bin/ ./rmalter

copies the directory (and its contents), but

cp -rvf /bin ./rmalter

only copies the symlink.

Answered By: Stephen Kitt
Categories: Answers Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.