1
On a Linux Centos 4 machine, I am trying to create a simple bash command line to walk a directory structure below an arbitrary current directory and in each subdirectory touch a file, list the directory contents but pipe them to /dev/null
, and remove the touched file. The obscure point of this script is to tickle the underlying NFS client/server system to ensure the contents of each directory are reflecting a change made on a different machine which otherwise may take some time to propogate. I have found this workaround avoids the delay. Ignoring the merits of my reason for doing this, why doesn't my proposed bash script work?
[CentosMachine] find . -type d -print0 | xargs -0 -I {} pushd {}; touch xYzZy.fixZ; ls &> /dev/null; rm -f xYzZy.fixZ; popd
xargs: pushd: No such file or directory
bash: popd: directory stack empty
The find
command is presently returning:
.
./dir
./emptyDir
./dirOfDir
./dirOfDir/ofDir
./dirOfDir/ofDir/Dir(empty)
At first I thought perhaps the (
and )
in one of the directory names might be the issue, but renaming that directory to be ./dirOfDir/ofDir/Dir_empty_
did not change the symptom. I also tried looking at strace
output but did not see anything that helped, but did see the directories being processed.
Here is a snippet of the end of the strace
output with that directory renamed to use underscores instead of parentheses:
[...]
chdir("ofDir") = 0
lstat64(".", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
lstat64("Dir_empty_", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
open("Dir_empty_", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY) = 4
fstat64(4, {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
fcntl64(4, F_SETFD, FD_CLOEXEC) = 0
getdents64(4, /* 2 entries */, 32768) = 48
getdents64(4, /* 0 entries */, 32768) = 0
close(4) = 0
chdir("Dir_empty_") = 0
lstat64(".", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
chdir("..") = 0
lstat64(".", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
chdir("..") = 0
lstat64(".", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
chdir("..") = 0
lstat64(".", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
fchdir(3) = 0
write(1, ".\0./dir\0./emptyDir\0./dirOfDir\0./"..., 75) = 75
exit_group(0) = ?
You answered your question without answering your question. The short answer is that
xargs
can’t take a compound command; you need to wrap the compound command in a string and pass it to the shell. – Scott – 2014-07-18T22:18:42.097