Почему делает 'комнату-f! (/var/www/wp)' оставляют файлы в/var/www?

Вы попробовали другим пользователем вместо пользователя root? В последней мягкой фетровой шляпе существует ограничение для корня. Можно изменить его от:/etc/ssh/ssh_config

5
03.03.2018, 17:36
4 ответа

Вы можете прочитать Ответ Михаила Гомера , чтобы узнать причину.

Удалить все в / var / www WP , POSIXLY:

find /var/www -path /var/www/wp -prune -o ! -path /var/www -exec rm -rf {} +
9
27.01.2020, 20:31

Если вы используете Bash ≥4.3, то если у вас есть резервные копии, теперь будет хорошее время, чтобы их найти .

Я предполагаю, что вы используете Bash. ! (...) Узор расширения имени файла расширяется на каждом существующем пути, который не соответствует шаблону в точке, который он используется . То есть:

echo rm  -f  !(/var/www/wp)

расширяется до каждого имени файла в текущем каталоге, который не «/ var / www / wp». Это каждый файл в текущем каталоге. По сути, вы работали RM -F * в ~ . Не запускайте команду RM выше .

Чтобы получить эффект, который вы хотите, используйте шаблон только для части пути, который вы хотите (не), чтобы соответствовать, как вы бы для * , {A, B, C} или любой другой шаблон. Команда:

echo rm -f /var/www/!(wp)

распечатает команду, которую вы хотели запустить.

Я не должен, честно говоря, предложить делать вещи таким образом - это склонна к ровному вопросу, которую вы имели здесь, и другие. Что-то с Найти легче следовать. По крайней мере, Echo Команда, прежде чем запустить ее, и вы увидите, что происходит.

37
27.01.2020, 20:31
 user@host:~$ rm --help
Usage: rm [OPTION]... FILE...
Remove (unlink) the FILE(s).

  -f, --force           ignore nonexistent files and arguments, never prompt
  -i                    prompt before every removal
  -I                    prompt once before removing more than three files, or
                          when removing recursively.  Less intrusive than -i,
                          while still giving protection against most mistakes
      --interactive[=WHEN]  prompt according to WHEN: never, once (-I), or
                          always (-i).  Without WHEN, prompt always
      --one-file-system  when removing a hierarchy recursively, skip any
                          directory that is on a file system different from
                          that of the corresponding command line argument
      --no-preserve-root  do not treat '/' specially
      --preserve-root   do not remove '/' (default)
  -r, -R, --recursive   remove directories and their contents recursively
  -d, --dir             remove empty directories
  -v, --verbose         explain what is being done
      --help     display this help and exit
      --version  output version information and exit

By default, rm does not remove directories.  Use the --recursive (-r or -R)
option to remove each listed directory, too, along with all of its contents.

To remove a file whose name starts with a '-', for example '-foo',
use one of these commands:
  rm -- -foo

  rm ./-foo

Note that if you use rm to remove a file, it might be possible to recover
some of its contents, given sufficient expertise and/or time.  For greater
assurance that the contents are truly unrecoverable, consider using shred.

Report rm bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
For complete documentation, run: info coreutils 'rm invocation'

Идея обходного пути:

:~$

cd /var/www
 мкдир /опт/движение
 мв жп /опт/движение/вп
 rm -r *
 мв /opt/wp /var/www/wp
[опционально ;)]] chown -R www-data:www-data /var/wwww

user@host:~$ mv Ссылка:

mv --help
Usage: mv [OPTION]... [-T] SOURCE DEST
  or:  mv [OPTION]... SOURCE... DIRECTORY
  or:  mv [OPTION]... -t DIRECTORY SOURCE...
Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.

Mandatory arguments to long options are mandatory for short options too.
      --backup[=CONTROL]       make a backup of each existing destination file
  -b                           like --backup but does not accept an argument
  -f, --force                  do not prompt before overwriting
  -i, --interactive            prompt before overwrite
  -n, --no-clobber             do not overwrite an existing file
