LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-08-2013, 10:57 AM   #1
tpprynn
Member
 
Registered: Oct 2013
Location: Kent, UK
Distribution: Debian
Posts: 63

Rep: Reputation: 0
The form of mv file.txt /usr/share/bobbins/


If I'm moving a file or copying or using tar is the last forward slash essential - is there a difference in any context between

cp ~/file.txt /usr/share/themes

and

cp ~/file.txt /usr/share/themes/

and the mv and tar -xf equivalents?

Thanks.
 
Old 11-08-2013, 02:45 PM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Providing themes is a directory, there is no difference between those two cp commands.

tar is different, because you could be specifying a directory tree or a specific file. Not covering it all, but the general form for tar (to create an archive) is:
Code:
tar [options] [pathname] [tar-output-file]
And I believe if you specify with or without the final slash in the [pathname] argument, the result is the same. But if you use the form with no slash as your [tar-output-file] what it may do is create a tar file matching that directory name, at the same level where that directory resides. If you use the form with an ending slash and nothing following it, tar will likely complain that you haven't given it a valid [tar-output-file].

Going in the other direction, to de-archive an existing tar, the last argument would be the name of the tar file and that term is not applicable to your ending slash argument. However if you use the -C argument for tar, which is to "change to directory", also known as --directory, then it will place the files extracted from your archive into the specified directory. In that case you can use a trailing slash, or not; however in both cases, if that directory does not exist, you'll get a complaint.
 
1 members found this post helpful.
Old 11-08-2013, 02:48 PM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Two things to add to what I said here are:

1.) The best things to do when you have questions like this are to run some tests on your own machine.
2.) If I'm writing something into a script and I doubt one way versus another, or have witnessed shells which treat the more open command condition differently, I always be as explicit as possible and fully write out the entire path and filenames so that I don't get bitten.
 
Old 11-09-2013, 03:30 PM   #4
tpprynn
Member
 
Registered: Oct 2013
Location: Kent, UK
Distribution: Debian
Posts: 63

Original Poster
Rep: Reputation: 0
Thanks for that. Yes, generally I would experiment. I did recently make a mess of using rm so I'm not feeling quite as intrepid at the moment...
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Redirect an app resource folder from system /usr/share to /home/user/[app]/usr/share minyor Linux - Software 2 04-23-2013 06:44 AM
saving the form data into a .txt file imran042 Programming 4 05-18-2012 01:53 PM
How can read from file.txt C++ where can save this file(file.txt) to start reading sam_22 Programming 1 01-11-2007 05:11 PM
SAMBA share txt file editing questions LinuxRam Linux - Software 14 09-10-2004 08:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:25 PM.

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
Open Source Consulting | Domain Registration