Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Inside a directory, there are 150 files named like ABLIMITS.TXT. How do I rename them to ABLIMITS_date.txt prompting the user for date?

share|improve this question

Your question is a little unclear (how can 150 files in a single parent dir all have the same filename?), so here is an example of doing it with a single file named ABLIMITS.TXT, which you can extrapolate as necessary:

In a POSIX shell:

Using the current date

mv ABLIMITS.TXT "ABLIMITS_$(date '+%Y-%m-%d').TXT"

Prompting the user for a date

read -rp "Please enter date: " date
share|improve this answer

I'm going to assume that you want to take the user input, and make sure it follows a standard format (e.g. YYYY-MM-DD). So let's try something like this:

for i in *
  read -p "Enter date for $i: " d
  mv "$i" "${i%.*}_$(date +%Y-%m-%d -d "$d").${i##*.}"

You can read the man page for date to get more information on the format.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.