Bash Scripts for Dir listing
I am needing to figure out how to see if a file exists inside of a directory. lets say I have
/test I need to see if test.txt or any file is in the directory if a file is in the directory then do something. like execute a wall statement saying there is a file there. can anyone help |
Check out the Linux Cookbook section on Finding Files. The 'find' command is very versatile; it can do what you're asking, including the part about executing a command after finding something.
|
That has a lot of helpful information but I am not that good at bash scripting yet, If you can I need help incorporating this into a script.
#! /bin/sh find /test *.txt if *.txt then wall " The file *.txt is in the file" exit or something like this #!/bin/sh ls /test/*.txt if *.txt exists then wall "The file *.txt is in the file" exit This is the basics for what I am trying to do. |
I am a far cry from a sh script expert but this should work:
Code:
if [ -r *.txt]; then |
Quote:
|
I read over most of it and tried to get it to work with what I was doing I am still working on it though thanks wapcaplet.
Mephisto, thank you for the input it will help me as the script becomes more completed. Currently what I am trying to do is just a small piece of the overall script |
Mephisto, thanks I have that section of my script running now.
I used this to check a directory for files that have been placed into a certain directory then it emails me a notification. |
All times are GMT -5. The time now is 03:40 AM. |