LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-17-2004, 02:21 PM   #1
t3___
Member
 
Registered: Sep 2003
Posts: 240

Rep: Reputation: 30
filenames with spaces - explain


can anyone explain how linux/unix systems handle filenames with spaces in them? does the underlying filesystem use some sort of mechanism (as windows did with longfilenames) to convert or represent them?

and on a related note... how can I CD (change directory) into a folder with a space?

Ive googled the subject for the last hour, and cant seem to find a clear, succinct explanation...
 
Old 02-17-2004, 02:23 PM   #2
esteeven
Senior Member
 
Registered: Oct 2001
Location: Bristol UK
Distribution: Arch Slackware Ubuntu
Posts: 1,082

Rep: Reputation: 52
You could try putting inverted commas around the whole filename.
 
Old 02-17-2004, 02:27 PM   #3
t3___
Member
 
Registered: Sep 2003
Posts: 240

Original Poster
Rep: Reputation: 30
"""EDIT - OH, i GET IT NOW... YOU WERE EXPLAINING HOW TO CD.... THANKS!""""


unfortunately I am trying to utilize the TOUCH command to timestamp files that are uploaded to my FTP sever, then have them deleted 48 hours later... a kind soul on this board created a script file that accomplished the timestamping successfully, but it does not work on files or folders with spaces...

I was hoping to understand how spaces are handled in Linux so that I could mend the anomaly myself...
 
Old 02-17-2004, 02:34 PM   #4
benjithegreat98
Senior Member
 
Registered: Dec 2003
Location: Shelbyville, TN, USA
Distribution: Fedora Core, CentOS
Posts: 1,019

Rep: Reputation: 45
cd long file or directory name

would actually be

cd long\ file\ or\ directory\ name

edit: and I think that *nix has always handled long filenames. Not positive, but I think that's the case.
 
Old 02-17-2004, 02:47 PM   #5
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
I think the length of the 'long' has, uh, lengthened, but yeah, I think that's right.

Basically, a space is just part of the default IFS and quoting the filename or escaping the space means 'I *really* mean a space' - it prevents the space being interpreted as a field separator.

If you 'touch foo bar baz' you create three files. If you have a file called 'foo bar baz' and 'touch foo bar baz', how's it supposed to know which you're talking about? By you telling it 'I mean to touch the file foo-space-bar-space-baz'.

-- Oh, and tab-completion goes right through spaces. If you only have the file 'foo bar baz', then 'touch f<tab>' will complete 'oo\ bar\ baz' for you.

Last edited by slakmagik; 02-17-2004 at 02:51 PM.
 
Old 02-17-2004, 02:59 PM   #6
Electro
LQ Guru
 
Registered: Jan 2002
Posts: 6,042

Rep: Reputation: Disabled
To keep the space format for a variable use double quotes. Single quotes is used to run commands. Double quotes keeps the text format.
 
Old 02-17-2004, 03:33 PM   #7
t3___
Member
 
Registered: Sep 2003
Posts: 240

Original Poster
Rep: Reputation: 30
thank everyone...

but Im trying to "affect" all files that land in the FTP directory... so its a wildcard situation... in other words, im not dealing witha particular file.

any way to acomplish this?
 
Old 02-17-2004, 03:58 PM   #8
SylvainP
LQ Newbie
 
Registered: Feb 2004
Distribution: Suse, Knoppix, Slackware
Posts: 27

Rep: Reputation: 15
Wildcards will work with spaces too, for example:

M*

will include "My Music"

or if you want all files beginning with "My "

M\ *

Maybe you can post the names of the files you're having trouble with?
 
Old 02-17-2004, 04:09 PM   #9
t3___
Member
 
Registered: Sep 2003
Posts: 240

Original Poster
Rep: Reputation: 30
Im sorry... i havent been completely clear...

see, what Im trying to do is ensure that our ftp server is used for quick get and put/transport operations only. we have instructed all users that any files or folder that are uploaded to the ftp directory will be automatically deleted after 48 hours.

so..... Im trying to get the TOUCH utility to timestamp ALL files that are uploaded - Im using a script file to accomplish that. therefore, Im not trying to target any specfic files, or type of files. ANY FILE THAT GETS UPLOADED SHOULD BE TIMESTAMPED.

When a file containing a space gets uploaded, TOUCH creates an empty "ghost" file for each word separated by spaces.... here is an example:

directory listing before script
~~~~~~~~~~~~~~~~~~~~~~

test word document.doc 2:49pm 12 kb

~~~~~~~~~~~~~~~~~~~~~~


and after the script runs at midnight

~~~~~~~~~~~~~~~~~~~~~~

test word document.doc 2:49pm 12 kb

test 12:00am 0 kb

