RSS Subscription
Linux Howtos & Tutorials

Enter your email:

Delivered by


NOTE:New tutorials are from LinuxCareer.com

Poll

Do you own or wish to have iPhone?
 


Linux eBooks FREE Download
A guide to programming Linux kernel modules
Introduction to Linux - A Hands on Guide
A Newbie's Getting Started Guide to Linux

Linux from Scratch - Create Your Own Linux System - Free eBook

Linux: The Hacking Solution (v.3.0)

SQLite 3 with PHP Essential Training – Free Video Training Tutorials

This guide will introduce you to the world of GNU/Linux

The GNU/Linux Advanced Administration

A Complete Beginner's Manual for Ubuntu 10.04 (Lucid Lynx)

Advanced Bash-Scripting Guide

Set up, maintain, and secure a small office email server

Partner Linux Sites:
How-To.LinuxCareer.com
Jobs.LinuxCareer.com
TuxMachines
Monsterb
LinuxBloggers
AdamsInfo
LinuxScrew
All For Linux

Rename all files and prefix a time-stamp to all file names

Question:

Hi is there a way to rename all files in a directory and prefix a time-stamp to all files? thanks

Answer:

For that you can use a following set of commands:

First declare a time-stamp variable in a format to fit your needs. For example:

$ TS=$( date +%Y%m%d%H%M )

This will create a bash variable called TS with a value of current date and time:

$ echo $TS
201101230708

Feel free to modify a timestamp to fit your needs. When ready navigate to a directory in where you wish to rename all files by appending a time-stamp prefix and execute a following command:

$ for file in $( ls ); do mv $file $TS-$file; done

This will rename all files in your current directory to:

201101230708-myfilename

Of course you can combime all commands in a single command:

$ for file in $( ls ); do mv $file $( date +%Y%m%d%H%M )_$file; done

Hope this helps.

Linux questions and answers

Share this linux post:

Submit Rename all files and prefix a time-stamp to all file names in Delicious Submit Rename all files and prefix a time-stamp to all file names in Digg Submit Rename all files and prefix a time-stamp to all file names in FaceBook Submit Rename all files and prefix a time-stamp to all file names in Google Bookmarks Submit Rename all files and prefix a time-stamp to all file names in Stumbleupon Submit Rename all files and prefix a time-stamp to all file names in Technorati Submit Rename all files and prefix a time-stamp to all file names in Twitter
 
Comments for this page are closed !!!
Please visit our new Linux Forum for additional help or discussion.


Linux eBooks FREE Download