LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-09-2014, 04:04 AM   #1
powerplyer
Member
 
Registered: Mar 2012
Posts: 31

Rep: Reputation: Disabled
File Renaming Help


I have a script which outputs two files with variables. One is a text and the other is a .tar.gz file. I would like to rename them the same name and keep the extensions as is.

x is the variable.

For example to two files output currently
Test_SNXXXX.txt (Main Generated from Script)
Test_Final_XXXXXX.tar.gz (Generated from a script from within the main script)

Here is what I would like to do.
Keep the name of Test_SNXXXX.txt
Rename Test_Final_XXXX.tar.gz to Test_SNXXXX.tar.gz

I would like to do this from within my script. I am newbie so sorry for the dumb question.
 
Old 05-09-2014, 04:07 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,840

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
would be much easier if you show us that script....
 
Old 05-09-2014, 09:41 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Agreed ... a little tough to replace a tire when you are blindfolded
 
Old 05-10-2014, 12:02 PM   #4
powerplyer
Member
 
Registered: Mar 2012
Posts: 31

Original Poster
Rep: Reputation: Disabled
thanks for the quick replies, i found that using cp command and setting a path solved the issue. thank you
 
Old 05-10-2014, 03:17 PM   #5
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
And, for almost all Linux/GNU systems, the file extension is of no significance. The file type is identified by the file's "magic number" in its first link.

For example, watch this interchange of a directory and a zip file's name:
Code:
[Peter ~]$ cd tmp/
[Peter tmp]$ file TechnicLauncher*
TechnicLauncher:     directory
TechnicLauncher.zip: Zip archive data, at least v2.0 to extract
[Peter tmp]$ mv TechnicLauncher.zip TechnicLauncher                      # Move the zip file into the directory
[Peter tmp]$ mv TechnicLauncher/ TechnicLauncher.zip                     # Change the directory name
[Peter tmp]$ mv TechnicLauncher.zip/TechnicLauncher.zip TechnicLauncher  # Move the zip file back, renaming it.
[Peter tmp]$ file TechnicLauncher*
TechnicLauncher:     Zip archive data, at least v2.0 to extract
TechnicLauncher.zip: directory
 
  


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
bash: renaming file extension based on actual file type alekone Linux - General 9 12-28-2008 09:12 AM
file renaming computer_tom Linux - General 3 02-18-2008 12:27 PM
File renaming amushtaq Linux - Software 2 01-13-2006 05:40 AM
renaming a file?? U-Toast Linux - Newbie 2 08-29-2004 01:07 AM
renaming or converting a text file to a dat file... tangaz Linux - Software 1 10-24-2003 06:57 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06: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