Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 424
  • Last Modified:

Need to find and replace files without extension.

I have a bunch of text files in a directory that do not have the .txt extension... what is a god one liner to add the .txt extension to these files but if the files already have and extension of some sort omit those?
0
Thaidog
Asked:
Thaidog
1 Solution
 
Thomas GrassiSystems AdministratorCommented:
0
 
woolmilkporcCommented:
cd /path/to/directory
find . -type f -maxdepth 1 ! -name "*\.[0-9A-Za-z]*" -print0| xargs -0 -i{} echo mv {} {}.txt

echo is for a dry run. Remove it to perform the actual operation.

The above assumes "extension of some sort" consisting of a dot "." and any number of alphanumeric characters.
Should you want to test for shorter extensions only please let me know!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now