find Files in sub-directory


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers find Files in sub-directory
# 8  
Old 11-04-2014
Hi R.Signh,

I got another problem i'm sorry.

Since I already confirm that the file.cmd is existing, I need to do a cd.

Code:
p_num=$1
ret_object=$2
path_2=$3

value=`find -type f -name "$ret_object"`
	if [[ -n "$value" ]]
	then
		cd 
		clear				
		echo "Object has been retracted"
		exit 0
	else
		clear
        echo "Object NOT found."
		oap_find_patch_fnc
	fi

In Line 8, I need to go where the file.cmd exist

Is this possible?

Thanks,
cmarzan

---------- Post updated at 04:53 PM ---------- Previous update was at 04:27 PM ----------

Hi R.Signh,

I got another problem i'm sorry.

Since I already confirm that the file.cmd is existing, I need to do a cd.

Code:
p_num=$1
ret_object=$2
path_2=$3

value=`find -type f -name "$ret_object"`
	if [[ -n "$value" ]]
	then
		cd 
		clear				
		echo "Object has been retracted"
		exit 0
	else
		clear
        echo "Object NOT found."
		oap_find_patch_fnc
	fi

In Line 8, I need to go where the file.cmd exist

Is this possible?

Thanks,
cmarzan

Last edited by cmarzan; 11-04-2014 at 04:32 AM.. Reason: change the entire content
# 9  
Old 11-04-2014
Quote:
Originally Posted by cmarzan
Hi R.Signh,

I got another problem i'm sorry.

Since I already confirm that the file.cmd is existing, I need to do a cd.

Code:
p_num=$1
ret_object=$2
path_2=$3
 
value=`find -type f -name "$ret_object"`
    if [[ -n "$value" ]]
    then
        cd 
        clear                
        echo "Object has been retracted"
        exit 0
    else
        clear
        echo "Object NOT found."
        oap_find_patch_fnc
    fi

In Line 8, I need to go where the file.cmd exist

Is this possible?

Thanks,
cmarzan

---------- Post updated at 04:53 PM ---------- Previous update was at 04:27 PM ----------

Hi R.Signh,

I got another problem i'm sorry.

Since I already confirm that the file.cmd is existing, I need to do a cd.

Code:
p_num=$1
ret_object=$2
path_2=$3
 
value=`find -type f -name "$ret_object"`
    if [[ -n "$value" ]]
    then
        cd 
        clear                
        echo "Object has been retracted"
        exit 0
    else
        clear
        echo "Object NOT found."
        oap_find_patch_fnc
    fi

In Line 8, I need to go where the file.cmd exist

Is this possible?

Thanks,
cmarzan
Hello cmarzan,

Could you please be clear in your requirement, as 1st post says you only need to find file in subdirectories and do an operation. Now the script you have posted having some variables which have values seems to me like you are passing arguments to script. Could you please let me know if you want to move a file from a place to another within script or any other operations you need to perform? Also what values you are taking from user as input or you are passing as arguments while running script please?


Thanks,
R. Singh

