how to change names of directory in a given directory
I am new to unix.
I have 1 directory(parent) where it has 5 directories in it. I want to rename the parent directory as well 5 directories in it. for example: mv -rf ${i}/${j}/ ${i}_new/${prefix_name}_${j}/ ${i}---> list of parent directories ${j}---> list of child directories present in parent directory. ${i}_new--->parent directory to be renamed. ${prefix_name}_${j}---> child directory to be renamed. Is the above command correct? can anyone help me for this as i am using this in one of my script. Thanks UNIX forum. |
Just for remane purpose you can use:-
Code:
~$ mv <old_name> <new_name> Code:
#!/bin/bash |
1) Please use ***[code][/code]*** tags around your code and data, to preserve the original formatting and to improve readability. Do not use quote tags, bolding, colors, "start/end" lines, or other creative techniques.
2) Always quote variables to avoid word-splitting on whitespace, especially when working with filenames. http://mywiki.wooledge.org/Arguments http://mywiki.wooledge.org/WordSplitting http://mywiki.wooledge.org/Quotes But the ${..} brackets around variables do nothing except clutter up the code (in most cases). I recommend leaving them off generally. 3) But what do you mean when you say things like "${i}---> list of parent directories"? Does the $i variable contain more than a single entry? If so, then you can't just use a single command. You have to break it up somehow and loop over the individual entries. Could you please post an example filetree and how you want it to look afterwards? |
@shivaa, you're still using the incorrect for loop pattern. I've mentioned this several times in threads you've posted. Would you please stop suggesting it to people?
Parsing ls isn't recommended either. |
This sounds like homework to me.
|
Hello David,
I agree. Since you suggested me to use while+read instead of using for, I have been using while+read only. But I was just waiting for your response on an another thread (see) to find out how can I use read to capture input inside while+read loop. Anyway, thanks for a explainations. @unix2000: Try to follow what David the H. has suggested above. |
Quote:
Code:
for dir in /path/to/parent_dir/* OP: Code:
mv "/path/to/parent" "/path/to/parent_new" |
Quote:
But then again the question in that thread does cover a rather specific situation, and doesn't prevent you from avoiding DRLWF loops elsewhere. ;) |
All times are GMT -5. The time now is 05:26 AM. |