ravi
ravi

Reputation: 21

copy files to another directory except ".txt" file extension

I have many files with different file extensions,so i want to copy all except

".txt"

to another directory.

I tried below command to find all possible files with different file extensions except ".txt"

ls -lrt /home/updatet/test/ -I "*.txt"

and to copy

ls -1 /home/updatet/test/ | xargs cp {} demo/

Upvotes: 1

Views: 918

Answers (2)

Bjorn A.
Bjorn A.

Reputation: 1178

find /home/updatet/test ! -name \*.txt -exec cp {} demo/ \;

Upvotes: 1

Charles Duffy
Charles Duffy

Reputation: 295638

Using bash extglobs:

See http://wiki.bash-hackers.org/syntax/pattern#extended_pattern_language for documentation

shopt -s extglob
cp /home/updatet/test/!(*.txt) demo/

Portably:

for f in /home/updatet/test/*; do
  case $f in
    *.txt) :;;
    *)     cp "$f" demo/ ;;
  esac
done

Upvotes: 1

Related Questions