Last edited by RavinderSingh13; 11-04-2014 at 05:04 AM..
This User Gave Thanks to RavinderSingh13 For This Post:
# 10  
Old 11-04-2014
Try
Code:
cd ${value%/*}

This User Gave Thanks to RudiC For This Post:
# 11  
Old 11-05-2014
Hi R.Signh,

Here is the entire script that I'm working on.

Code:
oap_find_patch_fnc()  {
echo "        Enter PATCH number you want to retract or 99 to exit \c"
read patch_number
path=$AAAHOME/tmp/backup_ModelBankTA/backup_ModelBankTA

	if [ ${patch_number} = 99 ] 
	then
		exit 0
	else
		echo ${path}_${patch_number}
		if [ -d ${path}_${patch_number} ] 
		then 
			clear
			cd ${path}_${patch_number}
			echo "        Select OBJECT to retract \c"
			read retract_object			
		else
			clear
			echo "PATCH number entered does not exist in the directory."
			oap_find_patch_fnc
		fi
	fi
	
}
oap_find_file()
{
p_num=$1
ret_object=$2
path_2=$3

value=`find -type f -name "$ret_object"`

	if [[ -n "$value" ]]
	then
		cd 
		clear				
		echo "Object has been retracted"
		exit 0
	else
		clear
        echo "Object NOT found."
		oap_find_patch_fnc
	fi
fi	
}
oap_find_patch_fnc
oap_find_file $patch_number $retract_object $path

After
Code:
cd

.. I need to put an import script to import the
Code:
$ret_object

which was inputted by the user. I need to
Code:
cd

the exact directory where the
Code:
$ret_object

exist because the import script needs to see the file.

I'm sorry if i confused you...

Thanks,
cmarzan

---------- Post updated at 07:12 PM ---------- Previous update was at 05:35 PM ----------

Hi Sir rodic,

Thanks for the help. It is now working ok..

Also to you Sir R.Signh


Many Thanks,
cmarzan

---------- Post updated 11-05-14 at 12:01 PM ---------- Previous update was 11-04-14 at 07:12 PM ----------

Hi,

In connection to this thread..

Code:
oap_find_patch_fnc()  {
echo "        Enter PATCH number you want to retract or 99 to exit \c"
read patch_number
path=$AAAHOME/tmp/backup_ModelBankTA/backup_ModelBankTA

	if [ ${patch_number} = 99 ] 
	then
		exit 0
	else
		if [ -d ${path}_${patch_number} ] 
		then 
			clear
			echo "        Select OBJECT to retract \c"
			read retract_object			
		else
			clear
			echo "PATCH number NOT found."
			oap_find_patch_fnc
		fi
	fi
	
}
oap_find_file_fnc()
{
p_num=$1
ret_object=$2
path_2=$3

value=`find -type f -name "$ret_object"`

	if [[ -n "$value" ]]
	then
				if [ "$AAA_ADMIN_DIR" = "" ]; then
					echo "ERROR: \$AAA_ADMIN_DIR is not defined"
					exit 255
				fi
				. $AAA_ADMIN_DIR/scripts/initaaa.cfg
				cd ${value%/*}
				$AAAHOME/aaa imp -U -P <$ret_object>$ret_object.out -Jutf8
				mkdir $AAAHOME/tmp/retract_ModelBankTA/retract_ModelBankTA_$p_num
				
				clear				
				echo "Object has been retracted"
				exit 0
	else
		clear
        echo "Object NOT found."
		oap_find_patch_fnc
	fi
	
}
##################################################################################################################
##Main                                                                                                           #
##################################################################################################################
oap_find_patch_fnc
oap_find_file_fnc $patch_number $retract_object $path


Sir, after executing line 39, it will create a .out file with the same file name as
Code:
$ret_object

. After that, Line 40 will be executed. Here is what I don't know next... I wanted to copy all the .out files from the Main directory up to it's sub-folders to the folder created in Line 40 but the tricky here is that the sub-folders must also be copied if it has a .out file inside.

Thanks,
cmarzan

Last edited by cmarzan; 11-05-2014 at 12:06 AM.. Reason: additional question
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Find all files in the current directory excluding hidden files and directories

Find all files in the current directory only excluding hidden directories and files. For the below command, though it's not deleting hidden files.. it is traversing through the hidden directories and listing normal which should be avoided. `find . \( ! -name ".*" -prune \) -mtime +${n_days}... (7 Replies)
Discussion started by: ksailesh1
7 Replies

2. UNIX for Dummies Questions & Answers

How to Find Files other than specified directory ?

Hi All, I am creating one script to Archive the older log files to Archive folder and deleting older files. For example below path contains different sub folders. So searching for log files older than 2 days then zip and moving to Archive directory in the same directory. Source files :-... (4 Replies)
Discussion started by: vadlamudy
4 Replies

3. UNIX for Dummies Questions & Answers

How to find and copy files from one directory to another

Ok i have three directories Destination - /u/dir1 (has subdirectories dir2 which also has subdirectory dir3) Source1 - /u/test/files/dir1/dir2/dir3 Source2 - /u/out/images/dir1/dir2/dir3 What i would like to do is copy everything from Source1 and Source2 into the Destination directory.... (3 Replies)
Discussion started by: ziggy25
3 Replies

4. UNIX for Advanced & Expert Users

How can I find out the open files in a directory

Hello all, Is there any other way of finding the open files in a directory apart from command 'lsof'. thanks (3 Replies)
Discussion started by: joshi123
3 Replies

5. Shell Programming and Scripting

Find files ONLY in current directory

Hello all, I am having a hard type in figuring out how to only gather certain files in the current directory without exploring its subdirectories. I tried: find . -name "*.ksh" -prune this also returns ksh files from lower subdirectories. I also tried find . -ls -name "*.ksh" This also... (8 Replies)
Discussion started by: gio001
8 Replies

6. UNIX for Dummies Questions & Answers

Find files and display only directory list containing those files

I have a directory (and many sub dirs beneath) on AIX system, containing thousands of file. I'm looking to get a list of all directory containing "*.pdf" file. I know basic syntax of find command, but it gives me list of all pdf files, which numbers in thousands. All I need to know is, which... (4 Replies)
Discussion started by: r7p
4 Replies

7. UNIX for Dummies Questions & Answers

Need help to find the files under a directory

Hi, I wanted to delete all the files under a directory "/apps/tmp/" which are two weeks older. But i should not delete the sub-directories and the contents of sub-directories. I also have searched in forum and found the following command, find . \( ! -name . -prune \) -mtime +13 -print ... (8 Replies)
Discussion started by: Sheethal
8 Replies

8. UNIX for Dummies Questions & Answers

How to find a word in a all the files in a Directory??

I want to find a specific word present in all the files ina directory....Please tell me the command to be used?? Thanks (6 Replies)
Discussion started by: shikhakaul
6 Replies

9. Shell Programming and Scripting

Find files in directory

Hi all I want to find a particular file type lets say .abc under /home/oracle/, the file name is start with 'D' and followed by ddmmyyyy date format, the file name should look like this D19092008.abc To my question, how can i perform the searching from the date 19/09/2008 to 29/09/2008. The... (3 Replies)
Discussion started by: coldstarhk
3 Replies

10. Filesystems, Disks and Memory

find the 5o largest files in a directory

I'm trying to find the 50 largest file in a directory named /sasdb and its' subdirectories. I'm using the find command and a pipe to awk Not sure if I'm actually getting the largest files from this directory and its subdirectories. Here is the code I used... find /sasdb -ls | awk '{print... (8 Replies)
Discussion started by: igidttam
8 Replies
Login or Register to Ask a Question