Script for listing specific filename in 3 directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script for listing specific filename in 3 directory
# 1  
Old 09-15-2010
Bug Script for listing specific filename in 3 directory

I used to work in perl but I would like to try now bash. Here's my problem

I wanted to search for specific filename (ls -ltrh) on 3 directories.. Example
Code:
ls -ltrh | grep "string"
/dir1
/dir1/dir2
/dir1/dir2/dir3

I wanted to get the result to be copied on a different directory. Sample output
Code:
/dir1
-rw-r--r--   1 user1   sysadmin    248K Sep  6 17:20 12345.dat

/dir1/dir2
none

/dir1/dir2/dir3
none

thanks

Last edited by Franklin52; 09-16-2010 at 02:50 AM.. Reason: Please use code tags!
# 2  
Old 09-16-2010
Code:
find  /dir1 /dir1/dir2 /dir1/dir2/dir3 -name "*string*" -type f -print

Because the second and third dirs are under /dir1, so you will get duplicated output on some files.

Code:
find  /dir1 /dir1/dir2 /dir1/dir2/dir3 -name "*string*" -type f -exec cp {} /different_dir \;

# 3  
Old 09-16-2010
thank you and it worked.

how about incorporating it to a simple bash script wherein I need to input the string? Say I'm looking for A45678.dat on those 3 directories.

I would like to put only the 45678 so it will search the filenames on those 3 directories.. I would like to have an output similar to ls -ltrh. In this way I will only execute the script appending the needed string like 45678.

thanks a lot

---------- Post updated at 12:59 PM ---------- Previous update was at 12:51 PM ----------

got it now...thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to Tar file in a specific Directory

I'm trying to write a Unix script that will go to a specific directory (/tmp/Sanbox/logs) and tar.gz all the log files in that directory and delete the original files that are older than 2 days. So far I have this but it doesn't work. Any help would be appreciated. #!/bin/bash ... (7 Replies)
Discussion started by: Loc
7 Replies

2. Shell Programming and Scripting

Running script in crontab in a specific directory

I am trying to run a script from crontab but the entire script (which is 70+ lines) is written in bash and I need it to run from a certain directory. So when I run it manually I cd to /local/mnt/scr and then type ./reordersc and it works fine. However, I want it to run from the crontab and I... (20 Replies)
Discussion started by: newbie2010
20 Replies

3. Shell Programming and Scripting

Shell scripting-I need a script which should watch a directory for a file with specific directory

I need a script which should watch a directory for a file with specific directory. If it finds a file in directory, it should search for few specific keyword in the file. if the keyword exists, it should trim string from specific column. The file should be moved to another directory and the a... (8 Replies)
Discussion started by: akashdeepak
8 Replies

4. Shell Programming and Scripting

Request for shell script for listing directories, subdirs containing specific files.

I'm looking for a script which outputs the list of directories and sub directories from root level consisting of specific files. For instance I want shell script to list all the directories and subdirectories containing .txt files.:wall: (4 Replies)
Discussion started by: super210
4 Replies

5. Shell Programming and Scripting

capture specific listing in the ls -l

Hi, my desired output needs only that has *.pdf ls -l *.pdf error: arg list too long so I have redirected ls -l > file.txt therefore, I get the following details in the file -rw-r--r-- 1 devusr devgrp 848015 Aug 11 15:13 0000795769.pdf -rw-r--r-- 1 devusr devgrp ... (3 Replies)
Discussion started by: techmoris
3 Replies

6. Shell Programming and Scripting

AWK script for directory listing using GREP

Hi, All - script1.awk contains the following script: BEGIN { printf "The following are directory files:" "ls -l | grep '^d' | {print $0}" printf "There were "NR" directories in this list." } When I run the script, Here is what I get: $ awk -f... (4 Replies)
Discussion started by: ora_umair
4 Replies

7. Shell Programming and Scripting

Shell Script Passing Parameters For Directory Listing

i have this basic piece of code that i am trying to debug to accept input parameter to be able to display a directory listing of files. cd /u02/app/eatv/dev/out CURDIR=`pwd` echo directory listing of $CURDIR echo if ; then ls -latr else ls -latr $1 fi basically if the script... (9 Replies)
Discussion started by: wtolentino
9 Replies

8. Shell Programming and Scripting

Listing a directory via a script using variables

In my script I need to list the directory, where the generic name of the files will change, in my test case its set to TEST_*.mqsc. I wrote a small test script as below, but it just does not pip the listing to a file. Any idea why? dir='C:/cygwin/var/log/img/aut/' file=TEST01_*.mqsc ls $dir... (4 Replies)
Discussion started by: gugs
4 Replies

9. UNIX for Dummies Questions & Answers

listing only filename

hi I want to list only file name from a directory through shell scripting. can any body help me. (3 Replies)
Discussion started by: prasann
3 Replies

10. UNIX for Dummies Questions & Answers

Recursive directory listing without listing files

Does any one know how to get a recursive directory listing in long format (showing owner, group, permission etc) without listing the files contained in the directories. The following command also shows the files but I only want to see the directories. ls -lrtR * (4 Replies)
Discussion started by: psingh
4 Replies
Login or Register to Ask a Question