LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 02-28-2016, 08:24 PM   #1
asw225
LQ Newbie
 
Registered: Feb 2016
Posts: 15

Rep: Reputation: Disabled
need help refining my command


I am in the CLI trying to move a file from a sub directory to another directory while changing the name of the file

If I am in the home directory now and am trying to pull a file from my Desktop directory while changing its name, should any of the following work?


mv file1.txt NewFile.txt /home/

mv file1.txt NewFile.txt | mv NewFile.txt ~



For some reason its not working out for me?
 
Old 02-28-2016, 09:10 PM   #2
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 1,205

Rep: Reputation: 197Reputation: 197
mv <source> <destination>

if current path is:

/home/user/Desktop
try this:

mv file1.txt /home/NewFile.txt

if current path is:

/home

try this:

mv /home/user/Desktop/file1.txt ./NewFile.txt


just make sure you have write permissions to /home directory

Good luck!!!
 
Old 02-29-2016, 01:43 AM   #3
aragorn2101
Member
 
Registered: Dec 2012
Location: Mauritius
Distribution: Slackware
Posts: 355

Rep: Reputation: 154Reputation: 154
The simple mv command should do it very easily for you. In CLI mv is also used to rename a file like this:

> mv original_file.txt new_file.txt

So, if in addition you wish to move the file to another directory, you simply add the complete paths:

> mv original_file.txt NEW_PATH_TO_FILE/new_file.txt
 
Old 02-29-2016, 02:56 AM   #4
malekmustaq
Senior Member
 
Registered: Dec 2008
Location: root
Distribution: Slackware & BSD
Posts: 1,627

Rep: Reputation: 471Reputation: 471Reputation: 471Reputation: 471Reputation: 471
Move and rename file in a single command of "mv" in the terminal.

Try this at your /home/you directory.

Create a file with content
Code:
echo "You and me." >> me
and check if it is created
Code:
ls me
and check what it has
Code:
cat me
You are certain the file exists.

Now move and rename it in a single command:
Code:
mv me Desktop/you
it momentarily stops then the prompt resumes in position. Now, recheck if the same file was copied and renamed into ~/Desktop folder
Code:
cat Desktop/you
There you are.

Hope that helps.

Good luck and enjoy.
 
  


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
Refining an alert notification script. Stepman 72 Linux - Newbie 1 11-18-2014 10:32 AM
ideas to refining this script adam_blackice Programming 2 09-10-2007 10:43 PM
Gentoo 2006.1 - Refining X Configurations indienick Linux - Desktop 11 04-17-2007 08:36 PM
LXer: Linux: Looking At 2.6.19, Refining the Development Process LXer Syndicated Linux News 0 09-23-2006 08:54 AM
Refining a Website ... mmertens Linux - Software 9 02-21-2003 03:05 AM


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