I have a directory mnt/d/LIVI
.
Inside the directory, LIVI, I have sub-directories:
mnt/d/LIVI/ak
mnt/d/LIVI/ag
mnt/d/LIVI/few
mnt/d/LIVI/ww4
mnt/d/LIVI/ks5
I wanted to copy a file named tt.txt
from mnt/d/LIVI/ak/tt.txt
and paste to all the sub directories of LIVI, using Ubuntu terminal. How do i do it using a shell script file?
I tried the following one, but it didn’t work.
I created a text file named mnt/d/LIVI/FOLDERS.txt
, This listed all the sub directories names.
And saved a script file in mnt/d/LIVI
directory. The following is the script
#!/bin/sh
# -*- coding: utf-8-unix -*-
ROOTDIR=$(dirname $0 | xargs readlink -f)
for SIMDIR in cat FOLDERS.txt | xargs readlink -f ; do
cp mnt/d/LIVI/ak/tt.txt $SIMDIR
done
#cd ..
date
2
Answers
You may try this
bash
scriptThe script must reside under the diectory
mnt/d/LIVI
Don’t read lines with
for
.(If you really wanted to, the syntax for that would look like
but really, don’t. The link above explains why in more detail.)
I don’t see why you want to run
readlink
on the directories at all?Note also Correct Bash and shell script variable capitalization