Solved

Need to find and replace files without extension.

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to install Ubuntu 16 in DELL venue 8 pro 20 133
How code a 301 redirect for folder files -> 1 file 2 39
batch file problem 5 45
how to configure linux OS using Ubuntu 7 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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
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.

785 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