Bash Script Iterating Question

I am trying to look through one of my directories to remove certain files. I am pretty new to Unix and bash so I just need a little help in starting this. I know I would have to write two loops one to iterate the directories and one to iterate the files. How would I write the loops?

Is this a homework assignment?

Why do you need two loops to iterate through one directory?

By what criteria will you remove certain files? What do you want to do to the files that you do not remove from consideration?

From what you have said so far, I'm not sure you need any loop; shell pattern matching might do everything you need.

It's not a homework assignment; just something I am playing with to learn UNIX. I will be starting a new job soon where they use UNIX and bash scripting so my uncle let me copy a few directories and files to work with.

I noticed a few of the files in the directories have underscores in the name and I wanted to see if I could delimit the underscores.

There is a command named `find' which will do that for you

find /path/to/directory -name "*_*" -type f

That could display every file that contain an `_' in /path/to/directory and below.

1 Like