Hi,

I'm pretty new to scripting so need some help...

Basically I have a 1TB drive that hosts hundreds of .mdf files. What I want to do is search this drive for these .mdf files, zip them, and then delete the original .mdf file permanently.

Any advice/help would be greatly appreciated.

Thanks

Steven

dir=/path/to/1TB/drive
IFS=$(printf "\n") zip mdf $(find "$dir" -name '*.mdf')
find "$dir" -name '*.mdf' -exec rm {} +

Will this work under Windows powershell?


Windows powershell is not a Unix shell.

"Shell Scripting forum is the place for Q&A-style discussions related to *nix shell scripting languages"

dir=/path/to/1TB/drive
IFS=$(printf "\n") zip mdf $(find "$dir" -name '*.mdf')
find "$dir" -name '*.mdf' -exec rm {} +

Why IFS=$(printf "\n") instead of just IFS=$'\n' ? To avoid bash-only feature?

Why IFS=$(printf "\n") instead of just IFS=$'\n' ? To avoid bash-only feature?


Exactly; the $'\n' syntax is not portable.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.