LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   commands to use or script (https://www.linuxquestions.org/questions/linux-newbie-8/commands-to-use-or-script-907833/)

congos 10-12-2011 04:06 PM

commands to use or script
 
how do i copy a file that has no end and add .txt to it

sycamorex 10-12-2011 04:08 PM

The 'end' is called an (file) extension.
Please, google some tutorials on the 'cp' command.

T3RM1NVT0R 10-12-2011 04:12 PM

@ Reply
 
Not sure what you mean by no end to it.

cp is the command which is use to copy a file. You can use the same command to copy the file with the different name.

Suppose you have a file with the name test under /home/user/test and you want to move it to /home/user/testing folder as test.txt then you can run the following command.

Code:

cp /home/user/test /home/user/testing/test.txt
If you want to know more switches that you can use with cp command you can just type the following command:

Code:

man cp
sycamorex is right. If you want more information then you can google for tutorials on cp command.

congos 10-12-2011 04:17 PM

T3RM1NVT0R thanks alot atleast it helps i need a script that i will be able to run and which will copy files without an externsion like
cp /home/user/test and add .txt /home/user/testing/test.txt iis there any command i can use in the script?????

congos 10-12-2011 04:21 PM

can i write
best=file
cp $best $best.txt??

T3RM1NVT0R 10-12-2011 04:28 PM

@ Reply
 
Nope. That is not the correct way of writing the script.

How many files are there which you want to change the extensions for? If it is just for one file then script is not required. If there are many then yes you do need a script.

If you already have a script then we guys can help you fix the problem in the script. If you do not have a script or you do not know how to create a script then you should better have a look at the following tutorials:

http://www.freeos.com/guides/lsst/ /* For beginners */

http://linuxconfig.org/Bash_scripting_Tutorial

http://tldp.org/LDP/abs/html/ /* This one is for advanced user */

I hope this helps

congos 10-12-2011 11:02 PM

im copying alot of files this is a script im trying to modify but not sure how to make it copy files without an extension and then add a .txt to them


abc= #assuming the file does not have an end or extension
foo='abc$'
FROM=/user/share/doc
TO=~/home/doc
for grep $foo in $from do
echo the files have no file extension
cp -r $FROM $TO

MTK358 10-13-2011 07:15 AM

That code doesn't make any sense to me. Are the paths in TO or FROM directories or files? It seems they should be directories, but then why are you using grep (in a place where it's not valid syntax)? And then why are you discarding the results of the grep and simply copying TO to FROM?

David the H. 10-13-2011 07:44 AM

:twocents:

First of all, renaming files is one of the most requested scripting questions here and on the net. A quick search or two of the archives will turn up dozens of previous threads with all the information you need.

Second, there are also already a number of ready-made renaming tools available that can do exactly what you want. A search of your distribution's software repositories should tell you what's available.

Third, please use [code][/code] tags around your code, to preserve formatting and to improve readability.

Fourth, when you have a problem, it helps to define it clearly at the outset. You could give us some actual examples of the filenames and how you want to rename them, as well as any pertinent details about the environment and the tools you have available.

Check out the first link in my signature, and follow on from there to Eric S. Raymond's guide on how to ask questions the smart way. Properly framing your posts will help you to get the responses you need, without wasting people's time, either ours or yours.

chrism01 10-13-2011 09:24 PM

Examples
Code:

# renames (moves) the file
mv file file.txt

# creates a 2nd copy
cp file file.txt

your choice :)


All times are GMT -5. The time now is 10:47 PM.