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... |
You could try putting inverted commas around the whole filename.
|
"""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... |
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. |
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. |
To keep the space format for a variable use double quotes. Single quotes is used to run commands. Double quotes keeps the text format.
|
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? |
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? |
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 $? |
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 {} \; |
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. |
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. |
~~~~~~~~~~~~~~~~
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!!! |
~~~~~~~~~~~~~~~~~
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? |
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 |
All times are GMT -5. The time now is 11:52 AM. |