Unix/Linux Forum: Find The File Names Based On Name From Directory - Unix/Linux Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Find The File Names Based On Name From Directory Rate Topic: -----

#1 User is offline   akb2010 Icon

  • Newbie (User Level: 0/10)
  • Group: Members
  • Posts: 1
  • Joined: 21-January 10

Posted 21 January 2010 - 05:03 AM

Hi experts,

I would like to write a shell script that can print the file name from directory.Not required to see the contents.

Ex :

directory will have 5 files with different name.No matter what contents are.

Now I need to find the file which will have particular name (sub string ).Please do not look into contents.It should be in loop to check all the file names

Please provide the shell script.

Please let me know if any one need more info.
0

#2 User is offline   VivekRaj Icon

  • User Level: 1/10
  • Pip
  • Group: Members
  • Posts: 11
  • Joined: 18-February 10

Posted 18 February 2010 - 09:41 AM

Run this script under the directory where you want to look up.

for i in `ls`
do
echo -e `expr match "$i" '\(.*compare.*\)'`
done

The above script first take the output of ls command.Then,it checks each and every file name is containing the substring compare.

If it matched,it will print the name of the file.
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Cambridge Plus :: Cambridgeshire Steam Rally :: 3D Mechanical Design :: AJS Piston Rings
Unix Man Pages / Linux Man Pages :: HiFi Forum :: A14 Comments :: UNIX/Linux Forum Archives