What does this linux command mean?

I was having trouble with file owner rights with files uploaded/resized through scripts. Basically its apache doing the job so they were the assigned owner.

Problem is, I couldn’t change the file permission nor delete those files when needed.

This script somehow works by changing the file permission to 777 so that anyone could delete it. But it changes the whole directory and its subs. I wish to learn a bit of what its doing to modify it.

Heres the source: http://www.frihost.com/forums/vt-14867.html

Heres the code:


system('find . -type d -exec chmod 777 {} \\; 2>&1'); 
system('find . -type f -exec chmod 777 {} \\; 2>&1'); 

print "\

What does find . -type d -exec chmod 777 {} \; 2>&1 mean?

I know its something like find directories, change permission to 777. But I’m totally lost with the {} \; 2>&1 :confused:

I don’t have Linux so I don’t know either, although IMHO it looks like some bit shifting.

I do know that giving 0777 permissions is something you most definately want to not do. Why does it “work”? Because it allows anyone and anything to do do anything and everything. Including reading, deleting, rewriting, uploading and running any file they like. = Major security risk.

Excellent guys! That is some great help. I couldn’t possibly had searched google with those weird characters. :smiley:

So in another words, I could do without the 2>&1 command? Assuming no errors will be encountered.

By placing a number (the file descriptor) will affect which stream is used for the redirection. The Unix standard I/O streams are:

standard input: 0
standard output: 1
standard error: 2

2>&1 is to merge stderr (handle 2) into stdout (handle 1). In simple words both output and errors will be displayed.

{} \ is just representing output of find command.

find means the command is looking for something.

. means start in the current directory

-type d we are looking for directories
-type f we are looking for regular files

-exec chmod 777 {} \; change all the files/directories found so that any hacker can make whatever changes to them that they want

2>&1 means the same as the similar command on Windows 2>1 - write the error output (2) to the same place as the main output (1)