Visit Our UNIX and Linux User Community


Find and EXECDIR option


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Find and EXECDIR option
# 1  
Old 08-05-2009
Find and EXECDIR option

Hello,

I was reading the man pages of find and it says that the -exec option should not be used. I read the following about the recommended option, -execdir:

Code:
 -execdir command {} +
              Like -exec, but the specified command is run from the  subdirec‐
              tory  containing  the  matched  file,  which is not normally the
              directory in which you started find.  This a  much  more  secure
              method  for invoking commands, as it avoids race conditions dur‐
              ing resolution of the paths to the matched files.  As  with  the
              -exec option, the '+' form of -execdir will build a command line
              to process more than one matched file, but any given  invocation
              of command will only list files that exist in the same subdirec‐
              tory.  If you use this option, you must ensure that  your  $PATH
              environment  variable  does not reference the current directory;
              otherwise, an attacker can run any commands they like by leaving
              an appropriately-named file in a directory in which you will run
              -execdir.

I do not really follow the explanation well.

Question 1: What is this race condition they arte talking about?
Question 2: Why if a hacker leaves a file in a directory that the execdir will examine poses a risk? Does the execdir option RUN every file?
# 2  
Old 08-06-2009
Answer 1:
A race condition is when tasks are going in parallel and sometimes the one is sooner finished than the other. Sometimes it will be ok since you expected that the 1st task will finish as 1st and the 2nd as 2nd, but sometimes it could be that the 2nd finishes earlier and so with gives you an awkward or unexpect result.
Race condition - Wikipedia, the free encyclopedia

Answer 2:
Some people use the dot "." in their $PATH. This is good for being lazy since you don't have to use dot-slash to execute a file like ./myscript. But, it can be that there might be some evil person on the box, that put's a self-made ls command in one of your directories. So when the dot in $PATH is not at the end of the list and after the dot there is for example /usr/bin, then not ls from /usr/bin will be taken but the ls from your directory, where you currently stand is. This self-made ls by the evil person can contain something funny, but it can also have very malicious code in it that you don't want to execute like deleting files, thrashing the system etc. corrupting data or exposing data outside.
I usually never have the dot in my $PATH, not even at the end. I type so much every day that I don't mind adding a ./ in front of the things I want to execute.
 

Previous Thread | Next Thread
Test Your Knowledge in Computers #367
Difficulty: Medium
The Single UNIX Specification specifies vi, so every conforming UNIX system must have it.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

find with mtime option

Hi, Please give me more details on the following examples, about "mtime" option. When I try this, I could not get the expected output, please help. find . -mtime -1 -print find . -mtime +1 -print find . -mtime 1 -print How do I get the files modified between two dates, say from... (4 Replies)
Discussion started by: Dev_Dev
4 Replies

2. UNIX for Dummies Questions & Answers

find with prune option help needed

Hello, I am using ksh93 (/usr/dt/bin/dtksh) on Solaris and am stuck when trying to use find with the -prune option. I need to search a directory (supplied in a variable) for files matching a certain pattern, but ignore any sub-directories. I have tried: find ${full_path_to_dir_to_search}... (9 Replies)
Discussion started by: gary_w
9 Replies

3. Shell Programming and Scripting

find -regex option

I'm trying to use regular expression arguments as variables. I have to surround the regular expression with double quotes or else it automatically expands that regular expression to whatever is in that directory. Unfortunately when I run 'find' it further surrounds the double quotes with single... (6 Replies)
Discussion started by: stevensw
6 Replies

4. Shell Programming and Scripting

Help with find -perm option

How to find all files for instance that match the permission rwxr*x--- where * is a wildcard which can be optionally asserted but all the others must match? Thanks in advance (7 Replies)
Discussion started by: stevensw
7 Replies

5. Shell Programming and Scripting

Confusing find command option

Hi, I am a little bit confusing of using find command. Actually, I am planning to delete the files whatever the files are existing in the day before yesterday. So, I am writing the command like this. find . -name "*.txt" -ctime -2 { here I am confusing, if I will use +2 or +1 also I am... (5 Replies)
Discussion started by: nagraju.allam
5 Replies

6. Shell Programming and Scripting

Please suggest me a better option than FIND command

Hi All, Could you please help me in searching files in a better way satisfying the below conditions I want to search files in a path whose access time is more than 5min and less than 60 min and whose Byte size is greater than zero For this, i am using the below command, but it is... (2 Replies)
Discussion started by: sparks
2 Replies

7. Shell Programming and Scripting

recently introduced to the newer option for find...does an older option exist?

To find all the files in your home directory that have been edited in some way since the last tar file, use this command: find . -newer backup.tar.gz Is anyone familiar with an older solution? looking to identify files older then 15mins across several directories. thanks, manny (2 Replies)
Discussion started by: mr_manny
2 Replies

8. Shell Programming and Scripting

Find in Bash with -a option

Hi, The proble is below: Assume i have files starting from "process" then date/time then ".log". ex . process.20100504092942.log process.20100503152213.log process.20100430144217.log process.20100429153644.log process.20100428121200.log process.20100427130746.log... (2 Replies)
Discussion started by: meetvipin
2 Replies

9. Shell Programming and Scripting

help with find command and prune option

Hi I have a directory say mydir and inside it there are many files and subdirectories and also a directory called lost+found owned by root user I want to print all files directories and subdirectorres from my directory using find command except lost+found If i do find . \( -name... (3 Replies)
Discussion started by: xiamin
3 Replies

10. Shell Programming and Scripting

find with prune option

Hi, I want to list files only from the current dir and its child dir (not from child's child dir). i have the following files, ./ABC/1.log ./ABC/2.log ./ABC/ABC1/A.log ./ABC/ABC1/B.log ./ABC/ABC1/XYZ/A1.log ./ABC/ABC1/XYZ/A2.log Here i want to list only the log file from current... (1 Reply)
Discussion started by: apsprabhu
1 Replies

Featured Tech Videos