Ever wanted to copy only the executable files from a directory - without any directories or subdirectories? I've got you covered
for i in $(ls -l | grep r-x | grep -v ^d | awk '{print $9}') ; do cp $i $TARGETDIR ; done
Explaination:
ls -l
list all file in the current directorygrep r-x
filter for lines withr-x
in them (include executables)grep -v ^d
filter away lines which start with ad
(exclude directories)awk
print only the 9th column (only print filename)for i in $(filenames); do cp $i $TD; done
copy every file in $filenames to $TD