Checking if multiple directories exist


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Checking if multiple directories exist
# 1  
Old 07-24-2012
Do you even need an array? Or a loop? mkdir can be fed more than one thing at a time, can be told to skip dirs that already exist with -p, and the shell automatically splits on spaces without the help of an array. So, you can do this all in one op without arrays.

Code:
DIRS="a b c"

if ! mkdir -v -p $DIRS
then
        echo "Problem creating $DIRS"
        exit 1
fi

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Checking File record equal to multiple of 70 or nearest number to multiple of 70

Hello, I have a file with below content - Example 3 6 69 139 210 345 395 418 490 492 I would like the result as - Multiple of 70 or nearest number in the file less than the multiple of 70 69 139 (5 Replies)
Discussion started by: Mannu2525
5 Replies

2. Shell Programming and Scripting

Checking of file exist in different folder

Hi All, Seeking for your assistance to compare if the file in working directory is found on the DIR2 directory and if not found move the file in DIR2. ex. WORKING_DIR=/home/dir1/ file1.txt DIR2=/home/admin/users file1.txt what i did was found_nonempty='' for file in... (4 Replies)
Discussion started by: znesotomayor
4 Replies

3. Shell Programming and Scripting

File exist for multiple files

Hi, I am unable to achieve the file exist conditions if there are multiple files same similar name for e.g. in a $Direct i am having files like aus.txt aus.txt_pr aus.txt_2012 i need to put a file exist condition like which is not working then echo "File present" but the... (9 Replies)
Discussion started by: rohit_shinez
9 Replies

4. Shell Programming and Scripting

Checking FTP server file exist or not

I am trying to delete old file in ftp server, after transferring new file successfully . but here i am checking both the file available or not using ls command. if both the file available means i need to get file_new and file_old file size as greater than zero. but i am getting only for... (3 Replies)
Discussion started by: elango963
3 Replies

5. UNIX for Dummies Questions & Answers

Deleting multiple directories inside multiple directories

Hi, Very unfamiliar with unix/linux stuff. Our admin is on vacation so, need help very quickly. I have directories (eg 40001, 40002, etc) that each have one subdirectory (01). Each subdir 01 has multiple subdirs (001, 002, 003, etc). They are same in each dir. I need to keep the top and... (7 Replies)
Discussion started by: kkouraus1
7 Replies

6. Shell Programming and Scripting

check if multiple directories exist else create missing directories

Hi , I 'm trying to check if multiple directories exist on a server, if not create the missing ones and print " creating missing directory. how to write this in a simple script, I have made my code complex if ; then taskStatus="Schema extract directory exists, checking if SQL,Count and... (7 Replies)
Discussion started by: ramky79
7 Replies

7. Shell Programming and Scripting

File exist checking error

Hi all, I have following code: export USERID=user export BATCHHOSTIP=190.113.3.324 remotePath=/home/user fileName=redbook.txt EXIST=`ssh $USERID@$BATCHHOSTIP 'if ; then echo 0; else echo 1 ; fi'` echo $EXIST II run the code from other server. The redbook.txt file is exist in... (1 Reply)
Discussion started by: suigion
1 Replies

8. Shell Programming and Scripting

checking existance of files and directories

I have a list of files and their directories, starting from a particular location. e.g. temp/new/a.c temp/new/b.c temp/old/a.c temp/old/older/b.c etc. Now I want to check the existence of all these files in the respective directories . I am trying something like cat "fileList" |... (4 Replies)
Discussion started by: herojeett
4 Replies

9. Shell Programming and Scripting

checking textfile exists or not in all directories

Hai All, please help me in solving this assignment!!! i need a unix script that has to check the text file exists or not in all directories and sub directories if textfile exists display the directory path else display does not exists!! example: kamal.txt that i want to search if the... (5 Replies)
Discussion started by: G.K.K
5 Replies

10. Shell Programming and Scripting

moving directories to new directories on multiple servers

Hi - I am new to unix scripts...I need to move several directories on multiple servers to new directories. (0 Replies)
Discussion started by: mackdaddy07
0 Replies
Login or Register to Ask a Question
install(1M)															       install(1M)

NAME
install - install commands SYNOPSIS
dira] dirb] dirc] group] user] file [dirx ...] DESCRIPTION
is a command most commonly used in ``makefiles'' (see make(1)) to install a file (updated target file) in a specific place within a file system. Each file is installed by copying it into the appropriate directory, thereby retaining the mode and owner of the original command. The program prints messages telling the user exactly what files it is replacing or creating and where they are going. is useful for installing new commands, or new versions of existing commands, in the standard directories (i.e. etc.). If no options or directories (dirx...) are given, searches a set of default directories and in that order) for a file with the same name as file. When the first occurrence is found, issues a message saying that it is overwriting that file with file (the new version), and proceeds to do so. If the file is not found, the program states this and exits without further action. If one or more directories (dirx ...) are specified after file, those directories are searched before the directories specified in the default list. Options Options are interpreted as follows: Installs a new command (file) in the directory specified by dira, only if it is not found. If it is found, issues a message saying that the file already exists, and exits without overwriting it. Can be used alone or with the option. Forces file to be installed in given directory, whether or not one already exists. If the file being installed does not already exist, the mode and owner of the new file will be set to and respectively. If the file already exists, the mode and owner will be that of the already existing file. Can be used alone or with the or options. Ignores default directory list, searching only through the given directories (dirx ...). Can be used alone or with any other options other than and If file is not found in any of the searched directories, it is put in the directory specified in dirc. The mode and owner of the new file will be set to and respectively. Can be used alone or with any other options other than and If file is found, this option saves the ``found'' file by copying it to in the directory in which it was found. This option is useful when installing a normally busy text file such as or where the existing file cannot be removed. Can be used alone or with any other options other than Causes file to be owned by group group. This option is available only to users who have appropriate privileges. Can be used alone or with any other option. Causes file to be owned by user user. This option is available only to users who have appropriate privileges. Can be used alone or with any other option. Suppresses printing of messages other than error messages. Can be used alone or with any other options. When no directories are specified (dirx ...), or when file cannot be placed in one of the directories specified, checks for the existence of the file If exists, it is used to determine the final destination of file. If does not exist, the default directory list is further scanned to determine where file is to be located. The file contains a list of absolute pathnames, one per line. The pathname is the "official" destination (for example of the file as it appears on a file system. The file serves as a master list for system command destinations. If there is no entry for file in the file the default directory list is further scanned to determine where file is to be located. Cross Generation The environment variable is used to locate the locations file (in the form This is necessary in cases where cross generation is being done on a production system. Furthermore, each pathname in is appended to (for example, and used as the destination for file. Also, the default directories are also appended to so that the default directories are actually and The file does not exist on a distribution tape; it is created and used by local sites. WARNINGS
cannot create alias links for a command (for example, vi(1) is an alias link for ex(1)). SEE ALSO
make(1), cpset(1M). install(1M)