New answers tagged

0

Using a flag is also much clearer, and has less risk of unintended effects, when the command is used in a script instead of manually entered. Patching dots onto paths in a script could end up in all kinds of unexpected mischief.


19

The problem with cp/mv/ln as they were originally designed is that they're two commands in one (copy to and copy into). cp A B is either copy A to B or copy A into B (copy A to B/A) depending on whether B exists and is a directory or not (and more variations if B is a symlink to a directory). That's bad because it's ambiguous. So the GNU implementations ...


25

Your . trick can only be used when you're copying a directory, not a file. The -T option works with both directories and files. If you do: cp srcfile destfile and there's already a directory named destfile it will copy to destfile/srcfile, which may not be intended. So you use cp -T srcfile destfile and you correctly get the error: cp: cannot ...


6

The -T can provide a failure if a directory incorrectly exists for what should be a destination file: $ mkdir mustbeafile $ touch afile $ cp -T afile mustbeafile cp: cannot overwrite directory `mustbeafile' with non-directory $ echo $? 1 $ cp afile mustbeafile $ That is, instead of success-on-unexpected-copy-to-a-subdir, a warning and not-good exit ...


0

I tested these command on Linux Debian in the terminal. If your terminal is wide enough, just stating "ls" will give columns but it won't use all the space (width) of the terminal. I made the terminal as wide as the screen and "ls" just produced 4 columns. Problem is if you pipe this into "more" you loose the columns. Next I used "ls -w200" in the ...



Top 50 recent answers are included