473,322 Members | 1,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Linux wrapper to find a file or sub directory in a directory

2
Linux wrapper to find a file or sub directory in a directory
Jan 12 '15 #1
4 3996
Luuk
1,047 Expert 1GB
This is not a proper question.
If you need help try to ask your question with a full sentence.

Try to include what you tried to solve this yourself.
(besides sleeping during the time your teacher told you how to do this)
Jan 12 '15 #2
rk0830
2
Hi Luuk,

Thanks for the wonderful comment.

Here is the script I executed :

echo -n Enter the file or directory you want to locate in this backup image :
read text
echo "You entered $text"
sleep 5
echo $text can be found at :
find -iname $text -ls -print 2>/dev/null;
echo Here is the BYTE SIZE, PERMISSIONS, OWNER, DATE and LOCATION of your search result

and the output of the script serves the purpose, Here is the output:

[20150112 16:38:50] root@x3250-m3-21:/ # ./find.sh
Enter the file or directory you want to locate in this backup image :dho
You entered dho
dho can be found at :
2228469 4 drwxr-xr-x 3 root root 4096 Jan 12 10:34 ./root/dho
./root/dho
1704143 4 drwxr-xr-x 2 root root 4096 Oct 29 16:13 ./dho
./dho
Here is the BYTE SIZE, PERMISSIONS, OWNER, DATE and LOCATION of your search result.

I need to fine tune this script, suppose If user enters a file or sub directory, which is not present in the system, the script should output a message saying, this file or directory is not present.

I know, we can do it using IF, THEN statement, for that i need to write if find command output is null then echo, no such file or directory is present in the system.

Can you help me in this please ?
Jan 12 '15 #3
Luuk
1,047 Expert 1GB
You should read the man pages for 'find'

Among other thing it contains:
EXIT STATUS
find exits with status 0 if all files are processed successfully, greater than 0 if errors occur. This is deliberately
a very broad description, but if the return value is non-zero, you should not rely on the correctness of the results of
find.


Which means that you could use the value of $? after find to see if there was an error executing your find.

Expand|Select|Wrap|Line Numbers
  1. luuk@opensuse:~> find NotExistingFolder -ls -print
  2. find: ‘NotExistingFolder’: No such file or directory
  3. luuk@opensuse:~> echo $?
  4. 1
  5. luuk@opensuse:~>
  6.  
Jan 13 '15 #4
sicarie
4,677 Expert Mod 4TB
+1 to what Luuk said.

Additionally, if this is in a shell script, there are a host of options for if statements, depending on what is being looked for. For example, if you're looking for a command you can run if [ -x /bin/bash ] and that would look for the bash executable. If you're looking for a directory I'm sure there's an equivalent option.
Jan 14 '15 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: o'seally | last post by:
solaris/linux admins/rookie_developers that battle with this error are probably all frustrated when it happens. i bet you're also somehow frustrated by this seemingly unsolvable error :-) ...take...
2
by: francescomoi | last post by:
Hi. I'm trying to build 'MySQL-python-1.2.0' on my Linux FC2: ---------------------------------- # export PATH=$PATH:/usr/local/mysql/bin/ # export mysqlclient=mysqlclient_r # python setup.py...
2
by: Abe | last post by:
I have a strange Perl problem I don't understand. I've written the following program to scan different disks on a Windows server to look for directory files. Works fine until it gets to 'e:' when...
3
by: comp.lang.php | last post by:
Using Linux/PHP 4.3.2 CLI: $fileID = fopen('myfile.txt', 'r'); // WORKS JUST FINE Using Linux/PHP 4.3.8 CLI: $fileID = fopen('myfile.txt'); // THROWS WARNING 'no such file or directory...
4
by: Andy Gilman | last post by:
I want a method basically that tells me if a path is a file or directory, or any other possibilities. What do i need to do? I'm hoping I dont have to manually determine all these things with...
2
by: Eric Wright | last post by:
Good evening, I am rather new to the linux world and I am diving in head first. I am trying to set up postgres with perl, python, and java support as I am going to be developing applications in...
0
by: Theo Kanter | last post by:
Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Lines: 22 Message-ID: <Ca52h.21400$E02.8869@newsb.telia.net> Date: Wed, 01 Nov 2006 17:53:38 GMT...
2
by: enquiring mind | last post by:
-learning python with limited knowledge of linux. -get error msg 21 "file or directory does not exist" -running Suse linux 10. -haven't had a problem before - rebooted several times. -python...
1
by: JeanDean | last post by:
I have successfully installed the valgrind-3.2.3 but it is resulting in following error ------------------------- valgrind ls -l valgrind: failed to start tool 'memcheck' for platform...
3
by: Okonita | last post by:
Hi all, I am having problem completing this restore operation. "db2 restore database AAMI01 from /pap/data/backups taken at 20071002130554 to /pap/data/db01 into AAMI01 NEWLOGPATH /pap/data/new/...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.