LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 10-12-2011, 04:06 PM   #1
congos
LQ Newbie
 
Registered: Oct 2011
Posts: 20

Rep: Reputation: Disabled
Post commands to use or script


how do i copy a file that has no end and add .txt to it
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 10-12-2011, 04:08 PM   #2
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,819
Blog Entries: 1

Rep: Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218
The 'end' is called an (file) extension.
Please, google some tutorials on the 'cp' command.
 
Old 10-12-2011, 04:12 PM   #3
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
@ 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.

Last edited by T3RM1NVT0R; 10-12-2011 at 04:14 PM.
 
Old 10-12-2011, 04:17 PM   #4
congos
LQ Newbie
 
Registered: Oct 2011
Posts: 20

Original Poster
Rep: Reputation: Disabled
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?????
 
Old 10-12-2011, 04:21 PM   #5
congos
LQ Newbie
 
Registered: Oct 2011
Posts: 20

Original Poster
Rep: Reputation: Disabled
can i write
best=file
cp $best $best.txt??
 
Old 10-12-2011, 04:28 PM   #6
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
@ 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
 
Old 10-12-2011, 11:02 PM   #7
congos
LQ Newbie
 
Registered: Oct 2011
Posts: 20

Original Poster
Rep: Reputation: Disabled
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
 
Old 10-13-2011, 07:15 AM   #8
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721
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?
 
Old 10-13-2011, 07:44 AM   #9
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959


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.
 
2 members found this post helpful.
Old 10-13-2011, 09:24 PM   #10
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,371

Rep: Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381
Examples
Code:
# renames (moves) the file
mv file file.txt

# creates a 2nd copy
cp file file.txt
your choice
 
  


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
SSH connection from BASH script stops further BASH script commands tardis1 Linux - Newbie 3 12-06-2010 08:56 AM
commands in shell script ? wolfindark Linux - Newbie 5 07-07-2008 04:29 AM
Shell Script Commands shandy^^^ Programming 16 02-09-2006 10:16 AM
console commands as script? rooman Linux - Newbie 14 02-02-2006 07:49 PM
How do I script these commands? johnnybhoy67 Linux - General 6 10-21-2005 09:53 AM


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