# Repeat same command on multiple lines

**URL:** <https://community.unix.com/t/repeat-same-command-on-multiple-lines/222945>\
**Category:** Shell Programming and Scripting\
**Created:** [December 3, 2008, 1:55pm UTC](https://community.unix.com/t/repeat-same-command-on-multiple-lines/222945 "2008-12-03T13:55:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![PrasannaKS](https://community.unix.com/letter_avatar/prasannaks/32/5_5575768a8748004e209b776fc1b2916d.png) [@PrasannaKS](https://community.unix.com/u/PrasannaKS)\
**Post date:** [December 3, 2008, 1:55pm UTC](https://community.unix.com/t/repeat-same-command-on-multiple-lines/222945/1 "2008-12-03T13:55:25Z")

</div>

HI

I have a text file named docs with 100 filenames with full directory path one by one. I want to perform an action on all of them, the action i want to do this chown bin:bin \<filename\>. The \<filename\> should be each line in the docs text file. Please give the code. Somebody told to use for loop and somebody uses while. Please suggest the best and give the code.

---

<div class="post-metadata">

**Author:** ![Ikon](https://community.unix.com/user_avatar/community.unix.com/ikon/32/1015_2.png) [@Ikon](https://community.unix.com/u/Ikon)\
**Post date:** [December 3, 2008, 2:08pm UTC](https://community.unix.com/t/repeat-same-command-on-multiple-lines/222945/2 "2008-12-03T14:08:55Z")

</div>

```nohighlight
for line in `cat file.txt`;
do
 chown bin:bin $line
done

```

---

<div class="post-metadata">

**Author:** ![PrasannaKS](https://community.unix.com/letter_avatar/prasannaks/32/5_5575768a8748004e209b776fc1b2916d.png) [@PrasannaKS](https://community.unix.com/u/PrasannaKS)\
**Post date:** [December 3, 2008, 2:43pm UTC](https://community.unix.com/t/repeat-same-command-on-multiple-lines/222945/3 "2008-12-03T14:43:58Z")

</div>

thanks a lot