If you specify more than one of -i, -f, -n, only the final one takes effect.
      --strip-trailing-slashes  remove any trailing slashes from each SOURCE
                                 argument
  -S, --suffix=SUFFIX          override the usual backup suffix
  -t, --target-directory=DIRECTORY  move all SOURCE arguments into DIRECTORY
  -T, --no-target-directory    treat DEST as a normal file
  -u, --update                 move only when the SOURCE file is newer
                                 than the destination file or when the
                                 destination file is missing
  -v, --verbose                explain what is being done
      --help     display this help and exit
      --version  output version information and exit

The backup suffix is '~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.
The version control method may be selected via the --backup option or through
the VERSION_CONTROL environment variable.  Here are the values:

  none, off       never make backups (even if --backup is given)
  numbered, t     make numbered backups
  existing, nil   numbered if numbered backups exist, simple otherwise
  simple, never   always make simple backups

Report mv bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
For complete documentation, run: info coreutils 'mv invocation'

user@host:~$ chown Ссылка:

chown --help                                                                                                                              
    Usage: chown [OPTION]... [OWNER][:[GROUP]] FILE...                                                                                                           
      or:  chown [OPTION]... --reference=RFILE FILE...                                                                                                           
    Change the owner and/or group of each FILE to OWNER and/or GROUP.                                                                                            
    With --reference, change the owner and group of each FILE to those of RFILE.                                                                                 

      -c, --changes          like verbose but report only when a change is made                                                                                  
      -f, --silent, --quiet  suppress most error messages                                                                                                        
      -v, --verbose          output a diagnostic for every file processed                                                                                        
          --dereference      affect the referent of each symbolic link (this is                                                                                  
                             the default), rather than the symbolic link itself                                                                                  
      -h, --no-dereference   affect symbolic links instead of any referenced file                                                                                
                             (useful only on systems that can change the                                                                                         
                             ownership of a symlink)                                                                                                             
          --from=CURRENT_OWNER:CURRENT_GROUP                                                                                                                     
                             change the owner and/or group of each file only if                                                                                  
                             its current owner and/or group match those specified                                                                                
                             here.  Either may be omitted, in which case a match                                                                                 
                             is not required for the omitted attribute                                                                                           
          --no-preserve-root  do not treat '/' specially (the default)                                                                                           
          --preserve-root    fail to operate recursively on '/'                                                                                                  
          --reference=RFILE  use RFILE's owner and group rather than                                                                                             
                             specifying OWNER:GROUP values
      -R, --recursive        operate on files and directories recursively

    The following options modify how a hierarchy is traversed when the -R
    option is also specified.  If more than one is specified, only the final
    one takes effect.

      -H                     if a command line argument is a symbolic link
                             to a directory, traverse it
      -L                     traverse every symbolic link to a directory
                             encountered
      -P                     do not traverse any symbolic links (default)

          --help     display this help and exit
          --version  output version information and exit

    Owner is unchanged if missing.  Group is unchanged if missing, but changed
    to login group if implied by a ':' following a symbolic OWNER.
    OWNER and GROUP may be numeric as well as symbolic.

    Examples:
      chown root /u        Change the owner of /u to "root".
      chown root:staff /u  Likewise, but also change its group to "staff".
      chown -hR root /u    Change the owner of /u and subfiles to "root".

    Report chown bugs to bug-coreutils@gnu.org
    GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
    General help using GNU software: <http://www.gnu.org/gethelp/>
    For complete documentation, run: info coreutils 'chown invocation'
-2
27.01.2020, 20:31

Найти, комбинацию GREP и XARGS

find /var/www/ -maxdepth 1|grep -v wp|xargs rm -rf

и могут преобразовать в файл Bash, для более обобщенной цели.

#!bash
# $1 -- directory 
# $2 -- Exception filename or directory name
find "$1" -maxdepth 1|grep -v "$2"|xargs rm -rf
0
27.01.2020, 20:31

Теги

Похожие вопросы