LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Command Syntax to move or copy files to a new folder (https://www.linuxquestions.org/questions/linux-newbie-8/command-syntax-to-move-or-copy-files-to-a-new-folder-4175545960/)

Charliesrch 06-20-2015 04:32 PM

Command Syntax to move or copy files to a new folder
 
I have created a couple of new folders that reside in the file cabinet of my Ubuntu 14.04.2 LTS install. I have not been able to move or copy loose files from the Documents directory using the Terminal (the folders were created in the Terminal and they show in the File Cabinet). I get responses from a "mv" or "cp" line command such as "no such file exists" or "directory", etc. Is there a proper syntax for naming a file? The files I have tried to move or copy were created in LibreOffice Calc or .pdf downloaded files. I can drag-and drop from the desktop but I want to learn how to use the Terminal extensively.

JeremyBoden 06-20-2015 05:21 PM

If the file is not in your current directory, you will need to give an absolute or relative path to the file.
e.g.
Code:

mv /home/username/fromfilename tofilename
will rename a file.
Code:

mv ~/fromfilename tofilename
Is slightly easier. I suggest you read the output of
Code:

man mv

suicidaleggroll 06-20-2015 06:31 PM

Tab completion is your friend. Type the first few characters of the file and hit tab. If it doesn't fill in the rest of the name for you, hit tab again. If there are multiple files with the same first few characters, it will print them out. If it doesn't do anything, then there is no file in that directory that begins with those characters. I can't even remember the last time I typed in an entire filename manually, it's just asking for stupid typo errors and you second guessing if you spelled it correctly.

Billy@2015 06-20-2015 06:37 PM

@ Charliesrch

If your file(s) resides in another location. You can type the path like so. An Example:

Code:

mv ~/Documents/filename.txt ~/Documents/newfilename.txt
Or cd to the Documents folder and then use mv or cp

Code:

cd ~/Documents

mv filename.txt newfilename.txt

Remember, mv works in two ways. It will move a file(s) to another location or rename the file(s).



Also, if your files have special characters, you'd need to use an escape character like '\' or wrap the filename in quotes.



this\ is\ a\ sample\ file.txt

"this is a sample file.txt"

In these two examples, the space is the special character.

You can also use TAB completion to fill the rest of the filename. Just type the first few letters of the filename and press TAB. If it's the only file that begins with those letters, TAB completion will fill the rest.If not, type the next letter and press TAB. Keep repeating until TAB completion fill the filename completely.

TAB completion can work on files, directories and directory paths.

Charliesrch 06-21-2015 03:52 AM

Many THANKS ! As an extremely new newbie, sometimes I need some clarification such as these great examples and advice. The man pages - and Konqueror are helpful with my study and practice, but a 'helping hand' performs miracles when I hit a snag.


All times are GMT -5. The time now is 05:11 PM.