Quantcast
Channel: Copy the same file to the desktops of all users - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 3

Answer by msp9011 for Copy the same file to the desktops of all users

$
0
0

Your code expands as:

cp myfile /home/user1/Desktop/ /home/user2/Desktop/ /home/user3/Desktop/ /home/user4/Desktop/ ... /home/userN/Desktop/

From man of cp:

Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.

which means, it will try to copy "myfile /home/user1/Desktop/ /home/user2/Desktop/ /home/user3/Desktop/ /home/user4/Desktop/ ..." to /home/userN/Desktop/

it will throw an error because except "myfile" all other where directories...

try this,

UserS=($(awk -F':' '{ if ( $3 >= 500 ) print $1 }' /etc/passwd))
for i in ${UserS[@]}
do
    [ -d /home/"$i"/Desktop ] && cp myfile /home/"$i"/Desktop
done

Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>