Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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...
"""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...
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.
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.
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
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
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 {} \;
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.