If I want to copy a single file into three locations (directories), by using a single cp command (e.g. cp file /dir1/ /dir2/ /dir3/. Would that be possible? If yes, please provide the command for GNU/Linux or Unix operating systems.
The short answer is no. You can not use GNU/cp or BSD/cp to copy a single file to multiple directories. However, you can use combination of cp and xargs/parallel and other commands to copy a single file to multiple directories in MacOS, Linux, FreeBSD, OpenBSD, NetBSD and Unix-like systems.
The cp command The basic cp command syntax is as follows to copy multiple files to a single directory: cp file1 /dir1/ cp file1 file2 file3 /dir1/
Copy file to multiple directories in Unix or Linux – The trick is to use the xargs command or GNU parallel command.
Copying one file named foo.txt to multiple directories called /tmp/1/, /tmp/2/, and /tmp/3 using xargs The xargs command construct argument list(s) and execute utility such as cp or mv. The syntax is: Continue reading