Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: how to create files using touch which contains spaces in path,names

  1. #1
    Join Date
    Aug 2011
    Location
    India
    Posts
    250

    Default how to create files using touch which contains spaces in path,names

    Hi I am Rupesh from India and I have a text file which contains filenames of files including their path. I want to create empty files using touch.

    For example consider a file called file name.opus and it's path as below

    ./dir one/dir two/dir three/file name.opus

    I want to create a file with name "file name.opus" contained in directory "dir one" which is contained in directory "dir two" which is contained in directory "dir three".

    The directories dir one,dir two, dir three are created previously and when I issue the command touch as below

    touch ./dir one/dir two/dir three/file name.opus

    I am getting errors as directories dir one two three not found.

    Please suggest how to create a file name in the above pattern.
    Regards,
    Rupesh.

  2. #2
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,240

    Default Re: how to create files using touch which contains spaces in path,names

    Like any other shell command where file names (or other fields) contain spaces (or any other character that is special to the shell): escaping

    • you escape single characters by placing a \ in front, e.g.
      Code:
      dir\ one
    • you escape longer ranges (works of course also with one character) by enclosing the between single quotes, e.g.:
      Code:
      'dir one'/dir' 'two
    • when certain characters special to the shell must still be interpreted by the shell (often this is a $ in variable expansion), you can use double quotes, e.g.
      Code:
      "dir one"/"dir two"
    Henk van Velden

  3. #3

    Default Re: how to create files using touch which contains spaces inpath,names

    On 10/09/2017 12:56 PM, hcvv wrote:
    >
    > Like any other shell command where file names (or other fields) contain
    > spaces (or any other character that is special to the shell): escaping
    >
    >
    > - you escape single characters by placing a \ in front, e.g.
    > Code:
    > --------------------
    > dir\ one
    > --------------------
    >
    > - you escape longer ranges (works of course also with one character)
    > by enclosing the between single quotes, e.g.:
    > Code:
    > --------------------
    > 'dir one'/dir' 'two
    > --------------------
    >
    > - when certain characters special to the shell must still be
    > interpreted by the shell (often this is a $ in variable expansion),
    > you can use double quotes, e.g.
    > Code:
    > --------------------
    > "dir one"/"dir two"
    > --------------------


    The slashes do not need to be interpreted by the shell, at least not with
    bash as I have it on my laptop (tested just to be sure):

    Code:
    touch 'test0/test one/test two/test three/file here';
    touch "test0/test one/test two/test three/file here";
    Assuming the directory structure exists, the command above works just fine
    too. I only include these to supplement your responses which cover
    more-complex cases where you may want to use variables or have other
    characters in there.

    --
    Good luck.

    If you find this post helpful and are logged into the web interface,
    show your appreciation and click on the star below.

    If you want to send me a private message, please let me know in the
    forum as I do not use the web interface often.

  4. #4

    Default Re: how to create files using touch which contains spaces in path,names

    Hi Rupesh.

    Is this the same problem as here? If so why did you not respond to the suggestions in that thread? Have you explained the problem sufficiently well that we know all of the details?

  5. #5
    Join Date
    Aug 2011
    Location
    India
    Posts
    250

    Default Re: how to create files using touch which contains spaces in path,names

    Quote Originally Posted by Obscurant View Post
    Hi Rupesh.

    Is this the same problem as here? If so why did you not respond to the suggestions in that thread? Have you explained the problem sufficiently well that we know all of the details?
    I have posted that thread in Linux questions then within one hour a person named tbone started writing words which will hurt me and so I immediately stopped watching what others have written.

    For each and every thread I have created in Linux questions tbone is writing words which hurts me.
    Regards,
    Rupesh.

  6. #6
    Join Date
    Aug 2011
    Location
    India
    Posts
    250

    Default Re: how to create files using touch which contains spaces in path,names

    Code:
    touch 'test0/test one/test two/test three/file here'; 
    touch "test0/test one/test two/test three/file here";
    I have tried both of what you specified and the command successfully executed without any errors but when I tried to examine the contents of the bottom folder I found no files I mean that directory is empty.
    Regards,
    Rupesh.

  7. #7
    Join Date
    Jan 2014
    Location
    Erlangen
    Posts
    1,060

    Default Re: how to create files using touch which contains spaces in path,names

    By the way Linux is very tolerant regarding characters considered illegal in file names by lesser operating systems:

    Code:
    karl@erlangen:~> mkdir -p '#$%&*"\/:;?=|~'                                                                                            
    karl@erlangen:~> ll -d \#\$%\&\*\"\\/\:\;\?\=\|~/
    drwxr-xr-x 2 karl users 4096 10. Okt 08:12 #$%&*"\/:;?=|~/
    karl@erlangen:~>
    AMD Athlon 4850e (2009), openSUSE 13.1, KDE 4, Intel i3-4130 (2014), i7-6700K (2016), i5-8250U (2018), openSUSE Tumbleweed, KDE Plasma 5

  8. #8
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,240

    Default Re: how to create files using touch which contains spaces inpath,names

    Quote Originally Posted by ab View Post

    The slashes do not need to be interpreted by the shell, at least not with
    bash as I have it on my laptop (tested just to be sure):
    I am not quite sure what you mean here. I reread my post above again and again, but I can not find any remark about "slashes" (/ I assume) at all, let alone if they would be special to the shell (which they are not indeed).
    Quote Originally Posted by ab View Post
    Code:
    touch 'test0/test one/test two/test three/file here';
    touch "test0/test one/test two/test three/file here";
    Assuming the directory structure exists, the command above works just fine
    too. I only include these to supplement your responses which cover
    more-complex cases where you may want to use variables or have other
    characters in there.
    If you mean "the command works" that the file names file here in the directory test three in the directory test two in the directory test one in the directory test0 has it's access and modification times changed (and at the same time is created when not already existing), then that is what I would expect.
    Henk van Velden

  9. #9
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,240

    Default Re: how to create files using touch which contains spaces in path,names

    Quote Originally Posted by rupeshforu3 View Post
    I have posted that thread in Linux questions then within one hour a person named tbone started writing words which will hurt me and so I immediately stopped watching what others have written.

    For each and every thread I have created in Linux questions tbone is writing words which hurts me.
    Dear rupesh ji,

    I know some people are less nice to people who show they do not know things then others. But you must understand that using Unix/Linux and specially the shell (bash) is not an obvious thing to do. They have a steep, very steep learning curves. Even the fact that the commands you type in a terminal are first interpreted by bash and can be subject to a lot of alterations by bash before they are used as arguments for a command, is often difficult to understand for many.

    Thus, everybody that wants to use bash should at least have some basic knowledge about the "word splitting", "characters special to the shell", "escaping/quoting". I know that many are not willing to spend the time in reading a basic bash tutorial, but sooner or later they will run into problems. Asking for help, will most of the time at the most bring a direct solution to that particular problem and then you will stumble into the next one.

    Many people will not be willing to spend their spare time in taking someone by the hand and guide through each and every step. Forums are no Guru-Chela substitute. So people will tell you to go and study! They will do so in more harsh terms when they have to repeat that. That may not be very nice, but you must also understand that you bother them to give of their own time and they have no further relation to you. You are no family, you do not pay them, the only reward they might have is that you show that you learned from them and that you are thankful. When you do not, they will leave you alone.

    That is how the world of open source is. Comforting to those that are eager to work hard and learn. Rejecting to those that only want to profit from other ones knowledge, never show they have learned something, never say thank you.

    Please Rupesh ji, now sit down and take some time and try to calculate how much time all those people on all those forums used to answer you. They could have done a lot of other things in that time. But they choose to try to help you (even if you not always understood that it was trying to help you) and not to do some nice programming, drink tea, go shopping, or whatever.

    नमस्ते

    Henk
    Henk van Velden

  10. #10
    Join Date
    Aug 2011
    Location
    India
    Posts
    250

    Default Re: how to create files using touch which contains spaces in path,names

    Dear hccv yes you are right and I am very thankfu for all the people who spent time in order to reply to my threads. I know that bash is a command interpreter and it is difficult to understand but we must try understanding it.

    I have created some threads because I can't understand the outcome of some tools. For example once I have issued the command wget and it has downloaded some page say link.html and named it as link.html.tmp and actually wget has to download the files specified in wget but it has not done it instead it displayed message as link.html.tmp is not a target file so stopping the download. After that no work done by wget.

    Actually one person in Linux questions suggested a command sequence and it done the work given to it but now it is displaying message removing link.html.tmp since it should be rejected. I have requested what's the meaning of this message but no one replied. Actually I think that wget is best for downloading anything because it has many features not found in other download manager's and so I prefer to use it but I can't understand the error messages displayed by it.

    Even after studying all the manuals and guides I can't understand the meaning of "... has been rejected". In such rare cases I may post or create a thread but many of you say that we are providing lot of help but there is no work done by you etc.,. If I want to raise irrelevant questions I may raise a number of questions like " This day someone sneezed before me what to do etc.," but not.

    I have created two thread's which are most important and requirement to me and also relevant but there is no response from you those threads are

    Using wget as an offline browser to download all mp3 files from a website
    Second is the current thread ie the system frequently crashes.
    Regards,
    Rupesh.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •