Sponsored Content
Top Forums UNIX for Dummies Questions & Answers How to search directory for specific file? Post 302625387 by 47shailesh on Tuesday 17th of April 2012 05:02:06 PM
Old 04-17-2012
This is what the above code is doing:
  • Reading filename and retention from a file.
  • Doing a month to day conversion with wrong syntax.
  • Not sure what the use of all_files variable, later checking and storing if the filename is older than retention, which is dependent on incorrect value of period.
  • Then checking if nonempty filename exist greater than retention then store some info in file else store some other info in additional files. Do you need log of what files were deleted ?

There is no code to delete the obsolete file.

Code:
STAT=/prod/STAT/seqfiles
cat /test/mkamal/ret/rulesx.txt | while read name ret_period
do
    period=`echo "30.5 * ${ret_period}" | bc `
    find $STAT -name $name -mtime +"$period" -exec ls {} \;`
done

once the script displays right results replace ls {} with rm {}
This User Gave Thanks to 47shailesh For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Linux shortcutkey to search specific file from a list of directory?!

Hi, I'm the new user of linux/unix. Can I ask that anybody know how to use the linux/unix shortcut key to search a specific file from a list of directory? For example, I know the file name that I want to search. But I forget which directory or location is my desired file put.Got any shortcut... (7 Replies)
Discussion started by: patrick87
7 Replies

2. Shell Programming and Scripting

Search for a file in specific directory

I have to search a file in a prticular directory. filename will be passed through command line. The directory may contain subdirectory. i.e. suppose directory in /u03/appl (it can hard coded in script). This directory may contain subdirectory. $ scriptname.sh filename output should be... (2 Replies)
Discussion started by: jadoo_c2
2 Replies

3. UNIX for Dummies Questions & Answers

How to search all the files in a directory for a specific string

Hi Guys, I want to search the content of all the files (of a particular type like .txt) in a directory for a specific string pattern. Can anyone help me? Thanks (7 Replies)
Discussion started by: mwrg
7 Replies

4. UNIX for Advanced & Expert Users

allow user to use sudo cp on a specific directory and only a specific file

Is there a way to allow a user to use sudo cp on a specific directory and only a specific file? (6 Replies)
Discussion started by: cokedude
6 Replies

5. Shell Programming and Scripting

Urgent request to consider:Search specific name in a file and fetch specific entries

Hi all, I have 2 files, One file contain data like this FHIT CS CHRM1 PDE3A PDE3B HSP90AA1 PTK2 HTR1A ESR1 PARP1 PLA2G1B These names are mentioned in the second file(Please see attached second file) as # Drug_Target_X_Gene_Name:(Where X can be any number (1-1000) (1 Reply)
Discussion started by: manigrover
1 Replies

6. Shell Programming and Scripting

Search specific name in a file and fetch specific entries

Hi all, I have 2 files, One file contain data like this FHIT CS CHRM1 PDE3A PDE3B HSP90AA1 PTK2 HTR1A ESR1 PARP1 PLA2G1B These names are mentioned in the second file(Please see attached second file) as (7 Replies)
Discussion started by: manigrover
7 Replies

7. Shell Programming and Scripting

Change to directory and search some file in that directory in single command

I am trying to do the following task : export ENV=aaa export ENV_PATH=$(cd /apps | ls | grep $ENV) However, it's not working. What's the way to change to directory and search some file in that directory in single command Please help. (2 Replies)
Discussion started by: saurau
2 Replies

8. UNIX for Dummies Questions & Answers

Search for a specific String in a log file for a specific date range

Hi, I have log file which rolls out every second which is as this. HttpGenRequest - -<!--OXi dbPublish--> <created="2014-03-24 23:45:37" lastMsgId="" requestTime="0.0333"> <response request="getOutcomeDetails" code="114" message="Request found no matching data" debug="" provider="undefined"/>... (3 Replies)
Discussion started by: karthikprakash
3 Replies

9. 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

10. UNIX for Dummies Questions & Answers

How to search in specific directory using find?

Hi, Is there any way to use find command and search only specific subdirectories in a directory. for example /home/d1 /home/d2 /home/d3 i want to search in the following directories /home /home/d1 /home/d2 i do not want the find command to search the /home/d3 directory. (6 Replies)
Discussion started by: Little
6 Replies
STAT(5) 							File Formats Manual							   STAT(5)

NAME
stat, wstat - inquire or change file attributes SYNOPSIS
Tstat tag[2] fid[2] Rstat tag[2] fid[2] stat[116] Twstat tag[2] fid[2] stat[116] Rwstat tag[2] fid[2] DESCRIPTION
The stat transaction inquires about the file identified by fid. The reply will contain a 116-byte (DIRLEN in <libc.h>) machine-independent directory entry laid out as follows: name[28] file name; must be / if the file is the root directory of the server uid[28] owner name gid[28] group name qid.path[4] the file server's identification for the file qid.vers[4] version number for given path mode[4] permissions and flags atime[4] last access time mtime[4] last modification time length[8] length of file in bytes type[2] for kernel use dev[2] for kernel use Integers in this encoding are in little-endian order (least significant byte first). The convM2D and convD2M routines (see fcall(2)) con- vert between directory entries and C structs. This encoding may be turned into a machine dependent Dir structure (see stat(2)) using routines defined in fcall(2). The mode contains permission bits as described in intro(5) and the following: 0x80000000 (this file is a directory), 0x40000000 (append only), 0x20000000 (exclusive use). Writes to append-only files always place their data at the end of the file; the offset in the read or write message is ignored, as is the OTRUNC bit in an open. Exclusive use files may be open for I/O by only one fid at a time across all clients of the server. If a second open is attempted, it draws an error. Servers may implement a timeout on the lock on an exclusive use file: if the fid holding the file open has been unused for an extended period (of order at least minutes), it is reasonable to break the lock and deny the initial fid further I/O. The two time fields are measured in seconds since the epoch (Jan 1 00:00 1970 GMT). The mtime field reflects the time of the last change of content. For a plain file, mtime is the time of the most recent create, open with truncation, or write; for a directory it is the time of the most recent remove, create, or wstat of a file in the directory. Similarly, the atime field records the last read of the contents; also it is set whenever mtime is set. In addition, for a directory, it is set by an attach, walk, or create, all whether successful or not. The length records the number of bytes in the file. Directories and most files representing devices have a conventional length of 0. The stat request requires no special permissions. The wstat request can change some of the file status information. The name can be changed by anyone with write permission in the parent directory; it is an error to change the name to that of an existing file. The mode and mtime can be changed by the owner of the file or the group leader of the file's current group. The directory bit cannot be changed by a wstat; the other defined permission and mode bits can. The gid can be changed: by the owner if also a member of the new group; or by the group leader of the file's current group if also leader of the new group (see intro(5) for more information about permissions and users(6) for users and groups). None of the other data can be altered by a wstat. In particular, there is no way to change the owner of a file. A read of a directory yields an integral number of directory entries in the machine independent encoding given above (see read(5)). ENTRY POINTS
Stat messages are generated by fstat and stat. Wstat messages are generated by fwstat and wstat. STAT(5)
All times are GMT -4. The time now is 08:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy