We can copy some file by extensions like this:
cp *.txt ../new/
but how can I copy all files that have no extension?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
The answer from @ubaid-ashraf is almost there. The way to specify file with no extension, in
ksh would be:
cp -- !(*.*) /new/path/
so that any file with dot in file name is skipped.
For that to work in
bash, you need to enable the
extglob option (
shopt -s extglob) and the
kshglob option in
set -o kshglob).
You can do something like:
cp -- !(*.txt) /path/to/directory
The above code will copy all the files without .txt extension. You can also give multiple extension via pipe character.
cp -- !(*.txt|*.c|*.py) /path/to/directory
You can use find+grep to get only files that have no extension
find . -maxdepth 1 -type f | sed 's/^\.\///' | grep -v "\."
So your copy command will be
cp ` find . -maxdepth 1 -type f | sed 's/^\.\///' | grep -v "\." ` destination_folder