Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have tried all the ways of getting into a directory with spaces, and they all do not work.

mkdir "test folder"

Attempt #1

cd "test folder"

**bash: cd: test: No such file or directory**

Attempt #2

cd 'test folder'

**bash: cd: test: No such file or directory**

Attempt #3

cd test\ folder/

**bash: cd: test: No such file or directory**

Attempt #4

TEST=test\ folder

echo $TEST
**test folder**

cd $TEST

**bash: cd: test: No such file or directory**

this is my bash version: GNU bash, version 4.2.24(1)-release (i686-pc-linux-gnu). Could it possibly be something is wrong with my .bashrc?

share
3  
Is it possible you have an alias or procedure defined for cd? –  Nicole Hamilton Jan 14 '13 at 1:14
    
YES!!! I had a script that changes the name of the window to the name of the file I was editting!! THANK YOU!!! Overlooked this :( hahaha –  kennzors Jan 14 '13 at 1:21
    
Glad I was able to help. Have a great new year. –  Nicole Hamilton Jan 14 '13 at 1:24

2 Answers 2

There could be other hidden characters (other than a space....like maybe a TAB) in the directory name.....

Try:

 cd *folder

OR

 cd test*

and see if this works.

share
    
this works as well! Thank you!! –  kennzors Jan 14 '13 at 1:22

You can use the following ls switches to detective these types of problems:

   -b, --escape
          print C-style escapes for nongraphic characters

   -q, --hide-control-chars
          print ? instead of non graphic characters

   --show-control-chars
          show non graphic characters as-is (default unless program is `ls' and output is a terminal)

   -Q, --quote-name
          enclose entry names in double quotes

NOTE: The --show-control-chars is usually on by default.

Examples:

% touch normal_file
% touch "spacy_file "
% touch "ctrl_file^[^\^]"

NOTE: The 3rd file was created by pressing ...

  • hold Ctrl and press V & 3
  • hold Ctrl and press V & 4
  • hold Ctrl and press V & 5

-lb

% ls -lb
total 0
-rw-rw-r-- 1 saml saml 0 Jan 13 21:22 ctrl_file\033\034\035
-rw-rw-r-- 1 saml saml 0 Jan 13 21:22 normal_file
-rw-rw-r-- 1 saml saml 0 Jan 13 21:22 spacy_file\ 

-l

% ls -l
total 0
-rw-rw-r-- 1 saml saml 0 Jan 13 21:22 ctrl_file???
-rw-rw-r-- 1 saml saml 0 Jan 13 21:22 normal_file
-rw-rw-r-- 1 saml saml 0 Jan 13 21:22 spacy_file 

-q

% ls -q
ctrl_file???  normal_file  spacy_file 

-lq

% ls -lq
total 0
-rw-rw-r-- 1 saml saml 0 Jan 13 21:22 ctrl_file???
-rw-rw-r-- 1 saml saml 0 Jan 13 21:22 normal_file
-rw-rw-r-- 1 saml saml 0 Jan 13 21:22 spacy_file 

-lQ

% ls -lQ
total 0
-rw-rw-r-- 1 saml saml 0 Jan 13 21:22 "ctrl_file\033\034\035"
-rw-rw-r-- 1 saml saml 0 Jan 13 21:22 "normal_file"
-rw-rw-r-- 1 saml saml 0 Jan 13 21:22 "spacy_file "
share

This site is currently not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .