
Live smart.
One of the standout aspects of Linux that sets it apart from other major operating systems is its robust automation capabilities. This remarkable feature is made possible by an intriguing fusion of commands, allowing you to live smarter and streamline your tech-driven life.
This command iterates over each line of a file that contains a list of file names and creates actual files using the corresponding names.
while IFS= read -r filename; do touch "$filename"; done < sample.txt
Let’s break down the command:
whilestarts a loop that reads each line from thesample.txtfile.IFS=ensures that leading and trailing whitespace in each line is preserved during the read operation.read -r filenamereads a line from the file and assigns it to thefilenamevariable.;separates the individual commands within the loop.touch "$filename"creates a file with the name stored in thefilenamevariable.donemarks the end of the loop.< sample.txtredirects the contents ofsample.txtas input for the loop.
By running this command, the script will read each line from sample.txt and create a file with the corresponding name. For example, if sample.txt contains the following lines:
AAA
BBB
CCC
The command will create three files named AAA, BBB, and CCC in the current directory.
Please note that if any file with the same name already exists in the directory, the touch command will update the access and modification times of that file instead of creating a new file.