Find the answer to your Linux question:
Results 1 to 8 of 8
I am new to Fedora Core 3.0 Linux version. I have a folder in the Linux server that I have set. I want to add the sticky bit to a ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2006
    Posts
    3

    Sticky Bit on a directory - How to?


    I am new to Fedora Core 3.0 Linux version.

    I have a folder in the Linux server that I have set.

    I want to add the sticky bit to a particular directory and it should cascade to the sub-directories inside it so that no one can delete the directory, its sub-directories or the files inside it.

    What command should I use or can I do it through Samba?

    Please help.

  2. #2
    Linux Guru AlexK's Avatar
    Join Date
    Feb 2005
    Location
    Earth
    Posts
    3,379
    if I understand you correctly, you don't want anyone deleting a particular directory and any sub-directories, is that right? (don't understand the sticky bit part though).

    take a look at the chmod command, should set the permissions for a particular directory and the -R flag sets it for every file and sub-directory in it.

    basic syntax is:
    Code:
    chmod -R <permissions> /path_to_top_level_directory
    Life is complex, it has a real part and an imaginary part.

  3. #3
    Just Joined!
    Join Date
    May 2006
    Posts
    3

    Chmod command

    Dear Alex,

    The main directory under

    home/edp_k - Current permissions is - drwxrwxrwt (1777)

    home/edp_k/perp - Current permissions is - drwxr-xr-t (1755)

    Can you tell me the exact command that I should type for edp_k and the perp folder individually?

    Regards,

    IG

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru AlexK's Avatar
    Join Date
    Feb 2005
    Location
    Earth
    Posts
    3,379
    if you want to change permissions for home/edp_k and all folders beneath it so that
    1. Owner can do anything
    2. Group can read
    3. Others can read

    execute this:
    Code:
    chmod -R 744 home/edp_k/
    for more info take a look at:
    Code:
    man chmod
    Life is complex, it has a real part and an imaginary part.

  6. #5
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    To delete a file, you need write permissions to its directory. So if no one can delete anything below /home/edp_k/perp, you need to run:
    Code:
    chmod -R -w /home/edp_k/perp
    That recursively (-R) removes write permission (-w) from that directory, all its subdirectories, and all files within. Though now that I think about it, that'll also lose write permissions to the files. If you want to keep write permissions on the files, try a:
    Code:
    find /home/edp_k/perp -exec if[ -d {} ]; then chmod -w {}; fi \;
    That should work.

  7. #6
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Slackware, {Free, Open, Net}BSD, Solaris
    Posts
    1,297
    Hi, iguha.

    If you were trying to make your directory act like /tmp, then the sticky bit is certainly something to consider:
    Quote Originally Posted by man chmod
    STICKY DIRECTORIES
    When the sticky bit is set on a directory, files in that directory may
    be unlinked or renamed only by root or their owner. Without the sticky
    bit, anyone able to write to the directory can delete or rename files.
    The sticky bit is commonly found on directories, such as /tmp, that are
    world-writable.
    However, if you don't need to allow users to create files and directories, then removing permissions may address the problem. Note that even if write permission is missing from a directory, a file can still be modified if write permission is set for the file. I haven't tried this recently, so you need to do some work here with the information we've provided.

    It's always useful to practice on a scratch directory structure, particularly from other logins, as necessary.

    If these posts don't address your problem, please give us more details.

    Best wishes ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  8. #7
    Banned CodeRoot's Avatar
    Join Date
    Sep 2005
    Posts
    567
    Quote Originally Posted by iguha
    home/edp_k - Current permissions is - drwxrwxrwt (1777)
    home/edp_k/perp - Current permissions is - drwxr-xr-t (1755)
    You already have the sticky bit set - the 't' and the '1' represent that.

    The "symbolic" command to turn it "on":

    Code:
    chmod +t <target>
    The "symbolic" command to turn it "off":

    Code:
    chmod -t <target>

  9. #8
    Just Joined!
    Join Date
    Dec 2009
    Posts
    3

    Exclamation syntax error near unexpected token `then'

    sorry, but this does not work:
    find /home/edp_k/perp -exec if[ -d {} ]; then chmod -w {}; fi \;
    -bash: syntax error near unexpected token `then'

    try this:

    HTML Code:
    find /home/edp_k/perp -type d -exec chmod g+s {} \;
    This command sets sticky bit for group on all folders and subfolders but not on files

Posting Permissions

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