LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-13-2017, 02:28 AM   #1
aristosv
Member
 
Registered: Dec 2014
Posts: 197

Rep: Reputation: 3
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?
 
Old 03-13-2017, 02:43 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 13,611

Rep: Reputation: 4364Reputation: 4364Reputation: 4364Reputation: 4364Reputation: 4364Reputation: 4364Reputation: 4364Reputation: 4364Reputation: 4364Reputation: 4364Reputation: 4364
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
 
1 members found this post helpful.
Old 03-13-2017, 03:03 AM   #3
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 13,422
Blog Entries: 9

Rep: Reputation: 3668Reputation: 3668Reputation: 3668Reputation: 3668Reputation: 3668Reputation: 3668Reputation: 3668Reputation: 3668Reputation: 3668Reputation: 3668Reputation: 3668
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] ffmpeg - want it to convert/rename/batch, don't overwrite or ask to ejames82 Linux - General 7 01-28-2014 01:11 PM
Rename a directory / Directory owner group leamassiot Linux - General 2 07-27-2012 04:04 AM
rename a directory Volcano Linux - Newbie 5 02-22-2008 08:03 AM
rename all files in my directory BabaKali Linux - Newbie 2 11-10-2004 05:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration