Check folder or subfolder exists coderinme

Check folder or subfolder exists

Write a shell script which will receive any number of filenames as
arguments. The shell script should check whether such files already
exist. If they do, then it should be reported. If these files do not exist
then check if a sub-directory called mydir exists in the current
directory. If it doesn’t exist then it should be created and in it the files
supplied as arguments should get created. If mydir already exists then
it should be reported along with the number of files that are currently
presently in mydir.


if [ $# -lt 1 ]; then
echo "Usage: $0 file1 [file2 ...]"
exit 1
for i in "$@"; do
if [ -f $i ]; then
echo "File $i already exists."
elif [ -d "mydir" ]; then
for j in `find "mydir" -type f `; do
echo "File $j exists"
mkdir "./mydir"
for i in "$@"; do
touch "./mydir/"$i
echo "Directory mydir created with the files with name same as arguments"

For more programs in shell, visit our Shell Coder Archives
Check folder or subfolder exists

Disclaimer : All rights reserved. No part of this Post may be copied, distributed, or transmitted in any form or by any means, without prior written permission of website admin, except in case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law. For permission requests, write to owner, addressed “Attention: Permissions Coordinator,” to the admin @coderinme

A web developer(Front end and Back end), and DBA at Currently working as Salesforce Developer @ Tech Matrix IT Consulting Private Limited. Check me

Leave a reply:

Your email address will not be published.