Если вы хотите быть в безопасности/обрабатывать имена файлов с пробелами, переводами строк, кавычками, обратными косыми чертами и т. д., вы должны использовать нулевые -разделители в конце:
find "$srcdir" -maxdepth 1 -type f -print0 | head -z -n 100 | xargs -0 -r -- mv -t "$destdir" --
РЕДАКТИРОВАТЬ2:ПРИМЕЧАНИЕ:если у вас нетhead -z
(по какой-либо причине)вы можете заменить указанный выше head -z -n 1000
наtr '\0\n' '\n\0' | head -n 1000 | tr '\0\n' '\n\0'
(или см. другие способы)
-maxdepth 1
не будет искать файлы в подкаталогах $srcdir
, поэтому перечислены только файлы в $srcdir
. -print0
будет использовать \0
вместо новой строки(\n
)между каждым перечисленным файлом -это помогает обрабатывать файлы, содержащие символы новой строки и пробелы, с помощью xargs. head -z
будет считать \0
завершенные (вместо новой строки(\n
)завершенные )строки строками. -n 100
перечислит только первые 100
файлы, найденные find
.
Если вы хотите увидеть, какая команда xargs
будет выполнена, добавьте-t
(или --verbose
). xargs -0
«Элементы ввода заканчиваются нулевым символом(\0
)вместо пробела,и кавычки и обратная косая черта не являются специальными (каждый символ воспринимается буквально )" xargs -r
не запустится mv
, если нет файлов для перемещения (, т.е. если find
не нашел ни одного файла ). --
прекращает обработку аргументов как опций программы, подробнее здесь
Пример вывода (запускает одну команду mv
и также может обрабатывать файлы с символами новой строки в имени):
$ find /tmp/t -maxdepth 1 -type f -print0 | head -z -n 100 | xargs -t -0 -r -- mv -t /tmp -- ; echo "exit codes: ${PIPESTATUS[@]}"
mv -t /tmp -- /tmp/t/file containing quotes"' then spaces /tmp/t/file containing quotes"' /tmp/t/file containing a slash n here\n /tmp/t/file containing a new line here
and continues /tmp/t/s /tmp/t/-x and -L 1. /tmp/t/of replace-str in the initi /tmp/t/-thisfile_starts_with_a_hyphen and has spaces and a -hyphen here /tmp/t/-thisfile_starts_with_a_hyphen and has spaces /tmp/t/-thisfile_starts_with_a_hyphen /tmp/t/another with spaces /tmp/t/one with spaces /tmp/t/c /tmp/t/a
exit codes: 0 0 0
$ ls -1R /tmp/t
/tmp/t:
a
'another with spaces'
b
c
'file containing a new line here'$'\n''and continues'
'file containing a slash n here\n'
'file containing quotes"'\'''
'file containing quotes"'\'' then spaces'
'of replace-str in the initi'
'one with spaces'
s
'some dir'
-thisfile_starts_with_a_hyphen
'-thisfile_starts_with_a_hyphen and has spaces'
'-thisfile_starts_with_a_hyphen and has spaces and a -hyphen here'
'-x and -L 1.'
/tmp/t/b:
'file with spaces'
'/tmp/t/some dir':
'some file'
Дляfind
:
-maxdepth levels
Descend at most levels (a non-negative integer) levels of direc‐
tories below the starting-points. -maxdepth 0
means only apply the tests and actions to the starting-points
themselves.
-type c
File is of type c:
b block (buffered) special
c character (unbuffered) special
d directory
p named pipe (FIFO)
f regular file
l symbolic link; this is never true if the -L option or the
-follow option is in effect, unless the symbolic link is
broken. If you want to search for symbolic links when -L
is in effect, use -xtype.
s socket
D door (Solaris)
-P Never follow symbolic links. This is the default behaviour.
When find examines or prints information a file, and the file is
a symbolic link, the information used shall be taken from the
properties of the symbolic link itself.
-L Follow symbolic links. When find examines or prints information
about files, the information used shall be taken from the prop‐
erties of the file to which the link points, not from the link
itself (unless it is a broken symbolic link or find is unable to
examine the file to which the link points). Use of this option
implies -noleaf. If you later use the -P option, -noleaf will
still be in effect. If -L is in effect and find discovers a
symbolic link to a subdirectory during its search, the subdirec‐
tory pointed to by the symbolic link will be searched.
When the -L option is in effect, the -type predicate will always
match against the type of the file that a symbolic link points
to rather than the link itself (unless the symbolic link is bro‐
ken). Actions that can cause symbolic links to become broken
while find is executing (for example -delete) can give rise to
confusing behaviour. Using -L causes the -lname and -ilname
predicates always to return false.
Дляhead
:
-n, --lines=[-]NUM
print the first NUM lines instead of the first 10; with the
leading '-', print all but the last NUM lines of each file
-z, --zero-terminated
line delimiter is NUL, not newline
РЕДАКТИРОВАТЬ:Кто-то упомянул , что у них не было head -z
, это версия, которую я использовал (в Fedora 25):
$ head --version
head (GNU coreutils) 8.25
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later .
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by David MacKenzie and Jim Meyering.
$ rpm -qf /usr/bin/head
coreutils-8.25-17.fc25.x86_64
Дляxargs
:
-0, --null
Input items are terminated by a null character instead of by
whitespace, and the quotes and backslash are not special (every
character is taken literally). Disables the end of file string,
which is treated like any other argument. Useful when input
items might contain white space, quote marks, or backslashes.
The GNU find -print0 option produces input suitable for this
mode.
-r, --no-run-if-empty
If the standard input does not contain any nonblanks, do not run
the command. Normally, the command is run once even if there is
no input. This option is a GNU extension.
-P max-procs, --max-procs=max-procs
Run up to max-procs processes at a time; the default is 1. If
max-procs is 0, xargs will run as many processes as possible at
a time. Use the -n option or the -L option with -P; otherwise
chances are that only one exec will be done. While xargs is
running, you can send its process a SIGUSR1 signal to increase
the number of commands to run simultaneously, or a SIGUSR2 to
decrease the number. You cannot increase it above an implemen‐
tation-defined limit (which is shown with --show-limits). You
cannot decrease it below 1. xargs never terminates its com‐
mands; when asked to decrease, it merely waits for more than one
existing command to terminate before starting another.
Please note that it is up to the called processes to properly
manage parallel access to shared resources. For example, if
more than one of them tries to print to stdout, the ouptut will
be produced in an indeterminate order (and very likely mixed up)
unless the processes collaborate in some way to prevent this.
Using some kind of locking scheme is one way to prevent such
problems. In general, using a locking scheme will help ensure
correct output but reduce performance. If you don't want to
tolerate the performance difference, simply arrange for each
process to produce a separate output file (or otherwise use sep‐
arate resources).
-t, --verbose
Print the command line on the standard error output before exe‐
cuting it.
Дляcp
:
-t, --target-directory=DIRECTORY
copy all SOURCE arguments into DIRECTORY
-v, --verbose
explain what is being done
Задокументированный способ переопределения переменных при запуске configure
заключается в указании их значений в качестве аргументов для configure
, как объяснено в./configure --help
:
`configure' configures transmission 3.00 to adapt to many kinds of systems.
Usage:./configure [OPTION]... [VAR=VALUE]...
To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables.
В вашем случае
./configure --disable-cli --disable-mac --disable-daemon --enable-utp --with-gtk --with-crypto=openssl CFLAGS='-O2 -march=native' CXXFLAGS='-O2 -march=native' CC=gcc-10 CPP='gcc-10 -E' CXX=g++-10
configure
по умолчанию учитывает переменные окружения , поэтому их установка также работает . В обоих случаях набор значений сохраняется в config.status
(, если переменные отмечены как «драгоценные» )и учтены с помощью config.status --recheck
. Документация Autoconf рекомендует указывать переменные в качестве аргументов , а не полагаться на среду.
То, что сработало (, но не является официальным подходом ), в моем случае Transmission 3.00 заключалось в том, чтобы просто добавить их перед ./configure
, вот так, я не буду изменять свою команду и помещать ее в полный:
CFLAGS='-O2 -march=native' CXXFLAGS='-O2 -march=native' CC='gcc-10' CPP='gcc-10 -E' CXX='g++-10'./configure --disable-cli --disable-mac --disable-daemon --enable-utp --with-gtk --with-crypto=openssl