Shell Script

jrustad24

New Member
Joined
Nov 14, 2020
Messages
4
Reaction score
0
Credits
43
I need to create a variable script that uses the "find" utility to search the home directory for files. Example; (./findFile.sh data) The search also needs to be case-insensitive. The results should look like what is in the attachment.
 

Attachments

  • Capture6.PNG
    Capture6.PNG
    38.7 KB · Views: 364


dos2unix

Well-Known Member
Joined
May 3, 2019
Messages
2,114
Reaction score
1,729
Credits
15,300
This looks like a homework assignment.

"find" will .. ummm... find files.

find / -name findFile.sh

The "/" is where the search starts from, so if you know the file is somewhere under /home, you could do something like...

find /home -name findFile.sh

the -name flag tells it to match the name exactly.
If you use -iname instead, it becomes case insensitive.

There are other flags such as how many directories deep you want to search,
Do you want to list symbolic links or not?

There are flags for newer files, so that if it finds the same file name more than once
it will show you which is the newest.
You can find files, symbolic links, directories, even sockets.

Most of this can be found out by reading the man pages.

man find

.
 

captain-sensible

Well-Known Member
Joined
Jun 14, 2019
Messages
2,910
Reaction score
1,972
Credits
18,114
name of file will be findFile.sh

well i guess the common element is /home/user/

so start from home
#!/bin/sh
cd ~
echo $(pwd)
ls -l | find -type f


//along those lines geany is quite good for playing with code and running !
 

Members online


Top