Spaces in filenames with BASH
hi all,
im trying to output a list of directories/files. however, directory/file names that contain spaces appear on multiple lines of the output. is there anyway i can have the name print to only one line? i got up to this point before reaching problems. ive tried a bunch of greps and seds but cant get further than this: Code:
for file in `dir -d *` ; do edenning |
Try using:
Code:
for file in *; do echo "$file"; done |
You can change the file separation character:
Code:
IFS=";" Code:
for file in "`dir -d *`" ; do Samsara |
thanks alot wapcaplet, that worked great :) not quite sure why i didnt think about that
|
if you just want directories
It's a lot simpler, just do: Code:
It's a shell expansion, so works for say, 'ls' too, list subdirs in /etc: Code:
:) |
Code:
[/home/soumen] $ time ls -d /tmp/*/ HTH. |
Hmm.
I think that depends a lot on what order you do it. The echo call will be globbing from cache memory. If you swap you get: e.g: Code:
but I wouldn't use ls -d in a for, I'd use: Code:
|
Yeah really interesting. This is even better:
Code:
SF1B : /supmis/soumen > for i in tmp/auth/*/*/ ; do Regards, Soumen |
Very interesting point.
e.g: Code:
billym.primadtpdev>for x in /usr/plopp/*/ ;do^Jecho x=$x^Jdone That will explain some funny file names on the system! fascinating. |
If you just want directories, try this find statement....
Code:
find /home/images -depth -type d -exec ls -d {} \; Code:
find /home/images -depth -name '*' -exec ls {} \; |
Isn't -depth taken by default?
|
Yeah, that's just a canned example I use and change a few things around for different situations. :)
|
we were just discussing the various quirks of
certain methods. |
All times are GMT -5. The time now is 07:19 AM. |