Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have logged into a server via sftp via terminal.

When I run the command

chmod -R 755 ./*

I get the error You must supply a numeric argument to the chmod command.. How do I apply a recursive chmod 755 while in sftp?

share|improve this question
    
yes - that's what i wrote in my question –  John Oct 16 '12 at 14:27
1  
chmod 755 -R ./* in this way? –  poz2k4444 Oct 16 '12 at 14:40
    
@John: I edited my answer yesterday, I think I found what you were looking for, have a glance at it... –  jaume Oct 18 '12 at 8:22
add comment

2 Answers 2

up vote 1 down vote accepted

You may not be able to. There's a good chance the chmod available to you via FTP or SFTP does not support the recursive option. Commands available under FTP/SFTP are often somewhat crippled versions of what you'd have available locally under the shell. If you're lucky, chmod may act recursively even without the -R option but if you're unlucky, you'll have to traverse the tree, chmod'ing each level one-at-a-time.

share|improve this answer
    
Or write a script that does it for you. –  Rob Oct 16 '12 at 15:41
    
Sure, you can write a script, but the script has parse the result of the remote ls one level at a time and use that to create the list of subdirs, then keep recursing. Not only is it doable, I've done it myself when I had to manage a remote FTP site. But it's a fair amount of work. –  Nicole Hamilton Oct 16 '12 at 15:51
add comment

From man sftp:

chmod mode path

Change permissions of file path to mode. path may contain glob(3) characters and may match multiple files.

man 7 glob (man 3 glob references glob(7)) describes the *, ? and [] wildcard patterns we are familiar with when using ls. So you could use:

chmod 755 ./*
chmod 755 ./*/*
chmod 755 ./*/*/*

repeatedly until you have reached all files and get the error:

Couldn't setstat on "./*/*/*": No such file or directory

Before such a mass change, you could double-check in advance which directories would be affected with lls (from man sftp):

lls [ls-options [path]]

Display local directory listing of either path or current directory if path is not specified. ls-options may contain any flags supported by the local system's ls(1) command. path may contain glob(3) characters and may match multiple files.

like this (specify an absolute path to lls to avoid surprises):

lls -Rla /path

You can also use lls -Rla /path to make sure your chmod worked as expected.

share|improve this answer
1  
Multi-level wildcards may or may not be supported, depending on the server. But if it works at all, you're right, this is a good way to do it. –  Nicole Hamilton Oct 16 '12 at 23:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.