Solved

Need to find and replace files without extension.

Posted on 2013-01-06
2
398 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How yum repo uses sqlite3 to keep metadata about the repository? 2 46
How to enable sync between two yum repo? 1 39
ftp to port 21 4 53
Powershell command 2 37
Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

839 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