LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   rename a directory you don't know the name of (https://www.linuxquestions.org/questions/linux-newbie-8/rename-a-directory-you-dont-know-the-name-of-4175601643/)

aristosv 03-13-2017 01:28 AM

rename a directory you don't know the name of
 
I have this tarball named "master" and when extracted it creates a directory named "moeiscool-Shinobi-5eea744". It could be any name though depending on what version of "master" is downloaded at the current time.

In a bash script I want to rename "moeiscool-Shinobi-5eea744" to "shinobi", but I don't know what the actual name of the original directory will be. Initially I was thinking about TAB emulation, but I don't know if its the best way, and I might be over-complicating things.

In bash, how would you rename a directory you don't know the name of?

pan64 03-13-2017 01:43 AM

you need to know something about its name. For example it contains the word "shinobi" or you may know its location.
In such cases you can try to cd into its parent and execute:
Code:

rename 's/.*shinobi.*/shinobi/i' *shinobi*
# or just a simple mv:
mv *Shinobi* shinobi


ondoho 03-13-2017 02:03 AM

another idea:
Code:

path1="/tmp/path1"
path2="$HOME/shinobi"
cd path1
untar master # and whatever else you need to do

cd * # assuming there's only one subdirectory

mv * "$path2"
mv .* "$path2"

not tested, some pseudocode.
should work in bash.


All times are GMT -5. The time now is 05:05 PM.