Solved

Need to find and replace files without extension.

Posted on 2013-01-06
2
393 Views
Last Modified: 2013-01-17
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
Comment
Question by:Thaidog
2 Comments
 
LVL 23

Expert Comment

by:Thomas Grassi
ID: 38748765
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 38748785
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now