Use a text file list in commands
Either of these two methods will let you use a text file containing a list as input for a command. The list can contain existing file names complete with paths for use in complex commands.
Method 1
Replace FILENAME with the name of the text file and COMMAND with the command you’d like to run on the items listed in the text file:
COMMAND $(cat FILENAME)
- Example:
- Create a text file on your Desktop named mylist.txt and put this information into it:
- Open a terminal window.
- Type this command to change to the Desktop directory:
- Type this command to use the text file to create three files:
- Look on your Desktop or type this command in the terminal window to see the three files you created:
- The result should be something like this:
mytestfile1.txt mytestfile2.txt mytestfile3.txt
cd Desktop
touch $(cat mylist.txt)
ls
mytestfile1.txt mytestfile2.txt mytestfile3.txt
Note that if you had other files on the Desktop, these will also be included in the list.
Method 2
Replace FILENAME with the name of the text file and COMMAND with the command you’d like to run on the items listed in the text file:
cat FILENAME | xargs COMMAND
- Example:
- Create a text file on your Desktop named mylist.txt and put this information into it:
- Open a terminal window.
- Type this command to change to the Desktop directory:
- Type this command to use the text file to create three files:
- Look on your Desktop or type this command in the terminal window to see the three files you created:
- The result should be something like this:
mytestfile1.txt mytestfile2.txt mytestfile3.txt
cd Desktop
cat mylist.txt | xargs touch
ls
mytestfile1.txt mytestfile2.txt mytestfile3.txt
Note that if you had other files on the Desktop, these will also be included in the list.
Obligatory Happy Ending
And they all lived happily ever after. The end.

Comment: