LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 01:28 AM   #1
aristosv
Member
 
Registered: Dec 2014
Posts: 263

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, 01:43 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
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, 02:03 AM   #3
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
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



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 12:11 PM
Rename a directory / Directory owner group leamassiot Linux - General 2 07-27-2012 03:04 AM
rename a directory Volcano Linux - Newbie 5 02-22-2008 07:03 AM
rename all files in my directory BabaKali Linux - Newbie 2 11-10-2004 04:27 PM

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

All times are GMT -5. The time now is 08:16 AM.

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
Open Source Consulting | Domain Registration