can't cd into directory with spaces

0

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?

kennzors

Posted 2013-01-14T01:11:48.027

Reputation: 1

3Is it possible you have an alias or procedure defined for cd? – Nicole Hamilton – 2013-01-14T01:14:38.973

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 – 2013-01-14T01:21:38.083

Glad I was able to help. Have a great new year. – Nicole Hamilton – 2013-01-14T01:24:50.223

Answers

3

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.

mdpc

Posted 2013-01-14T01:11:48.027

Reputation: 4 176

3

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 "

slm

Posted 2013-01-14T01:11:48.027

Reputation: 7 449