IFS – Find files and directories in your IFS – BlogFaq400

I take advantage of a question asked on the Midrange.com discussion groups ( Is there an easy way to find a file in IFS? ) to summarize, in this post, some different ways to search for a file within one or more IFS directories. The specific question was … “is there something to look for in IFS objects like WRKOBJ command we use in IBM i environment in QSYS library?”

If we “navigate” in our IFS starting from QSH, remember that we are in a world very similar to Linux and therefore several Linux commands work very well here too!

Suppose we have one IFS directory “/ f4docs” where there are thousands of files and subfolders. Let’s see different types of research and the different possibilities we have from the IBM i environment or from QSH:

1 – FIND command from QSH or SSH: we see in this a search of all the files in the directory “/ f4docs” of type “.TXT” with the name containing “02342” … including any subdirectories

find /f4docs -name “*02432*.TXT”

2 – FIND + GREP command from QSH or SSH: the problem with FIND is that it is always case-sensitive in QSH environment … if we need to filter only certain files not taking into account the “case” character:

find /f4docs -type f -name “*02432*” | grep “.txt” -i

3 – Command FIND + GREP (to also search inside the contents of the fil es), from QH and SSH: by slightly modifying the syntax of the GREP part, it is also possible to search for files with a certain content (in this case the string “MOTO”

find /f4docs -name “*.TXT” -exec grep -l ‘MOTO’ {};

4 – With SQL and QSYS2.IFS_OBJECT_STATISTICS : an interesting alternative to search for IFS files and objects is SQL with IBM i Services … in particular QSYS2.IFS_OBJECT_STATISTICS

Select * from Table (QSYS2.IFS_Object_Statistics (Start_Path_Name => ‘/ f4docs’, Subtree_Directories => ‘YES’)) x Where Lower (Path_Name) like ‘% 02432%’;

5 – With RTVDIRINF and SQL on the created catalog tables:

// first, delete RTVDIRINF result tables


// then collect data from your directoy

RTVDIRINF DIR(‘/f4docs’)

// and search your files

SELECT o.Qezalcsize
,SUBSTR(o.Qezobjnam, 1, 40)
FROM qusrsys.Qaezd0001o o
INNER JOIN qusrsys.Qaezd0001d d
ON o.Qezdiridx = d.Qezdiridx
and qezobjtype=’*STMF’
and UPPER(o.Qezobjnam) LIKE ‘%02432%’
ORDER BY o.Qezalcsize DESC;

6 – With Powershell and Findstr if the IFS directory is shared – share: if we want to search inside the contents of the files from Windows, we can use the PowerShell and the Findstr command, pointing to a shared IFS directory … with a really interesting speed. If we want, for example, to search for files that contain the word “MOTO” …. as in example 3 above, but using FINDSR the syntax is as follows:

findstr /s /i /c:”MOTO” \myIBMif4docs*.TXT
/s search in al subdirectories
/i case insensitive
/c: search string

7 – Updatedb and Locate, open source utility from the Linux world … they allow a quick search using all the potential of regular expressions.

updatedb -l0 -U /f4docs -o /tmp/myindex
locate -d /tmp/myindex 02342

Roberto De Pedrini

Generated by Feedzy