Find files using shell script

Rohit Saluja

I have the below script which looks for the file in the current directory and evaluates to true if the file exists in the directory and evaluates to false if it does not

#!/bin/bash
printf "\n Please enter a file name "

read num3

if [ -f $num3 ]
then
printf "It is valid script "
else
printf "Invalid file name "
fi

How can i check for the presence of the files in some other directory rather than the present directory in which the script is written ?

rcjohnson

Try this

#!/bin/bash
printf "\n Please enter a file name "
read num3
printf "\n Please enter the path to check "
read path2check

if find $path2check -name $num3 -print -quit |
   grep -q '^'; then
  echo "the file exists!"
else
  echo "the file does not exist!"
fi

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Find files and pack them using a shell script

From Dev

Using find in shell script

From Dev

Find and move files to appropriate directories using shell script

From Dev

Download files using Shell script

From Dev

Shell Script to find JPG and MOV files

From Dev

How to find uncommon lines between two text files using shell script?

From Dev

How to find if there are new files in a directory on HDFS (Hadoop) every 4 min using shell script

From Dev

How to find uncommon lines between two text files using shell script?

From Dev

Modifying ini files using shell script

From Dev

Creating a shell script to compress files using Cygwin

From Dev

Create new files in Shell script using VIM

From Dev

Adding size of files using shell script

From Dev

Shell script to unzip files using file watcher

From Dev

Using shell script to sort files then delete old files

From Dev

Using shell script to sort files then delete old files

From Dev

How to find files which do not end with ".log" in bash/shell script

From Dev

shell script : find a string by searching inside all the files in a folder?

From Dev

Shell script to find all types of files in a directory with their count

From Dev

Shell script to find and count total number of characters in all the files

From Dev

Generate files in shell script

From Dev

Editing files with shell script

From Dev

shell script to remove files

From Dev

Generate files in shell script

From Dev

command not find in shell script

From Dev

problem with find (shell script)

From Dev

Loop over files in directory using shell script Ubuntu

From Dev

How to access all files in all sub directories using shell script?

From Dev

Using a shell script to call multiple ROS launch files

From Dev

Syntax clash when using maven filters for shell script files

Related Related

  1. 1

    Find files and pack them using a shell script

  2. 2

    Using find in shell script

  3. 3

    Find and move files to appropriate directories using shell script

  4. 4

    Download files using Shell script

  5. 5

    Shell Script to find JPG and MOV files

  6. 6

    How to find uncommon lines between two text files using shell script?

  7. 7

    How to find if there are new files in a directory on HDFS (Hadoop) every 4 min using shell script

  8. 8

    How to find uncommon lines between two text files using shell script?

  9. 9

    Modifying ini files using shell script

  10. 10

    Creating a shell script to compress files using Cygwin

  11. 11

    Create new files in Shell script using VIM

  12. 12

    Adding size of files using shell script

  13. 13

    Shell script to unzip files using file watcher

  14. 14

    Using shell script to sort files then delete old files

  15. 15

    Using shell script to sort files then delete old files

  16. 16

    How to find files which do not end with ".log" in bash/shell script

  17. 17

    shell script : find a string by searching inside all the files in a folder?

  18. 18

    Shell script to find all types of files in a directory with their count

  19. 19

    Shell script to find and count total number of characters in all the files

  20. 20

    Generate files in shell script

  21. 21

    Editing files with shell script

  22. 22

    shell script to remove files

  23. 23

    Generate files in shell script

  24. 24

    command not find in shell script

  25. 25

    problem with find (shell script)

  26. 26

    Loop over files in directory using shell script Ubuntu

  27. 27

    How to access all files in all sub directories using shell script?

  28. 28

    Using a shell script to call multiple ROS launch files

  29. 29

    Syntax clash when using maven filters for shell script files

HotTag

Archive