8.11. Can't Access a File? Look for Spaces in the Name
% ls afile exefiles j toobig % lpr afile lpr: afile: No such file or directory
Huh? ls shows that the file is there, doesn't it? Try using:
% ls -l | cat -v -t -e total 89$ -rw-rw-rw- 1 jerry 28 Mar 7 19:46 afile $ -rw-r--r-- 1 root 25179 Mar 4 20:34 exefiles$ -rw-rw-rw- 1 jerry 794 Mar 7 14:23 j$ -rw-r--r-- 1 root 100 Mar 5 18:24 toobig$
The cat -e option marks the ends of lines with a $. Notice that afile has a $ out past the end of the column. Aha . . . the filename ends with a space. Whitespace characters like TABs have the same problem, though the default ls -q (Section 8.12) option (on many Unix versions) shows them as ? if you're using a terminal.
$ ls -Q "afile " "exefiles" "j" "toobig"
% mv "afile " afile
The quotes (Section 27.12) tell the shell to include the space as part of the first argument it passes to mv. The same quoting works for other Unix commands as well, such as rm.
Copyright © 2003 O'Reilly & Associates. All rights reserved.