I have been trying to copy all files with read/write permissions for owners from the home directory to another directory but i've been facing this problem as in the title. any help? :(
subDir=`date ' %y%m%d%H%M%S'` mkdir $subDir cp -R 'ls -l ~/ | grep ^.r\w\-' $subDir chmod -wx $subDir/*
CodePudding user response:
Do not parse ls. To find files use find
.
find . -type f -perm -u=rw -exec cp {} "$subDir" ';'
# Faster:
... -exec cp -t "$subDir" {}
I think you want find ~ -maxdepth 1
, I do not know if recursive files or not.