How do I enter a file or directory with special characters in its name?












37














I want to enter the following folder in the terminal:



Milano, Torino (Jan)-Compressed


How should I write the command cd to enter this directory?



Spaces and several other special characters like , *, ), ( and ? cause problems when I try to use them in the command line or scripts, e.g.:





$ cd space dir
bash: cd: space: No such file or directory

$ cat space file
cat: space: No such file or directory
cat: file: No such file or directory

$ cat (
bash: syntax error near unexpected token `newline'

$ echo content >
> ^C

$ ls ?
( ) * ?


How do I enter file or directory names that contain special characters in the terminal in general?










share|improve this question





























    37














    I want to enter the following folder in the terminal:



    Milano, Torino (Jan)-Compressed


    How should I write the command cd to enter this directory?



    Spaces and several other special characters like , *, ), ( and ? cause problems when I try to use them in the command line or scripts, e.g.:





    $ cd space dir
    bash: cd: space: No such file or directory

    $ cat space file
    cat: space: No such file or directory
    cat: file: No such file or directory

    $ cat (
    bash: syntax error near unexpected token `newline'

    $ echo content >
    > ^C

    $ ls ?
    ( ) * ?


    How do I enter file or directory names that contain special characters in the terminal in general?










    share|improve this question



























      37












      37








      37


      7





      I want to enter the following folder in the terminal:



      Milano, Torino (Jan)-Compressed


      How should I write the command cd to enter this directory?



      Spaces and several other special characters like , *, ), ( and ? cause problems when I try to use them in the command line or scripts, e.g.:





      $ cd space dir
      bash: cd: space: No such file or directory

      $ cat space file
      cat: space: No such file or directory
      cat: file: No such file or directory

      $ cat (
      bash: syntax error near unexpected token `newline'

      $ echo content >
      > ^C

      $ ls ?
      ( ) * ?


      How do I enter file or directory names that contain special characters in the terminal in general?










      share|improve this question















      I want to enter the following folder in the terminal:



      Milano, Torino (Jan)-Compressed


      How should I write the command cd to enter this directory?



      Spaces and several other special characters like , *, ), ( and ? cause problems when I try to use them in the command line or scripts, e.g.:





      $ cd space dir
      bash: cd: space: No such file or directory

      $ cat space file
      cat: space: No such file or directory
      cat: file: No such file or directory

      $ cat (
      bash: syntax error near unexpected token `newline'

      $ echo content >
      > ^C

      $ ls ?
      ( ) * ?


      How do I enter file or directory names that contain special characters in the terminal in general?







      command-line filename cd-command






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jun 13 '18 at 15:08









      dessert

      22.2k56198




      22.2k56198










      asked Feb 5 '12 at 11:58









      Pomario

      92851328




      92851328






















          8 Answers
          8






          active

          oldest

          votes


















          39














          That command is ambiguous because spaces are normally used to separate arguments. cd does not know what you want to do but you have two possibilities to solve it:



          Either you "mask" the spaces (and all other special characters) so that the terminal knows you mean the space as a character and not as a separator:



          cd Milano, Torino (Jan)-Compressed


          Or you put your folder name or path into quotes:



          cd "Milano, Torino (Jan)-Compressed"





          share|improve this answer

















          • 4




            Or use single quotes ('Milano, Torino (Jan)-Compressed'), if you don't want environment variables ($VARNAME) to be expanded and commands enclosed in backticks or $() to be run (or if there are double-quotes in the filename).
            – Eliah Kagan
            Jul 10 '12 at 13:52










          • @Eliah Single-quotes also escape exclamation marks (history expansion), where double-quotes don't.
            – wjandrea
            Jan 2 at 22:29



















          24














          A little tip: tab completion ;-)




          1. Just type the first letter e.g cd Mi (or more letters if needed) and press Tab. Terminal will help you by completing the rest words.


          Another way: drag and drop




          1. If you can see the directory and if you want to access it using terminal, just type: cd first and then drag and drop the directory on the terminal and hit enter.






          share|improve this answer



















          • 3




            Got to love tab completion <3
            – Rinzwind
            Feb 5 '12 at 15:39










          • While the accepted answer is technically correct, in practice you're going to want tab-completion so you don't have to do all that escaping.
            – phasetwenty
            Feb 9 '12 at 21:32










          • @Achu, but sometimes even the tab completion itself doesn't work for directories containing especial characters i.e. -, etc, so the suggested method would be cd -- '-foo-/'. but still we can use tab completion inside the quotation ;)
            – Amir
            Jan 10 '14 at 14:05



















          23














          Write it as



          cd 'Milano, Torino (Jan)-Compressed'


          Otherwise it treats Milano, as the folder name. This happens because of the spaces in the name of the folder.



          Alternatively escape a few of the special characters...



          cd Milano, Torino (Jan)-Compressed/





          share|improve this answer



















          • 10




            You can also use Tab for auto-completion inside the double quotes to auto-escape double-quotes within the filename.
            – htorque
            Feb 5 '12 at 12:06






          • 3




            Note that double quotes won't help you cd into a directory named $money, for example. You'd need to write '$money' or $money.
            – Dietrich Epp
            Feb 5 '12 at 20:22






          • 3




            I think generally single quotes are more explicit, and a better standard. Both work, but single quotes work more often and say "exactly as you see it".
            – isaaclw
            Feb 5 '12 at 21:50










          • @isaaclw Thanks, I agree! Edited.
            – Prateek
            Feb 6 '12 at 14:14



















          22














          tl;dr: To quote a special character either escape it with a backslash or enclose it in double " " or single quotes ' '. Tab ↹ Completion takes care of proper quoting.





          What you're asking for is called Quoting:




          Quoting is used to remove the special meaning of certain characters or words to the shell. (…) There are three quoting mechanisms: the escape character, single quotes, and double quotes.
          [citations taken from man bash]




          Quoting with the escape character




          A non-quoted backslash () is the escape character. It preserves the literal value of the next character that follows, with the exception of <newline>.




          So to enter a directory or a file with a special character, escape the latter with , e.g.:



          cd space dir      # change into directory called “space dir”
          cat space file # print the content of file “space file”
          echo content > \ # print “content” into file “”
          cat ( # print the content of file “(”
          ls -l ? # list file “?”


          bash's Programmable Completion (aka Tab ↹ Completion) automatically escapes special characters with the escape character .



          Quoting with double quotes " "




          Enclosing characters in double quotes preserves the literal value of all characters within the quotes, with the exception of $, `, , and, when history expansion is enabled, !.




          So to enter a directory or a file with a special character, escape at least the latter or a greater part of your filename or path with double quotes, e.g.:



          cd space" "dir     # change into directory called “space dir”
          cd spac"e di"r # equally
          cd "space dir" # equally
          cat "space file" # print the content of file “space file”
          cat "(" # print the content of file “(”
          ls -l "?" # list file “?”


          As $, ` and ! keep their special meaning inside double quotes, Parameter Expansion, Command Substitution, Arithmetic Expansion and History Expansion are performed on double-quoted strings.



          Quoting with single quotes ' '




          Enclosing characters in single quotes preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash.




          So to enter a directory or a file with a special character, escape at least the latter or a greater part of your filename or path with double quotes, e.g.:



          cd space' 'dir     # change into directory called “space dir”
          cd spac'e di'r # equal
          cd 'space dir' # equal
          cat 'space file' # print the content of file “space file”
          cat '(' # print the content of file “(”
          ls -l '?' # list file “?”
          echo content > '' # print “content” into file “”




          You can find more about Quoting in man bash/QUOTING, on wiki.bash-hackers.org and on tldp.org.






          share|improve this answer























          • '' breaks the shell syntax highlighter of SE.
            – David Foerster
            Dec 30 '17 at 20:35












          • @DavidFoerster There's the limit of google prettify (which is used for that), but I thought better than nothing… How about now? ;P
            – dessert
            Dec 30 '17 at 20:40












          • That was more a statement of fact and a little surprise than a criticism of your post. The only criticism here might go to the syntax highlighter. I would have done nothing about it personally.
            – David Foerster
            Dec 30 '17 at 20:41





















          10














          C-like strings and $'string'



          Among other things, one can use $'...' type of quoting to make use of ANSI-C backslash characters such as n and t, including those you've mentioned. From bash 4.3 manual:




          Words of the form $'string' are treated specially. The word expands
          to string, with backslash-escaped characters replaced as specified
          by the ANSI C standard.




          This is particularly useful with files which contain newlines, tabs, when you're writing complex awk lines where you need to make use of different ways to distinguish between single and double quotes, when filenames themselves contain single/double quote mishmash,etc.



          For example, creating and listing such files:



          $ touch a$'*'b  c$'n'd                                                     
          $ ls a$'*'b c$'n'd
          a*b c?d


          You can make use of character hex values, such as:



          $ touch 'file(name'
          $ ls file$'x28'name
          file(name


          printf



          Same idea as before - take advantage of escape characters:



          $ ls "$(printf "filex28name")"                                             
          file(name
          $ echo "Hello World" > c$'n'd
          $ cat "$(printf "cnd")"
          Hello World


          Use inodes:



          Every file or directory has special data structure associated with it called inode, which are referenced by a particular decimal number. So you can use that to indirectly locate the file with particular inode via find command, and do something with it:



          $ echo "This is a test" > file$'('name1
          $ ls -i
          5898996 file(name1 5898997 file?name2
          $ find -type f -inum "5898996" -exec cat {} ;
          This is a test


          Avoid dealing with individual files when you can use glob



          When you don't have to deal with individual files, just take advantage of * glob character in shell and quote variables when passing them to other commands. It makes dealing with difficult filenames much easier:



          $ for f in ./*; do echo "$f" ; done
          file name2
          file(name1


          Note the use of ./ - a safeguard against filenames which may contain leading - in them.






          share|improve this answer































            6














            To open a folder containing a space surround it in quotes like cd "Some Directory" or escape the space with a backslash, like: cd /home/kudic/Radna površina.






            share|improve this answer



















            • 3




              Or escape the space with a backslash, like: cd /home/kudic/Radna površina
              – Timo
              Jul 10 '12 at 13:43










            • Great point! I forgot to mention that. I normally use quotes out of habit, but the backslash is actually better to use in the long run.
              – Corey Whitaker
              Jul 10 '12 at 13:45






            • 1




              Or use single quotes ('Radna površina'), if you don't want environment variables ($VARNAME) to be expanded and commands enclosed in backticks or $() to be run (or if there are double-quotes in the filename).
              – Eliah Kagan
              Jul 10 '12 at 13:49





















            3














            If this directory is in your home folder then type:



            cd "Milano, Torino (Jan)-Compressed"


            else give absolute path:



            cd "/…/…/Milano, Torino (Jan)-Compressed"


            if there is a double quote in file name then escape that with "






            share|improve this answer























            • If you start a path with a leading forward slash, it goes from root. You might want to remove that.
              – isaaclw
              Feb 5 '12 at 21:52










            • @isaaclw That is why he filed it as an absolute path :P
              – user13091
              Feb 6 '12 at 1:16






            • 1




              Ah, that's three dots, indicating a "variable" folder. I assumed it was two dots, indicating "parent folder". Apologies.
              – isaaclw
              Feb 6 '12 at 3:43



















            3














            Another option although not the best in this case is to use wildcards. You can try:



            cd *Torino*



            It is best to use this method when there is a distinct word or phrase in the name of a directory not shared by others. For example I have mount points /media/DataSSD and /media/DataHDD. Autocompletion doesn't work until I type nearly half of the name so to get to my HDD partition I just type



            cd /media/*HD*






            share|improve this answer





















              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "89"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f101587%2fhow-do-i-enter-a-file-or-directory-with-special-characters-in-its-name%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              8 Answers
              8






              active

              oldest

              votes








              8 Answers
              8






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              39














              That command is ambiguous because spaces are normally used to separate arguments. cd does not know what you want to do but you have two possibilities to solve it:



              Either you "mask" the spaces (and all other special characters) so that the terminal knows you mean the space as a character and not as a separator:



              cd Milano, Torino (Jan)-Compressed


              Or you put your folder name or path into quotes:



              cd "Milano, Torino (Jan)-Compressed"





              share|improve this answer

















              • 4




                Or use single quotes ('Milano, Torino (Jan)-Compressed'), if you don't want environment variables ($VARNAME) to be expanded and commands enclosed in backticks or $() to be run (or if there are double-quotes in the filename).
                – Eliah Kagan
                Jul 10 '12 at 13:52










              • @Eliah Single-quotes also escape exclamation marks (history expansion), where double-quotes don't.
                – wjandrea
                Jan 2 at 22:29
















              39














              That command is ambiguous because spaces are normally used to separate arguments. cd does not know what you want to do but you have two possibilities to solve it:



              Either you "mask" the spaces (and all other special characters) so that the terminal knows you mean the space as a character and not as a separator:



              cd Milano, Torino (Jan)-Compressed


              Or you put your folder name or path into quotes:



              cd "Milano, Torino (Jan)-Compressed"





              share|improve this answer

















              • 4




                Or use single quotes ('Milano, Torino (Jan)-Compressed'), if you don't want environment variables ($VARNAME) to be expanded and commands enclosed in backticks or $() to be run (or if there are double-quotes in the filename).
                – Eliah Kagan
                Jul 10 '12 at 13:52










              • @Eliah Single-quotes also escape exclamation marks (history expansion), where double-quotes don't.
                – wjandrea
                Jan 2 at 22:29














              39












              39








              39






              That command is ambiguous because spaces are normally used to separate arguments. cd does not know what you want to do but you have two possibilities to solve it:



              Either you "mask" the spaces (and all other special characters) so that the terminal knows you mean the space as a character and not as a separator:



              cd Milano, Torino (Jan)-Compressed


              Or you put your folder name or path into quotes:



              cd "Milano, Torino (Jan)-Compressed"





              share|improve this answer












              That command is ambiguous because spaces are normally used to separate arguments. cd does not know what you want to do but you have two possibilities to solve it:



              Either you "mask" the spaces (and all other special characters) so that the terminal knows you mean the space as a character and not as a separator:



              cd Milano, Torino (Jan)-Compressed


              Or you put your folder name or path into quotes:



              cd "Milano, Torino (Jan)-Compressed"






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Feb 5 '12 at 12:05









              krystoph

              41633




              41633








              • 4




                Or use single quotes ('Milano, Torino (Jan)-Compressed'), if you don't want environment variables ($VARNAME) to be expanded and commands enclosed in backticks or $() to be run (or if there are double-quotes in the filename).
                – Eliah Kagan
                Jul 10 '12 at 13:52










              • @Eliah Single-quotes also escape exclamation marks (history expansion), where double-quotes don't.
                – wjandrea
                Jan 2 at 22:29














              • 4




                Or use single quotes ('Milano, Torino (Jan)-Compressed'), if you don't want environment variables ($VARNAME) to be expanded and commands enclosed in backticks or $() to be run (or if there are double-quotes in the filename).
                – Eliah Kagan
                Jul 10 '12 at 13:52










              • @Eliah Single-quotes also escape exclamation marks (history expansion), where double-quotes don't.
                – wjandrea
                Jan 2 at 22:29








              4




              4




              Or use single quotes ('Milano, Torino (Jan)-Compressed'), if you don't want environment variables ($VARNAME) to be expanded and commands enclosed in backticks or $() to be run (or if there are double-quotes in the filename).
              – Eliah Kagan
              Jul 10 '12 at 13:52




              Or use single quotes ('Milano, Torino (Jan)-Compressed'), if you don't want environment variables ($VARNAME) to be expanded and commands enclosed in backticks or $() to be run (or if there are double-quotes in the filename).
              – Eliah Kagan
              Jul 10 '12 at 13:52












              @Eliah Single-quotes also escape exclamation marks (history expansion), where double-quotes don't.
              – wjandrea
              Jan 2 at 22:29




              @Eliah Single-quotes also escape exclamation marks (history expansion), where double-quotes don't.
              – wjandrea
              Jan 2 at 22:29













              24














              A little tip: tab completion ;-)




              1. Just type the first letter e.g cd Mi (or more letters if needed) and press Tab. Terminal will help you by completing the rest words.


              Another way: drag and drop




              1. If you can see the directory and if you want to access it using terminal, just type: cd first and then drag and drop the directory on the terminal and hit enter.






              share|improve this answer



















              • 3




                Got to love tab completion <3
                – Rinzwind
                Feb 5 '12 at 15:39










              • While the accepted answer is technically correct, in practice you're going to want tab-completion so you don't have to do all that escaping.
                – phasetwenty
                Feb 9 '12 at 21:32










              • @Achu, but sometimes even the tab completion itself doesn't work for directories containing especial characters i.e. -, etc, so the suggested method would be cd -- '-foo-/'. but still we can use tab completion inside the quotation ;)
                – Amir
                Jan 10 '14 at 14:05
















              24














              A little tip: tab completion ;-)




              1. Just type the first letter e.g cd Mi (or more letters if needed) and press Tab. Terminal will help you by completing the rest words.


              Another way: drag and drop




              1. If you can see the directory and if you want to access it using terminal, just type: cd first and then drag and drop the directory on the terminal and hit enter.






              share|improve this answer



















              • 3




                Got to love tab completion <3
                – Rinzwind
                Feb 5 '12 at 15:39










              • While the accepted answer is technically correct, in practice you're going to want tab-completion so you don't have to do all that escaping.
                – phasetwenty
                Feb 9 '12 at 21:32










              • @Achu, but sometimes even the tab completion itself doesn't work for directories containing especial characters i.e. -, etc, so the suggested method would be cd -- '-foo-/'. but still we can use tab completion inside the quotation ;)
                – Amir
                Jan 10 '14 at 14:05














              24












              24








              24






              A little tip: tab completion ;-)




              1. Just type the first letter e.g cd Mi (or more letters if needed) and press Tab. Terminal will help you by completing the rest words.


              Another way: drag and drop




              1. If you can see the directory and if you want to access it using terminal, just type: cd first and then drag and drop the directory on the terminal and hit enter.






              share|improve this answer














              A little tip: tab completion ;-)




              1. Just type the first letter e.g cd Mi (or more letters if needed) and press Tab. Terminal will help you by completing the rest words.


              Another way: drag and drop




              1. If you can see the directory and if you want to access it using terminal, just type: cd first and then drag and drop the directory on the terminal and hit enter.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Jan 2 at 5:37

























              answered Feb 5 '12 at 12:35









              Achu

              15.8k136298




              15.8k136298








              • 3




                Got to love tab completion <3
                – Rinzwind
                Feb 5 '12 at 15:39










              • While the accepted answer is technically correct, in practice you're going to want tab-completion so you don't have to do all that escaping.
                – phasetwenty
                Feb 9 '12 at 21:32










              • @Achu, but sometimes even the tab completion itself doesn't work for directories containing especial characters i.e. -, etc, so the suggested method would be cd -- '-foo-/'. but still we can use tab completion inside the quotation ;)
                – Amir
                Jan 10 '14 at 14:05














              • 3




                Got to love tab completion <3
                – Rinzwind
                Feb 5 '12 at 15:39










              • While the accepted answer is technically correct, in practice you're going to want tab-completion so you don't have to do all that escaping.
                – phasetwenty
                Feb 9 '12 at 21:32










              • @Achu, but sometimes even the tab completion itself doesn't work for directories containing especial characters i.e. -, etc, so the suggested method would be cd -- '-foo-/'. but still we can use tab completion inside the quotation ;)
                – Amir
                Jan 10 '14 at 14:05








              3




              3




              Got to love tab completion <3
              – Rinzwind
              Feb 5 '12 at 15:39




              Got to love tab completion <3
              – Rinzwind
              Feb 5 '12 at 15:39












              While the accepted answer is technically correct, in practice you're going to want tab-completion so you don't have to do all that escaping.
              – phasetwenty
              Feb 9 '12 at 21:32




              While the accepted answer is technically correct, in practice you're going to want tab-completion so you don't have to do all that escaping.
              – phasetwenty
              Feb 9 '12 at 21:32












              @Achu, but sometimes even the tab completion itself doesn't work for directories containing especial characters i.e. -, etc, so the suggested method would be cd -- '-foo-/'. but still we can use tab completion inside the quotation ;)
              – Amir
              Jan 10 '14 at 14:05




              @Achu, but sometimes even the tab completion itself doesn't work for directories containing especial characters i.e. -, etc, so the suggested method would be cd -- '-foo-/'. but still we can use tab completion inside the quotation ;)
              – Amir
              Jan 10 '14 at 14:05











              23














              Write it as



              cd 'Milano, Torino (Jan)-Compressed'


              Otherwise it treats Milano, as the folder name. This happens because of the spaces in the name of the folder.



              Alternatively escape a few of the special characters...



              cd Milano, Torino (Jan)-Compressed/





              share|improve this answer



















              • 10




                You can also use Tab for auto-completion inside the double quotes to auto-escape double-quotes within the filename.
                – htorque
                Feb 5 '12 at 12:06






              • 3




                Note that double quotes won't help you cd into a directory named $money, for example. You'd need to write '$money' or $money.
                – Dietrich Epp
                Feb 5 '12 at 20:22






              • 3




                I think generally single quotes are more explicit, and a better standard. Both work, but single quotes work more often and say "exactly as you see it".
                – isaaclw
                Feb 5 '12 at 21:50










              • @isaaclw Thanks, I agree! Edited.
                – Prateek
                Feb 6 '12 at 14:14
















              23














              Write it as



              cd 'Milano, Torino (Jan)-Compressed'


              Otherwise it treats Milano, as the folder name. This happens because of the spaces in the name of the folder.



              Alternatively escape a few of the special characters...



              cd Milano, Torino (Jan)-Compressed/





              share|improve this answer



















              • 10




                You can also use Tab for auto-completion inside the double quotes to auto-escape double-quotes within the filename.
                – htorque
                Feb 5 '12 at 12:06






              • 3




                Note that double quotes won't help you cd into a directory named $money, for example. You'd need to write '$money' or $money.
                – Dietrich Epp
                Feb 5 '12 at 20:22






              • 3




                I think generally single quotes are more explicit, and a better standard. Both work, but single quotes work more often and say "exactly as you see it".
                – isaaclw
                Feb 5 '12 at 21:50










              • @isaaclw Thanks, I agree! Edited.
                – Prateek
                Feb 6 '12 at 14:14














              23












              23








              23






              Write it as



              cd 'Milano, Torino (Jan)-Compressed'


              Otherwise it treats Milano, as the folder name. This happens because of the spaces in the name of the folder.



              Alternatively escape a few of the special characters...



              cd Milano, Torino (Jan)-Compressed/





              share|improve this answer














              Write it as



              cd 'Milano, Torino (Jan)-Compressed'


              Otherwise it treats Milano, as the folder name. This happens because of the spaces in the name of the folder.



              Alternatively escape a few of the special characters...



              cd Milano, Torino (Jan)-Compressed/






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Feb 6 '12 at 14:13

























              answered Feb 5 '12 at 11:59









              Prateek

              2,05621731




              2,05621731








              • 10




                You can also use Tab for auto-completion inside the double quotes to auto-escape double-quotes within the filename.
                – htorque
                Feb 5 '12 at 12:06






              • 3




                Note that double quotes won't help you cd into a directory named $money, for example. You'd need to write '$money' or $money.
                – Dietrich Epp
                Feb 5 '12 at 20:22






              • 3




                I think generally single quotes are more explicit, and a better standard. Both work, but single quotes work more often and say "exactly as you see it".
                – isaaclw
                Feb 5 '12 at 21:50










              • @isaaclw Thanks, I agree! Edited.
                – Prateek
                Feb 6 '12 at 14:14














              • 10




                You can also use Tab for auto-completion inside the double quotes to auto-escape double-quotes within the filename.
                – htorque
                Feb 5 '12 at 12:06






              • 3




                Note that double quotes won't help you cd into a directory named $money, for example. You'd need to write '$money' or $money.
                – Dietrich Epp
                Feb 5 '12 at 20:22






              • 3




                I think generally single quotes are more explicit, and a better standard. Both work, but single quotes work more often and say "exactly as you see it".
                – isaaclw
                Feb 5 '12 at 21:50










              • @isaaclw Thanks, I agree! Edited.
                – Prateek
                Feb 6 '12 at 14:14








              10




              10




              You can also use Tab for auto-completion inside the double quotes to auto-escape double-quotes within the filename.
              – htorque
              Feb 5 '12 at 12:06




              You can also use Tab for auto-completion inside the double quotes to auto-escape double-quotes within the filename.
              – htorque
              Feb 5 '12 at 12:06




              3




              3




              Note that double quotes won't help you cd into a directory named $money, for example. You'd need to write '$money' or $money.
              – Dietrich Epp
              Feb 5 '12 at 20:22




              Note that double quotes won't help you cd into a directory named $money, for example. You'd need to write '$money' or $money.
              – Dietrich Epp
              Feb 5 '12 at 20:22




              3




              3




              I think generally single quotes are more explicit, and a better standard. Both work, but single quotes work more often and say "exactly as you see it".
              – isaaclw
              Feb 5 '12 at 21:50




              I think generally single quotes are more explicit, and a better standard. Both work, but single quotes work more often and say "exactly as you see it".
              – isaaclw
              Feb 5 '12 at 21:50












              @isaaclw Thanks, I agree! Edited.
              – Prateek
              Feb 6 '12 at 14:14




              @isaaclw Thanks, I agree! Edited.
              – Prateek
              Feb 6 '12 at 14:14











              22














              tl;dr: To quote a special character either escape it with a backslash or enclose it in double " " or single quotes ' '. Tab ↹ Completion takes care of proper quoting.





              What you're asking for is called Quoting:




              Quoting is used to remove the special meaning of certain characters or words to the shell. (…) There are three quoting mechanisms: the escape character, single quotes, and double quotes.
              [citations taken from man bash]




              Quoting with the escape character




              A non-quoted backslash () is the escape character. It preserves the literal value of the next character that follows, with the exception of <newline>.




              So to enter a directory or a file with a special character, escape the latter with , e.g.:



              cd space dir      # change into directory called “space dir”
              cat space file # print the content of file “space file”
              echo content > \ # print “content” into file “”
              cat ( # print the content of file “(”
              ls -l ? # list file “?”


              bash's Programmable Completion (aka Tab ↹ Completion) automatically escapes special characters with the escape character .



              Quoting with double quotes " "




              Enclosing characters in double quotes preserves the literal value of all characters within the quotes, with the exception of $, `, , and, when history expansion is enabled, !.




              So to enter a directory or a file with a special character, escape at least the latter or a greater part of your filename or path with double quotes, e.g.:



              cd space" "dir     # change into directory called “space dir”
              cd spac"e di"r # equally
              cd "space dir" # equally
              cat "space file" # print the content of file “space file”
              cat "(" # print the content of file “(”
              ls -l "?" # list file “?”


              As $, ` and ! keep their special meaning inside double quotes, Parameter Expansion, Command Substitution, Arithmetic Expansion and History Expansion are performed on double-quoted strings.



              Quoting with single quotes ' '




              Enclosing characters in single quotes preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash.




              So to enter a directory or a file with a special character, escape at least the latter or a greater part of your filename or path with double quotes, e.g.:



              cd space' 'dir     # change into directory called “space dir”
              cd spac'e di'r # equal
              cd 'space dir' # equal
              cat 'space file' # print the content of file “space file”
              cat '(' # print the content of file “(”
              ls -l '?' # list file “?”
              echo content > '' # print “content” into file “”




              You can find more about Quoting in man bash/QUOTING, on wiki.bash-hackers.org and on tldp.org.






              share|improve this answer























              • '' breaks the shell syntax highlighter of SE.
                – David Foerster
                Dec 30 '17 at 20:35












              • @DavidFoerster There's the limit of google prettify (which is used for that), but I thought better than nothing… How about now? ;P
                – dessert
                Dec 30 '17 at 20:40












              • That was more a statement of fact and a little surprise than a criticism of your post. The only criticism here might go to the syntax highlighter. I would have done nothing about it personally.
                – David Foerster
                Dec 30 '17 at 20:41


















              22














              tl;dr: To quote a special character either escape it with a backslash or enclose it in double " " or single quotes ' '. Tab ↹ Completion takes care of proper quoting.





              What you're asking for is called Quoting:




              Quoting is used to remove the special meaning of certain characters or words to the shell. (…) There are three quoting mechanisms: the escape character, single quotes, and double quotes.
              [citations taken from man bash]




              Quoting with the escape character




              A non-quoted backslash () is the escape character. It preserves the literal value of the next character that follows, with the exception of <newline>.




              So to enter a directory or a file with a special character, escape the latter with , e.g.:



              cd space dir      # change into directory called “space dir”
              cat space file # print the content of file “space file”
              echo content > \ # print “content” into file “”
              cat ( # print the content of file “(”
              ls -l ? # list file “?”


              bash's Programmable Completion (aka Tab ↹ Completion) automatically escapes special characters with the escape character .



              Quoting with double quotes " "




              Enclosing characters in double quotes preserves the literal value of all characters within the quotes, with the exception of $, `, , and, when history expansion is enabled, !.




              So to enter a directory or a file with a special character, escape at least the latter or a greater part of your filename or path with double quotes, e.g.:



              cd space" "dir     # change into directory called “space dir”
              cd spac"e di"r # equally
              cd "space dir" # equally
              cat "space file" # print the content of file “space file”
              cat "(" # print the content of file “(”
              ls -l "?" # list file “?”


              As $, ` and ! keep their special meaning inside double quotes, Parameter Expansion, Command Substitution, Arithmetic Expansion and History Expansion are performed on double-quoted strings.



              Quoting with single quotes ' '




              Enclosing characters in single quotes preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash.




              So to enter a directory or a file with a special character, escape at least the latter or a greater part of your filename or path with double quotes, e.g.:



              cd space' 'dir     # change into directory called “space dir”
              cd spac'e di'r # equal
              cd 'space dir' # equal
              cat 'space file' # print the content of file “space file”
              cat '(' # print the content of file “(”
              ls -l '?' # list file “?”
              echo content > '' # print “content” into file “”




              You can find more about Quoting in man bash/QUOTING, on wiki.bash-hackers.org and on tldp.org.






              share|improve this answer























              • '' breaks the shell syntax highlighter of SE.
                – David Foerster
                Dec 30 '17 at 20:35












              • @DavidFoerster There's the limit of google prettify (which is used for that), but I thought better than nothing… How about now? ;P
                – dessert
                Dec 30 '17 at 20:40












              • That was more a statement of fact and a little surprise than a criticism of your post. The only criticism here might go to the syntax highlighter. I would have done nothing about it personally.
                – David Foerster
                Dec 30 '17 at 20:41
















              22












              22








              22






              tl;dr: To quote a special character either escape it with a backslash or enclose it in double " " or single quotes ' '. Tab ↹ Completion takes care of proper quoting.





              What you're asking for is called Quoting:




              Quoting is used to remove the special meaning of certain characters or words to the shell. (…) There are three quoting mechanisms: the escape character, single quotes, and double quotes.
              [citations taken from man bash]




              Quoting with the escape character




              A non-quoted backslash () is the escape character. It preserves the literal value of the next character that follows, with the exception of <newline>.




              So to enter a directory or a file with a special character, escape the latter with , e.g.:



              cd space dir      # change into directory called “space dir”
              cat space file # print the content of file “space file”
              echo content > \ # print “content” into file “”
              cat ( # print the content of file “(”
              ls -l ? # list file “?”


              bash's Programmable Completion (aka Tab ↹ Completion) automatically escapes special characters with the escape character .



              Quoting with double quotes " "




              Enclosing characters in double quotes preserves the literal value of all characters within the quotes, with the exception of $, `, , and, when history expansion is enabled, !.




              So to enter a directory or a file with a special character, escape at least the latter or a greater part of your filename or path with double quotes, e.g.:



              cd space" "dir     # change into directory called “space dir”
              cd spac"e di"r # equally
              cd "space dir" # equally
              cat "space file" # print the content of file “space file”
              cat "(" # print the content of file “(”
              ls -l "?" # list file “?”


              As $, ` and ! keep their special meaning inside double quotes, Parameter Expansion, Command Substitution, Arithmetic Expansion and History Expansion are performed on double-quoted strings.



              Quoting with single quotes ' '




              Enclosing characters in single quotes preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash.




              So to enter a directory or a file with a special character, escape at least the latter or a greater part of your filename or path with double quotes, e.g.:



              cd space' 'dir     # change into directory called “space dir”
              cd spac'e di'r # equal
              cd 'space dir' # equal
              cat 'space file' # print the content of file “space file”
              cat '(' # print the content of file “(”
              ls -l '?' # list file “?”
              echo content > '' # print “content” into file “”




              You can find more about Quoting in man bash/QUOTING, on wiki.bash-hackers.org and on tldp.org.






              share|improve this answer














              tl;dr: To quote a special character either escape it with a backslash or enclose it in double " " or single quotes ' '. Tab ↹ Completion takes care of proper quoting.





              What you're asking for is called Quoting:




              Quoting is used to remove the special meaning of certain characters or words to the shell. (…) There are three quoting mechanisms: the escape character, single quotes, and double quotes.
              [citations taken from man bash]




              Quoting with the escape character




              A non-quoted backslash () is the escape character. It preserves the literal value of the next character that follows, with the exception of <newline>.




              So to enter a directory or a file with a special character, escape the latter with , e.g.:



              cd space dir      # change into directory called “space dir”
              cat space file # print the content of file “space file”
              echo content > \ # print “content” into file “”
              cat ( # print the content of file “(”
              ls -l ? # list file “?”


              bash's Programmable Completion (aka Tab ↹ Completion) automatically escapes special characters with the escape character .



              Quoting with double quotes " "




              Enclosing characters in double quotes preserves the literal value of all characters within the quotes, with the exception of $, `, , and, when history expansion is enabled, !.




              So to enter a directory or a file with a special character, escape at least the latter or a greater part of your filename or path with double quotes, e.g.:



              cd space" "dir     # change into directory called “space dir”
              cd spac"e di"r # equally
              cd "space dir" # equally
              cat "space file" # print the content of file “space file”
              cat "(" # print the content of file “(”
              ls -l "?" # list file “?”


              As $, ` and ! keep their special meaning inside double quotes, Parameter Expansion, Command Substitution, Arithmetic Expansion and History Expansion are performed on double-quoted strings.



              Quoting with single quotes ' '




              Enclosing characters in single quotes preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash.




              So to enter a directory or a file with a special character, escape at least the latter or a greater part of your filename or path with double quotes, e.g.:



              cd space' 'dir     # change into directory called “space dir”
              cd spac'e di'r # equal
              cd 'space dir' # equal
              cat 'space file' # print the content of file “space file”
              cat '(' # print the content of file “(”
              ls -l '?' # list file “?”
              echo content > '' # print “content” into file “”




              You can find more about Quoting in man bash/QUOTING, on wiki.bash-hackers.org and on tldp.org.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Dec 30 '17 at 20:40

























              answered Dec 9 '17 at 21:31









              dessert

              22.2k56198




              22.2k56198












              • '' breaks the shell syntax highlighter of SE.
                – David Foerster
                Dec 30 '17 at 20:35












              • @DavidFoerster There's the limit of google prettify (which is used for that), but I thought better than nothing… How about now? ;P
                – dessert
                Dec 30 '17 at 20:40












              • That was more a statement of fact and a little surprise than a criticism of your post. The only criticism here might go to the syntax highlighter. I would have done nothing about it personally.
                – David Foerster
                Dec 30 '17 at 20:41




















              • '' breaks the shell syntax highlighter of SE.
                – David Foerster
                Dec 30 '17 at 20:35












              • @DavidFoerster There's the limit of google prettify (which is used for that), but I thought better than nothing… How about now? ;P
                – dessert
                Dec 30 '17 at 20:40












              • That was more a statement of fact and a little surprise than a criticism of your post. The only criticism here might go to the syntax highlighter. I would have done nothing about it personally.
                – David Foerster
                Dec 30 '17 at 20:41


















              '' breaks the shell syntax highlighter of SE.
              – David Foerster
              Dec 30 '17 at 20:35






              '' breaks the shell syntax highlighter of SE.
              – David Foerster
              Dec 30 '17 at 20:35














              @DavidFoerster There's the limit of google prettify (which is used for that), but I thought better than nothing… How about now? ;P
              – dessert
              Dec 30 '17 at 20:40






              @DavidFoerster There's the limit of google prettify (which is used for that), but I thought better than nothing… How about now? ;P
              – dessert
              Dec 30 '17 at 20:40














              That was more a statement of fact and a little surprise than a criticism of your post. The only criticism here might go to the syntax highlighter. I would have done nothing about it personally.
              – David Foerster
              Dec 30 '17 at 20:41






              That was more a statement of fact and a little surprise than a criticism of your post. The only criticism here might go to the syntax highlighter. I would have done nothing about it personally.
              – David Foerster
              Dec 30 '17 at 20:41













              10














              C-like strings and $'string'



              Among other things, one can use $'...' type of quoting to make use of ANSI-C backslash characters such as n and t, including those you've mentioned. From bash 4.3 manual:




              Words of the form $'string' are treated specially. The word expands
              to string, with backslash-escaped characters replaced as specified
              by the ANSI C standard.




              This is particularly useful with files which contain newlines, tabs, when you're writing complex awk lines where you need to make use of different ways to distinguish between single and double quotes, when filenames themselves contain single/double quote mishmash,etc.



              For example, creating and listing such files:



              $ touch a$'*'b  c$'n'd                                                     
              $ ls a$'*'b c$'n'd
              a*b c?d


              You can make use of character hex values, such as:



              $ touch 'file(name'
              $ ls file$'x28'name
              file(name


              printf



              Same idea as before - take advantage of escape characters:



              $ ls "$(printf "filex28name")"                                             
              file(name
              $ echo "Hello World" > c$'n'd
              $ cat "$(printf "cnd")"
              Hello World


              Use inodes:



              Every file or directory has special data structure associated with it called inode, which are referenced by a particular decimal number. So you can use that to indirectly locate the file with particular inode via find command, and do something with it:



              $ echo "This is a test" > file$'('name1
              $ ls -i
              5898996 file(name1 5898997 file?name2
              $ find -type f -inum "5898996" -exec cat {} ;
              This is a test


              Avoid dealing with individual files when you can use glob



              When you don't have to deal with individual files, just take advantage of * glob character in shell and quote variables when passing them to other commands. It makes dealing with difficult filenames much easier:



              $ for f in ./*; do echo "$f" ; done
              file name2
              file(name1


              Note the use of ./ - a safeguard against filenames which may contain leading - in them.






              share|improve this answer




























                10














                C-like strings and $'string'



                Among other things, one can use $'...' type of quoting to make use of ANSI-C backslash characters such as n and t, including those you've mentioned. From bash 4.3 manual:




                Words of the form $'string' are treated specially. The word expands
                to string, with backslash-escaped characters replaced as specified
                by the ANSI C standard.




                This is particularly useful with files which contain newlines, tabs, when you're writing complex awk lines where you need to make use of different ways to distinguish between single and double quotes, when filenames themselves contain single/double quote mishmash,etc.



                For example, creating and listing such files:



                $ touch a$'*'b  c$'n'd                                                     
                $ ls a$'*'b c$'n'd
                a*b c?d


                You can make use of character hex values, such as:



                $ touch 'file(name'
                $ ls file$'x28'name
                file(name


                printf



                Same idea as before - take advantage of escape characters:



                $ ls "$(printf "filex28name")"                                             
                file(name
                $ echo "Hello World" > c$'n'd
                $ cat "$(printf "cnd")"
                Hello World


                Use inodes:



                Every file or directory has special data structure associated with it called inode, which are referenced by a particular decimal number. So you can use that to indirectly locate the file with particular inode via find command, and do something with it:



                $ echo "This is a test" > file$'('name1
                $ ls -i
                5898996 file(name1 5898997 file?name2
                $ find -type f -inum "5898996" -exec cat {} ;
                This is a test


                Avoid dealing with individual files when you can use glob



                When you don't have to deal with individual files, just take advantage of * glob character in shell and quote variables when passing them to other commands. It makes dealing with difficult filenames much easier:



                $ for f in ./*; do echo "$f" ; done
                file name2
                file(name1


                Note the use of ./ - a safeguard against filenames which may contain leading - in them.






                share|improve this answer


























                  10












                  10








                  10






                  C-like strings and $'string'



                  Among other things, one can use $'...' type of quoting to make use of ANSI-C backslash characters such as n and t, including those you've mentioned. From bash 4.3 manual:




                  Words of the form $'string' are treated specially. The word expands
                  to string, with backslash-escaped characters replaced as specified
                  by the ANSI C standard.




                  This is particularly useful with files which contain newlines, tabs, when you're writing complex awk lines where you need to make use of different ways to distinguish between single and double quotes, when filenames themselves contain single/double quote mishmash,etc.



                  For example, creating and listing such files:



                  $ touch a$'*'b  c$'n'd                                                     
                  $ ls a$'*'b c$'n'd
                  a*b c?d


                  You can make use of character hex values, such as:



                  $ touch 'file(name'
                  $ ls file$'x28'name
                  file(name


                  printf



                  Same idea as before - take advantage of escape characters:



                  $ ls "$(printf "filex28name")"                                             
                  file(name
                  $ echo "Hello World" > c$'n'd
                  $ cat "$(printf "cnd")"
                  Hello World


                  Use inodes:



                  Every file or directory has special data structure associated with it called inode, which are referenced by a particular decimal number. So you can use that to indirectly locate the file with particular inode via find command, and do something with it:



                  $ echo "This is a test" > file$'('name1
                  $ ls -i
                  5898996 file(name1 5898997 file?name2
                  $ find -type f -inum "5898996" -exec cat {} ;
                  This is a test


                  Avoid dealing with individual files when you can use glob



                  When you don't have to deal with individual files, just take advantage of * glob character in shell and quote variables when passing them to other commands. It makes dealing with difficult filenames much easier:



                  $ for f in ./*; do echo "$f" ; done
                  file name2
                  file(name1


                  Note the use of ./ - a safeguard against filenames which may contain leading - in them.






                  share|improve this answer














                  C-like strings and $'string'



                  Among other things, one can use $'...' type of quoting to make use of ANSI-C backslash characters such as n and t, including those you've mentioned. From bash 4.3 manual:




                  Words of the form $'string' are treated specially. The word expands
                  to string, with backslash-escaped characters replaced as specified
                  by the ANSI C standard.




                  This is particularly useful with files which contain newlines, tabs, when you're writing complex awk lines where you need to make use of different ways to distinguish between single and double quotes, when filenames themselves contain single/double quote mishmash,etc.



                  For example, creating and listing such files:



                  $ touch a$'*'b  c$'n'd                                                     
                  $ ls a$'*'b c$'n'd
                  a*b c?d


                  You can make use of character hex values, such as:



                  $ touch 'file(name'
                  $ ls file$'x28'name
                  file(name


                  printf



                  Same idea as before - take advantage of escape characters:



                  $ ls "$(printf "filex28name")"                                             
                  file(name
                  $ echo "Hello World" > c$'n'd
                  $ cat "$(printf "cnd")"
                  Hello World


                  Use inodes:



                  Every file or directory has special data structure associated with it called inode, which are referenced by a particular decimal number. So you can use that to indirectly locate the file with particular inode via find command, and do something with it:



                  $ echo "This is a test" > file$'('name1
                  $ ls -i
                  5898996 file(name1 5898997 file?name2
                  $ find -type f -inum "5898996" -exec cat {} ;
                  This is a test


                  Avoid dealing with individual files when you can use glob



                  When you don't have to deal with individual files, just take advantage of * glob character in shell and quote variables when passing them to other commands. It makes dealing with difficult filenames much easier:



                  $ for f in ./*; do echo "$f" ; done
                  file name2
                  file(name1


                  Note the use of ./ - a safeguard against filenames which may contain leading - in them.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Dec 9 '17 at 22:04

























                  answered Dec 9 '17 at 21:43









                  Sergiy Kolodyazhnyy

                  69.9k9144307




                  69.9k9144307























                      6














                      To open a folder containing a space surround it in quotes like cd "Some Directory" or escape the space with a backslash, like: cd /home/kudic/Radna površina.






                      share|improve this answer



















                      • 3




                        Or escape the space with a backslash, like: cd /home/kudic/Radna površina
                        – Timo
                        Jul 10 '12 at 13:43










                      • Great point! I forgot to mention that. I normally use quotes out of habit, but the backslash is actually better to use in the long run.
                        – Corey Whitaker
                        Jul 10 '12 at 13:45






                      • 1




                        Or use single quotes ('Radna površina'), if you don't want environment variables ($VARNAME) to be expanded and commands enclosed in backticks or $() to be run (or if there are double-quotes in the filename).
                        – Eliah Kagan
                        Jul 10 '12 at 13:49


















                      6














                      To open a folder containing a space surround it in quotes like cd "Some Directory" or escape the space with a backslash, like: cd /home/kudic/Radna površina.






                      share|improve this answer



















                      • 3




                        Or escape the space with a backslash, like: cd /home/kudic/Radna površina
                        – Timo
                        Jul 10 '12 at 13:43










                      • Great point! I forgot to mention that. I normally use quotes out of habit, but the backslash is actually better to use in the long run.
                        – Corey Whitaker
                        Jul 10 '12 at 13:45






                      • 1




                        Or use single quotes ('Radna površina'), if you don't want environment variables ($VARNAME) to be expanded and commands enclosed in backticks or $() to be run (or if there are double-quotes in the filename).
                        – Eliah Kagan
                        Jul 10 '12 at 13:49
















                      6












                      6








                      6






                      To open a folder containing a space surround it in quotes like cd "Some Directory" or escape the space with a backslash, like: cd /home/kudic/Radna površina.






                      share|improve this answer














                      To open a folder containing a space surround it in quotes like cd "Some Directory" or escape the space with a backslash, like: cd /home/kudic/Radna površina.







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Jul 10 '12 at 13:46









                      Javier Rivera

                      29.8k977101




                      29.8k977101










                      answered Jul 10 '12 at 13:41









                      Corey Whitaker

                      845712




                      845712








                      • 3




                        Or escape the space with a backslash, like: cd /home/kudic/Radna površina
                        – Timo
                        Jul 10 '12 at 13:43










                      • Great point! I forgot to mention that. I normally use quotes out of habit, but the backslash is actually better to use in the long run.
                        – Corey Whitaker
                        Jul 10 '12 at 13:45






                      • 1




                        Or use single quotes ('Radna površina'), if you don't want environment variables ($VARNAME) to be expanded and commands enclosed in backticks or $() to be run (or if there are double-quotes in the filename).
                        – Eliah Kagan
                        Jul 10 '12 at 13:49
















                      • 3




                        Or escape the space with a backslash, like: cd /home/kudic/Radna površina
                        – Timo
                        Jul 10 '12 at 13:43










                      • Great point! I forgot to mention that. I normally use quotes out of habit, but the backslash is actually better to use in the long run.
                        – Corey Whitaker
                        Jul 10 '12 at 13:45






                      • 1




                        Or use single quotes ('Radna površina'), if you don't want environment variables ($VARNAME) to be expanded and commands enclosed in backticks or $() to be run (or if there are double-quotes in the filename).
                        – Eliah Kagan
                        Jul 10 '12 at 13:49










                      3




                      3




                      Or escape the space with a backslash, like: cd /home/kudic/Radna površina
                      – Timo
                      Jul 10 '12 at 13:43




                      Or escape the space with a backslash, like: cd /home/kudic/Radna površina
                      – Timo
                      Jul 10 '12 at 13:43












                      Great point! I forgot to mention that. I normally use quotes out of habit, but the backslash is actually better to use in the long run.
                      – Corey Whitaker
                      Jul 10 '12 at 13:45




                      Great point! I forgot to mention that. I normally use quotes out of habit, but the backslash is actually better to use in the long run.
                      – Corey Whitaker
                      Jul 10 '12 at 13:45




                      1




                      1




                      Or use single quotes ('Radna površina'), if you don't want environment variables ($VARNAME) to be expanded and commands enclosed in backticks or $() to be run (or if there are double-quotes in the filename).
                      – Eliah Kagan
                      Jul 10 '12 at 13:49






                      Or use single quotes ('Radna površina'), if you don't want environment variables ($VARNAME) to be expanded and commands enclosed in backticks or $() to be run (or if there are double-quotes in the filename).
                      – Eliah Kagan
                      Jul 10 '12 at 13:49













                      3














                      If this directory is in your home folder then type:



                      cd "Milano, Torino (Jan)-Compressed"


                      else give absolute path:



                      cd "/…/…/Milano, Torino (Jan)-Compressed"


                      if there is a double quote in file name then escape that with "






                      share|improve this answer























                      • If you start a path with a leading forward slash, it goes from root. You might want to remove that.
                        – isaaclw
                        Feb 5 '12 at 21:52










                      • @isaaclw That is why he filed it as an absolute path :P
                        – user13091
                        Feb 6 '12 at 1:16






                      • 1




                        Ah, that's three dots, indicating a "variable" folder. I assumed it was two dots, indicating "parent folder". Apologies.
                        – isaaclw
                        Feb 6 '12 at 3:43
















                      3














                      If this directory is in your home folder then type:



                      cd "Milano, Torino (Jan)-Compressed"


                      else give absolute path:



                      cd "/…/…/Milano, Torino (Jan)-Compressed"


                      if there is a double quote in file name then escape that with "






                      share|improve this answer























                      • If you start a path with a leading forward slash, it goes from root. You might want to remove that.
                        – isaaclw
                        Feb 5 '12 at 21:52










                      • @isaaclw That is why he filed it as an absolute path :P
                        – user13091
                        Feb 6 '12 at 1:16






                      • 1




                        Ah, that's three dots, indicating a "variable" folder. I assumed it was two dots, indicating "parent folder". Apologies.
                        – isaaclw
                        Feb 6 '12 at 3:43














                      3












                      3








                      3






                      If this directory is in your home folder then type:



                      cd "Milano, Torino (Jan)-Compressed"


                      else give absolute path:



                      cd "/…/…/Milano, Torino (Jan)-Compressed"


                      if there is a double quote in file name then escape that with "






                      share|improve this answer














                      If this directory is in your home folder then type:



                      cd "Milano, Torino (Jan)-Compressed"


                      else give absolute path:



                      cd "/…/…/Milano, Torino (Jan)-Compressed"


                      if there is a double quote in file name then escape that with "







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Feb 5 '12 at 19:06









                      sladen

                      5,33612027




                      5,33612027










                      answered Feb 5 '12 at 12:00









                      Harshveer Singh

                      346138




                      346138












                      • If you start a path with a leading forward slash, it goes from root. You might want to remove that.
                        – isaaclw
                        Feb 5 '12 at 21:52










                      • @isaaclw That is why he filed it as an absolute path :P
                        – user13091
                        Feb 6 '12 at 1:16






                      • 1




                        Ah, that's three dots, indicating a "variable" folder. I assumed it was two dots, indicating "parent folder". Apologies.
                        – isaaclw
                        Feb 6 '12 at 3:43


















                      • If you start a path with a leading forward slash, it goes from root. You might want to remove that.
                        – isaaclw
                        Feb 5 '12 at 21:52










                      • @isaaclw That is why he filed it as an absolute path :P
                        – user13091
                        Feb 6 '12 at 1:16






                      • 1




                        Ah, that's three dots, indicating a "variable" folder. I assumed it was two dots, indicating "parent folder". Apologies.
                        – isaaclw
                        Feb 6 '12 at 3:43
















                      If you start a path with a leading forward slash, it goes from root. You might want to remove that.
                      – isaaclw
                      Feb 5 '12 at 21:52




                      If you start a path with a leading forward slash, it goes from root. You might want to remove that.
                      – isaaclw
                      Feb 5 '12 at 21:52












                      @isaaclw That is why he filed it as an absolute path :P
                      – user13091
                      Feb 6 '12 at 1:16




                      @isaaclw That is why he filed it as an absolute path :P
                      – user13091
                      Feb 6 '12 at 1:16




                      1




                      1




                      Ah, that's three dots, indicating a "variable" folder. I assumed it was two dots, indicating "parent folder". Apologies.
                      – isaaclw
                      Feb 6 '12 at 3:43




                      Ah, that's three dots, indicating a "variable" folder. I assumed it was two dots, indicating "parent folder". Apologies.
                      – isaaclw
                      Feb 6 '12 at 3:43











                      3














                      Another option although not the best in this case is to use wildcards. You can try:



                      cd *Torino*



                      It is best to use this method when there is a distinct word or phrase in the name of a directory not shared by others. For example I have mount points /media/DataSSD and /media/DataHDD. Autocompletion doesn't work until I type nearly half of the name so to get to my HDD partition I just type



                      cd /media/*HD*






                      share|improve this answer


























                        3














                        Another option although not the best in this case is to use wildcards. You can try:



                        cd *Torino*



                        It is best to use this method when there is a distinct word or phrase in the name of a directory not shared by others. For example I have mount points /media/DataSSD and /media/DataHDD. Autocompletion doesn't work until I type nearly half of the name so to get to my HDD partition I just type



                        cd /media/*HD*






                        share|improve this answer
























                          3












                          3








                          3






                          Another option although not the best in this case is to use wildcards. You can try:



                          cd *Torino*



                          It is best to use this method when there is a distinct word or phrase in the name of a directory not shared by others. For example I have mount points /media/DataSSD and /media/DataHDD. Autocompletion doesn't work until I type nearly half of the name so to get to my HDD partition I just type



                          cd /media/*HD*






                          share|improve this answer












                          Another option although not the best in this case is to use wildcards. You can try:



                          cd *Torino*



                          It is best to use this method when there is a distinct word or phrase in the name of a directory not shared by others. For example I have mount points /media/DataSSD and /media/DataHDD. Autocompletion doesn't work until I type nearly half of the name so to get to my HDD partition I just type



                          cd /media/*HD*







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Feb 2 '14 at 17:38









                          user242845

                          311




                          311






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Ask Ubuntu!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.





                              Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                              Please pay close attention to the following guidance:


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f101587%2fhow-do-i-enter-a-file-or-directory-with-special-characters-in-its-name%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              數位音樂下載

                              When can things happen in Etherscan, such as the picture below?

                              格利澤436b