1

i am not able to rename the folder name. i tried these ways. please correct me,

[testuser@backupdev1-lnx backup]$ cd /opt/backup/    
[testuser@backupdev1-lnx backup]$ ls -l
total 8
drwxrwxr-x 2 testuser testuser 4096 May 14 21:46 deployables
drwxrwxr-x 3 testuser testuser 4096 May 14 21:46 deployables_05_14_2013
[testuser@backupdev1-lnx backup]$ rename deployables deployables_$(date +"%m_%d_%Y")
[testuser@backupdev1-lnx backup]$ ls -l
total 8
drwxrwxr-x 2 testuser testuser 4096 May 14 21:46 deployables
drwxrwxr-x 3 testuser testuser 4096 May 14 21:46 deployables_05_14_2013
[testuser@backupdev1-lnx backup]$
[testuser@backupdev1-lnx backup]$ mv -f deployables deployables_$(date +"%m_%d_%Y")
mv: cannot move `deployables' to a subdirectory of itself, `deployables_05_14_2013/deployables'
[testuser@backupdev1-lnx backup]$
6
  • 1
    Please show ls -l instead of just ls. I wonder if perhaps deployables_05_14_2013 is a symlink to deployables. – Celada May 15 '13 at 2:25
  • Also, it looks like you are using the mm dd yyyy convention for date formats. This convention is illogical and problematic because it is neither more-significant-toward-less-significant nor less-significant-toward-more-significant. You should consider using ISO 8601's YYYY-mm-dd (most-significant-to-least-significant), or, failing that, at least use dd-mm-YYYY (least-significant-to-most-significant). – Celada May 15 '13 at 2:27
  • i changed my request. please check – Sun May 15 '13 at 3:02
  • @Celada the mm dd yyyy is the natural way to write dates for English speakers since that is how dates are spoken, for example May 15th, 2013. As a European, I am more used to 14/05/13 but the US convention is 05/14/13. – terdon May 15 '13 at 11:04
  • @terdon It may be natural in spoken English where you say the name of the month, but I don't find it natural at all in writing. On a more objective note, the biggest flaw of this format is that it is probably going to get misinterpreted whenever the day number is 12 or less (because it looks like a month number). The workaround for this is to use the month name instead of number... which is exactly what is done in speech. – Celada May 15 '13 at 12:05
2

This page at www.tuxfiles.org provides good information on manipulating directories in Linux. Since it appears you want delete the existing directory, the following command(s) will suffice:

rm -r deployables_$(date +"%m_%d_%Y"); mv deployables deployables_$(date +"%m_%d_%Y")

The mv command does does not overwrite directories and the destination needs to be removed before hand with the rm -r command. This will generate a harmless error if the source directory does not already exist.

3
  • Exactly @terdon. If the destination is a directory, the source file, file or directory, is placed into the destination, not overwriting the destination. – edwardbackstrom May 15 '13 at 13:24
  • Ummm... reading my comment again, I have no idea what I was talking about... Comment deleted, upvote added. – terdon May 15 '13 at 13:33
  • I got solved, that my mistake, actually "deployables_05_14_2013" folder already exist, so it not able to rename to the "deployables" to "deployables_05_14_2013" again. So it is not working. i added time and date both, then it working. – Sun May 16 '13 at 4:43
0

I got solved,

That my mistake, actually "deployables_05_14_2013" folder already exist, so it not able to rename to the "deployables" to "deployables_05_14_2013" again.

So it is not working. i added time and date both, then it working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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