LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 08-24-2016, 10:04 AM   #1
dthims
Member
 
Registered: Mar 2003
Posts: 48

Rep: Reputation: 1
cp file without typing the full path


want to copy this file, /etc/test.conf. so i type: sudo cp /etc/test.conf test-copy.conf. but it copies it to my home directory, not in the etc directory. how do i copy it to the etc directory WITHOUT typing the full path, or is that the only way. tia
 
Old 08-24-2016, 10:07 AM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,230

Rep: Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724
Change directory to /etc then copy test.conf to test-copy.conf ?
 
Old 08-24-2016, 03:33 PM   #3
Virneto
LQ Newbie
 
Registered: Jan 2013
Location: Azores
Distribution: Fedora
Posts: 17

Rep: Reputation: Disabled
use full paths

cp /etc/test.conf /etc/test-copy.conf
 
Old 08-24-2016, 04:16 PM   #4
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 19.1 MATE
Posts: 8,018
Blog Entries: 5

Rep: Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872
Quote:
Originally Posted by dthims View Post
want to copy this file, /etc/test.conf. so i type: sudo cp /etc/test.conf test-copy.conf. but it copies it to my home directory, not in the etc directory. how do i copy it to the etc directory WITHOUT typing the full path, or is that the only way. tia
The reason that the file was copied to your home directory with the command you used is because that is where you were when you issued the command (your working directory was your home directory).

To find out where your working directory is, use pwd (path to working directory).

In general, any filepaths in a command you issue that are not absolute (absolute filepaths begin with a /, representing the root of the filesystem), are treated as relative to your working directory.
 
1 members found this post helpful.
Old 08-24-2016, 04:52 PM   #5
Emerson
LQ Guru
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~arch
Posts: 6,317

Rep: Reputation: Disabled
Quote:
Originally Posted by dthims View Post
want to copy this file, /etc/test.conf. so i type: sudo cp /etc/test.conf test-copy.conf. but it copies it to my home directory, not in the etc directory. how do i copy it to the etc directory WITHOUT typing the full path, or is that the only way. tia
You do not need to type the full path, use shell completion, it will reduce the keyboard hits considerably - if you grasp how it works.
 
Old 08-24-2016, 08:03 PM   #6
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 4,360

Rep: Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001
This works, though most people would find it harder than re-typing the full path:
Code:
cp /etc/{test.conf,test-copy.conf}
It's also very easy to get wrong.
 
2 members found this post helpful.
  


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
How to output full path file name & first line of text of each file? rosalee Linux - Newbie 2 10-08-2015 05:18 PM
Configuring GNOME to have Full File Path Text Fields in File Open Dialog Boxes bgoodr Linux - Desktop 3 11-29-2011 10:07 AM
How to get the full path of a file in C? Basel Programming 3 10-30-2010 11:52 PM
[SOLVED] tired of typing full path to php or mysql...some way to create alias? sneakyimp Other *NIX 7 05-26-2010 11:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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