bashスクリプティングは初めてです。要件はBASH copy all files except oneに似ています。ファイルで始まるすべてのファイルをコピーしようとしていますが、ファイル〜(バックアップファイル)で始まる1つのファイルを除外しています。これは私がhvaeがこれまでにbashで試したものです。Bash:少数を除いて特定のタイプのすべてのファイルをコピーする
path1="/home/dir1/file*" (I know this * doesn't work - wildcards)
file_to_exclude="/home/dir1/file~*"
dest=/var/dest
count=`ls -l "$path1" 2>/dev/null | wc -l`
if [ $count !=0 ]
then
cp -p !$file_to_exclude $path1 $dest (Not sure if this is the way to exclude backup file)
fi
誰でもこの問題の解決方法を教えてください。代わりに、行の
file_to_exclude="some_pattern"
all_files=`ls /home/dir1/file*`
for file in $all_files; do
if [ "$file" != "$file_to_exclude" ]; then
cp $file /some/path
fi
done
方法でファイルをしたい場合は
あるいは、 home/dir1/file [^〜] * $ dest'? – Abdulrahman