guil_ads
guil_ads

Reputation: 27

shell script to read directory names and create .txt files with the same names in another directory

I have two directories, one called clients and another called test, inside the directory called clients I have some folders, I need a shell script that reads the name of the folders inside clients and creates .txt files with the same name inside the folder test, I am very new to shell and I have no idea how to do this, could you guys help me please?

Upvotes: 0

Views: 167

Answers (1)

RedYetiDev
RedYetiDev

Reputation: 679

Try using xargs with ls. ls -F displays all files in the directory client, but then displays the folders with an extra / at the end. the grep uses the extra / in the output of ls -F to only pass folders to the next command. Then, sed 's/\///g removes the extra / from grep, and passes the names to xargs. xargs will then pass the folders to the % symbol, and then make text files with the names.

ls -F client | grep / | sed 's/\///g' |  xargs -I % touch tests/%.txt

Upvotes: 2

Related Questions