Linux Copy and Rename Files
How Do I Copy and Rename Linux Files?
Copying FilesCopying files under Linux is similar to copying files under DOS. Here's an example using the cp (copy) command: $ cp goulash recipes/hungarian
$ cp stuff stuff.bak
The first example copies the goulash file from the current directory and stores it in your recipes/hungarian directory. The second example creates a file called stuff.bak in the current directory that is identical to the source file stuff.
Note: The cp command will overwrite files with the same name without warning. To be prompted before overwriting, use the -i flag, like so:
$ cp -i goulash recipes/hungarian
cp: overwrite recipes/hungarian/goulash (y/n)?
Renaming Files
Use the mv command to rename a file or move it to another directory, like so:
$ mv stuff junk
$ mv junk trashcan
The first example renames the file stuff as junk, and the second moves the file junk into a directory called trashcan.
Note: The mv command will wipe out files without warning. To be prompted before overwriting, use the -i flag, like so:
$ mv -i stuff junk
mv: overwrite junk (y/n)?
Previous Lesson: Displaying Linux Files
Next Lesson: Creating Files and Directories
Comments - most recent first
(Please feel free to answer questions posted by others!)
there is something confusing me here, in the MV command.
how is the first example rename file and the second move files ?? they are both the same "rename files"
shouldn't the 2nd example has an absolute location ?
cp: cannot stat `/media/sf_TEMP/*.zip/': No such file or directory
oracle@localhost media]$ ls -l
drwxrwx--- 2 root vboxsf 4096 Feb 1 17:23 sf_TEMP
[oracle@localhost media]$ touch sf_TEMP
[oracle@localhost media]$ cd /sf_TEMP
[oracle@localhost media]$ uname -r
2.6.32-300.39.2.el5uek
What can't I copy the file.
I log out and back into the terminal, to no avail.
Please help
"chmod u+x a.pl " in d terminal , but all i get is " d file dsnt exist" ...
Ive checkd d path n evrythn !!
"chmod u+x a.pl " in d terminal , but all i get is " d file dsnt exist" ...
Ive
Thanks.
Structure:
Backup
txt
doc
avi
mpeg
...
...
etc...
1. Script should create a directory named as BACKUP inside the external HDD.
2. Inside the BACKUP directory it will start creating more directories according to the file extentions.
3. Backup of all the files will be created according to the extension of file.
file name "copier.bin"
------------------------------------
cp *am* /home/vmefiles/
-----------------------------------
then I did "chmod +x copier.bin
and finally "./copier.bin" but the out put is just:
"cp *am* /home/vmefiles/"
please help...
But while moving/renaming there is no such need
"man rename"
into a terminal reveals that you can simply type
rename 's/OriginalNameChunk/ChunkToReplaceOriginal/' *.FileExtension
In DOS I would
rename MOV*.* *.mpg
and do the complete directory in two ticks.
In linux it seems impossible without two hours of coding.
Looked everywhere on the net and still can't find a SIMPLE example of renaming an existing file with no extension with an extension of my choice.
Bugger.
Can u give one for the other millions of people wanting to do it?
John
Does someone know something better than 'cp -rbV number Folder1 Folder2' ?
1)
• CP
• CD
• Create File
• Copy file contents into another files
• Create User
• Delete User
• Login using GUI.
- Kris
cp /etc/p2/rename /home/f4
Trying to copy p2 to w3 directory in my home directory, current wk dir, renaming p2 to f4
( No such file or directory)
You spent two hours trying to copy files? Perhaps you should be skiing or playing football. That's funner... EPIC LULZ!
use the r switch
it also works with most other file-only commands
I type: cp /usr/local/linuxgym-dara/vimdata/wordlist.txt ch2-vim
and error shows up saying
cp: cannot stat `/usr/local/linusgym-data/vimdata/wordlist.txt': No such file or directory
what could be wrong?
omitting directory.
i just type:
cp ja Desktop/folder1
eg. you have a file called 'stuff' and want to rename it 'junk' to put into the folder 'junk'.
1.) mv stuff junk.bak
2.) cp junk.bak junk
*I guess*
$ mv junk trashcan
How the system knows not to rename "junk" with name "trashcan",as it does in first case, but to move it in directory.
Is there any other error I could have done??
is there any other thing I must consider??
do I have to change the directory to somewhere else??
I welcome your comments. However... I am puzzled by many people who say "Please send me the Linux tutorial." This website *is* your Linux Tutorial! Read everything here, learn all you can, ask questions if you like. But
don't ask me to send what you already have. :-) NO SPAM! If you post garbage, it will be deleted, and you will be banned.
Copyright © by -
All rights reserved - Redistribution is allowed only with permission.

