SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Jul 2009
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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:
    PHP Code:
    <?php 

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

    print 
    "\n\nComplete!"
    ?>
    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

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,228
    Mentioned
    194 Post(s)
    Tagged
    2 Thread(s)
    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.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2010
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,862
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    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)
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    SitePoint Addict
    Join Date
    Jul 2009
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Excellent guys! That is some great help. I couldn't possibly had searched google with those weird characters.

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


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •