Skip to content
Advertisement

Making new directories with a Bourne Shell script

I am am new to Linux and have a question about scripts. I am interested to know how you create a new directory and copy all the files (with .txt extension) from the existing directory into it? I am familiar with the mkdir method but I am having trouble when trying to execute it within a script.

I have tried the following but there are errors. Here I am trying to copy the output to a new directory called MyTestFiles.

Any help would be much appreciated.

#!/bin/sh

cp *.[t][x][t] > MyTestFiles

Advertisement

Answer

It’s called “glob” (to match all files that end with “.txt”, for instance):

mkdir MyTextFiles
cp *.txt MyTextFiles/

Also, if you are new to Unix/Linux, man is your best friend:

man cp
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement