LinuxQuestions.org
Register a domain and help support LQ
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 07-31-2012, 10:32 PM   #1
random0munky
LQ Newbie
 
Registered: Jul 2011
Location: Washington, USA
Distribution: Ubuntu, CentOS, FreeBSD
Posts: 22

Rep: Reputation: Disabled
Better Practice When Working With Files


Hey,

I have a question that I ran into when working with files on my linux box. I went ahead and pasted what I have in terminal.

MacBookPro:Test random0munky$ ls -l
total 0
-rw-r--r-- 1 random0munky staff 0 Jul 31 19:31 myTest
-rw-r--r-- 1 random0munky staff 0 Jul 31 19:31 myTest.new
MacBookPro:Test random0munky$ mv myTest myTest.orig
MacBookPro:Test random0munky$ mv myTest.new myTest
MacBookPro:Test random0munky$ ls -l
total 0
-rw-r--r-- 1 random0munky staff 0 Jul 31 19:31 myTest
-rw-r--r-- 1 random0munky staff 0 Jul 31 19:31 myTest.orig
MacBookPro:Test random0munky$

I feel there's a better way / using better practices to accomplish the same task. What do you guys think?

Edit: I noticed that when you do the mv command, that the permissions as well as the group doesn't update with the file. Now just need to see about how to go about updating those 2 values.

Last edited by random0munky; 07-31-2012 at 10:48 PM.
 
Old 07-31-2012, 10:56 PM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Hi,

how about
Code:
mv -b -S '.orig' myTest.new myTest
If you do this often and also want to preserve the perms I would suggest a little shell script, shell function or alias.

Evo2.
 
Old 07-31-2012, 11:02 PM   #3
random0munky
LQ Newbie
 
Registered: Jul 2011
Location: Washington, USA
Distribution: Ubuntu, CentOS, FreeBSD
Posts: 22

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by evo2 View Post
Hi,

how about
Code:
mv -b -S '.orig' myTest.new myTest
If you do this often and also want to preserve the perms I would suggest a little shell script, shell function or alias.

Evo2.
I can see where you're going with this. Unfortunately, the permissions didn't transfer =/

Edit: How about this: mv -b -S '.orig' myTest.new myTest | chmod --reference myTest.orig myTest

Last edited by random0munky; 07-31-2012 at 11:14 PM.
 
Old 07-31-2012, 11:57 PM   #4
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Hi,
Quote:
Originally Posted by random0munky View Post
Edit: How about this: mv -b -S '.orig' myTest.new myTest | chmod --reference myTest.orig myTest
Sure. You could put the following in your .bashrc
Code:
mvbk () {
mv -b -S '.orig' $1 $2 && chmod --reference $2.orig $2 
}
Then you just need to call
Code:
mvbk myTest.new myTest
You could also modify the function so that you it only needs one argument assuming that the you will always be wanting to move $1.new to $1
eg
Code:
mvbk () { 
mv -b -S '.orig' $1.new $1 && chmod --reference $1.orig $1
}
Then you could just call
Code:
mvbk myTest
Evo2.
 
Old 08-01-2012, 12:02 AM   #5
random0munky
LQ Newbie
 
Registered: Jul 2011
Location: Washington, USA
Distribution: Ubuntu, CentOS, FreeBSD
Posts: 22

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by evo2 View Post
Hi,

Sure. You could put the following in your .bashrc
Code:
mvbk () {
mv -b -S '.orig' $1 $2 && chmod --reference $2.orig $2 
}
Then you just need to call
Code:
mvbk myTest.new myTest
You could also modify the function so that you it only needs one argument assuming that the you will always be wanting to move $1.new to $1
eg
Code:
mvbk () { 
mv -b -S '.orig' $1.new $1 && chmod --reference $1.orig $1
}
Then you could just call
Code:
mvbk myTest
Evo2.
Is there any other way that's a bit more prettier than the solutions we have came up with >.<
 
Old 08-01-2012, 12:17 AM   #6
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Hi,
Quote:
Originally Posted by random0munky View Post
Is there any other way that's a bit more prettier than the solutions we have came up with >.<
Hmm. Don't know. I like little shell functions.

Cheers,

Nick.
 
  


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
Best practice for data files using CMake damien_d Programming 1 04-08-2009 11:06 AM
install best practice rekaye1005 Linux - Software 2 02-14-2005 05:27 PM
Practice for programming? coolguy_iiit Programming 2 12-29-2004 02:07 PM
cannot download files in mozilla -save dialog not working, galeon not working cmisip Linux - General 0 08-03-2003 04:25 PM
Need some tar files to practice on AMDPwred Linux - General 7 01-16-2002 01:10 PM


All times are GMT -5. The time now is 12:45 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration