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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
07-31-2012, 09:32 PM
|
#1
|
LQ Newbie
Registered: Jul 2011
Location: Washington, USA
Distribution: Ubuntu, CentOS, FreeBSD
Posts: 22
Rep: 
|
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 09:48 PM.
|
|
|
07-31-2012, 09:56 PM
|
#2
|
LQ Guru
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,726
|
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.
|
|
|
07-31-2012, 10:02 PM
|
#3
|
LQ Newbie
Registered: Jul 2011
Location: Washington, USA
Distribution: Ubuntu, CentOS, FreeBSD
Posts: 22
Original Poster
Rep: 
|
Quote:
Originally Posted by evo2
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 10:14 PM.
|
|
|
07-31-2012, 10:57 PM
|
#4
|
LQ Guru
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,726
|
Hi,
Quote:
Originally Posted by random0munky
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
Evo2.
|
|
|
07-31-2012, 11:02 PM
|
#5
|
LQ Newbie
Registered: Jul 2011
Location: Washington, USA
Distribution: Ubuntu, CentOS, FreeBSD
Posts: 22
Original Poster
Rep: 
|
Quote:
Originally Posted by evo2
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
Evo2.
|
Is there any other way that's a bit more prettier than the solutions we have came up with >.<
|
|
|
07-31-2012, 11:17 PM
|
#6
|
LQ Guru
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,726
|
Hi,
Quote:
Originally Posted by random0munky
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.
|
|
|
All times are GMT -5. The time now is 11:00 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|