word 12:00am 0 kb

document 12:00am 0 kb

~~~~~~~~~~~~~~~~~~~~~~





!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
here is the actual script file in case you want to peep it
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

code:--------------------------------------------------------------------------------

#!/bin/bash



ftpDir="/var/lib/ftp" #set this to your ftp directory

workingDir="/home/myhome" #set this to the directory to hold the temp files in

init()
{
for i in `ls $ftpDir`
do
touch $ftpDir/$i
done

ls $ftpDir > $workingDir/lastListing

}



update()
{
ls $ftpDir > $workingDir/currentListing



comm -1 -3 $workingDir/lastListing $workingDir/currentListing > $workingDir/differences

for i in `cat $workingDir/differences`
do
touch $ftpDir/$i
echo $i
done

mv $workingDir/currentListing $workingDir/lastListing

rm $workingDir/differences
}



case $1 in
init)
init
;;


update)
update
;;


*)

echo $"Usage: $0 init|update"

exit 1

esac

exit $?

Last edited by t3___; 02-17-2004 at 04:10 PM.
 
Old 02-17-2004, 04:15 PM   #10
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
You can use find to delete files based on age. In this example the mtime is created when the file is uploaded to the directory. So, in this example, I'm going to delete all files ending in gz and were uploaded over 90 days ago. Using the ( * ) makes it so you don't have to worry about the body part of the file name. Should work with spaces also.

#Delete old files with the following command
find /mnt/backup -type f -name '*.gz' -mtime +90 -exec rm {} \;
 
Old 02-17-2004, 04:22 PM   #11
SylvainP
LQ Newbie
 
Registered: Feb 2004
Distribution: Suse, Knoppix, Slackware
Posts: 27

Rep: Reputation: 15
Replace

touch $ftpDir/$i

with

touch "$ftpDir/$i"

That's what was meant by the previous poster that says to put double quotes around your variables.
 
Old 02-17-2004, 04:27 PM   #12
t3___
Member
 
Registered: Sep 2003
Posts: 240

Original Poster
Rep: Reputation: 30
what up homey

I do utilize a 2nd script that deletes the files after 48 hours using the find command with ctime 2 switch...

the problem is that when files are copied to the ftp directory from in house using samba (a shortcut for internal users... they use a driver letter instead of having to log into ftp) THE FILES RETAIN THIER ORIGINAL TIMESTAMP. If I just ran the find rm script to delete files older than 48 hrs, some files with older timestamps would be deleted immediately.
 
Old 02-17-2004, 04:34 PM   #13
t3___
Member
 
Registered: Sep 2003
Posts: 240

Original Poster
Rep: Reputation: 30
~~~~~~~~~~~~~~~~
Replace

touch $ftpDir/$i

with

touch "$ftpDir/$i"

That's what was meant by the previous poster that says to put double quotes around your variables.
~~~~~~~~~~~~~~~~~~

AH! My bad... I shoulda caught that one! THANKS SO MUCH!!!
 
Old 02-17-2004, 06:07 PM   #14
t3___
Member
 
Registered: Sep 2003
Posts: 240

Original Poster
Rep: Reputation: 30
~~~~~~~~~~~~~~~~~
Replace

touch $ftpDir/$i

with

touch "$ftpDir/$i"
~~~~~~~~~~~~~~~~~

hmmm.... that didnt work at all - it is still creating the ghosted files and is not touching the filenames or folders that contain spaces...

any other ideas?
 
Old 02-17-2004, 06:13 PM   #15
benjithegreat98
Senior Member
 
Registered: Dec 2003
Location: Shelbyville, TN, USA
Distribution: Fedora Core, CentOS
Posts: 1,019

Rep: Reputation: 45
How about this......

Just before you touch it, you check the file to see if it contains a space. If it does then you rename it to temp.tmp (or whatever), hold the old name in a variable, touch it, then rename it to it's original name. If there are no spaces, then touch it.

Does this sound like too much to anybody?

edit: in psuedocode that would be something like:
Code:
if file contains spaces then
    filevar = name of file
    rename file to temp.tmp
    touch temp.tmp
    rename temp.tmp to filevar
else
    touch file

Last edited by benjithegreat98; 02-17-2004 at 06:17 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
filenames with spaces antony.booth Programming 5 11-01-2005 04:49 AM
How to use foreach on filenames with spaces? BrianK Linux - General 3 08-09-2005 12:15 PM
ls and filenames with spaces rose_bud4201 Programming 10 07-01-2005 08:28 AM
Spaces in filenames with mpg123 Boffy Linux - Software 3 04-26-2004 02:51 PM
spaces in filenames ebone Linux - General 2 11-12-2001 11:56 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration