0

Normally, the ls -la command shows the files and the copy access rights, owners and access group. **

  • How can I list only list the directories/files that I have access to?
  • How can I copy these directories/files to a destination directory?
alvas
  • 115,346
  • 109
  • 446
  • 738
  • Access is defined as read/write/execute in simple terms. Which one you are referring to? – anubhava Sep 13 '13 at 11:00
  • rights to copy, so i assume that's write/execute access. – alvas Sep 13 '13 at 11:42
  • For the first part `How can I list only list the directories/files that I have access to?` you just need read permissions on files and read/execute permissions on directories. – anubhava Sep 13 '13 at 12:06
  • 1
    Do you actually need the list before the copy? You could do a cp -pr src dest, then whatever gets copied is what you had access to. – kielni Sep 13 '13 at 15:06

2 Answers2

1

Try this:

a=`find $Your_Source_Path -iname "yourFolder_whose_Files_tohide" -prune -o -type f -print`
for i in $a
do
   cp $Your_source $Your_Dest_Path
done
Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56
0

One more answer which will copy only those files whose having copy access permission. For this first navigate to the directory whose file wanted to copy. Also inside this mention your destination path first where you wanted to copy. Try the below:-

destination_Path="/Users/Home/Desktop/test"
b=~/Desktop/copyPermission.txt
if [ ! -f $b ]
then 
touch $b 
fi
a=`ls -l`
e="-----w--w-"
echo "\n$a" | sed '1d' > $b
g=`pwd`
while read line
do 
d=`echo "$line" | awk '{print $1}'`
if [ $e != $d ]
then
r=`echo "$line" | awk '{print $9}'`
echo "Can have copy permission $g/$r" 
{
cp $g/$r "$destination_Path" && echo "copied successfully"
} || {
echo "cannot copy due to some error"
}
#else
#r=`echo "$line" | awk '{print $9}'`
#echo "Cannot have copy permission $r"
fi
done <"$b"
Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56