Re: OT: unix newbie questions
Le Mardi 06 Juin 2006 08:36, Fredrik Lundh a écrit : > > *26. You observed that some of your group members are fiddling with your > > file "myfile" and you wanted to remove the read permission to your > > group. How do you do? (1) > > >>> os.chmod("myfile.txt", 0404) rather, >>> os.chmod("myfile.txt", 0400) I guess. or maybe you want something like this : import os, stat os.chmod("myfile.txt", os.stat("myfile.txt").st_mode - stat.S_IRGRP) -- _ Maric Michaud _ Aristote - www.aristote.info 3 place des tapis 69004 Lyon Tel: +33 426 880 097 -- http://mail.python.org/mailman/listinfo/python-list
Re: OT: unix newbie questions
Fredrik Lundh wrote: >> *24. Display recent 10 java files, (with *.java extension) , in >> descending order by time, latest to oldest time. (1) * > > >>> files = sorted(glob.glob("*.py"), key=os.path.getmtime)[-10:] > >>> files.reverse() (to display the files, use print) -- http://mail.python.org/mailman/listinfo/python-list
Re: OT: unix newbie questions
Carlos Lopez wrote: > Please help i am losing my mind ... UNIX Newbee > > *23. How do you add a line to the end of an existing file "myfile" with > date stamp. (1) * >>> f = open("myfile", "a+") >>> f.write(datestamp) >>> f.close() > *24. Display recent 10 java files, (with *.java extension) , in > descending order by time, latest to oldest time. (1) * >>> files = sorted(glob.glob("*.py"), key=os.path.getmtime)[-10:] >>> files.reverse() > *25. How do you set only read permissions to user, group and others in > octal mode for a file "myfile.txt" ? (2) >>> os.chmod("myfile.txt", 0444) # note the leading zero > *26. You observed that some of your group members are fiddling with your > file "myfile" and you wanted to remove the read permission to your > group. How do you do? (1) >>> os.chmod("myfile.txt", 0404) > *28. Here is another long listing of a file. (1)* > -rw-r- 1 Y435678 odms 20 Sep 02 17:03 file.txt. *** > > *What are the owner permissions? * >>> s = os.stat("urllib.py").st_mode >>> if s & stat.S_IREAD: print "READ" >>> if s & stat.S_IWRITE: print "WRITE" >>> if s & stat.S_IEXEC: print "EXEC" > *29. The file “users_data” has the following contents : (1) > Tom Smith 7.00 15 105.00 > Rob Sheryl 8.00 20 160.00 > Ken Bradman 7.00 13 91.00 > Peter Smith 6.00 15 90.00 > Dennis Smith 8.00 13 104.00 > Tom Dave9.00 12 108.00 * > > *How do you sort the above file and redirect the output to another file > called “sortedusers” * >>> out = open("sortedusers", "w") >>> out.writelines(sorted(open("users_data"))) > *20. What is the command to list files in a directory : (2) >>> os.listdir(directory) or, if you want full path names and glob-style filtering: >>> glob.glob(os.path.join(directory, "*")) -- http://mail.python.org/mailman/listinfo/python-list
Re: OT: unix newbie questions
Another option is zsh, which is very much like bash, but better ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: OT: unix newbie questions
In article <[EMAIL PROTECTED]>, "Gerard Flanagan" <[EMAIL PROTECTED]> wrote: >* To create an empty __init__.py file I do 'vim __init__.py' then >immediately exit vim, is there a shell or vim command which will create >an empty file without opening the editor? man touch >* If I want to do : > >mv mypackage-1.0.2.tar.gz subdir/mypackage-1.0.2.tar.gz > > then tab-completion gives me the first occurrence of the file, but I >have to type the second occurrence - is there a way of not having to >type it? This is not how bash works. bash lists all the possible completions. >* cd ~ brings me to my home directory, is there a means by which I can >set up a similar alias for, say, /usr/local/www, so I can do: eg. cd ^ >to get to that directory? You could set up a variable, e.g. in bash export w=/usr/local/www then cd $w >* I'm using the tcsh shell and have no problems with it, but bash seems >more popular - any reason to change? (I don't intend writing many shell >scripts) Last time I used tcsh, its autocorrection facility kept making wrong suggestions. I just don't think it's worth using any more. Stick to bash for all your shell needs, both interactive and scripting, and leave it at that. >* Any other unix/vim tips for a 'nix newb?! Try emacs. -- http://mail.python.org/mailman/listinfo/python-list
Re: OT: unix newbie questions
On Sat, Mar 25, 2006 at 03:45:56AM -0800, Gerard Flanagan wrote: [...] > * If I want to do : > > mv mypackage-1.0.2.tar.gz subdir/mypackage-1.0.2.tar.gz > > then tab-completion gives me the first occurrence of the file, but I > have to type the second occurrence - is there a way of not having to > type it? In this specific case you don't need second filename. mv mypackage-1.0.2.tar.gz subdir/ is enough. If you need filename for some reason, use this. mv mypackage-1.0.2.tar.gz subdir/mypackage-1.0.2.tar.gz.backup => mv mypackage-1.0.2.tar.gz subdir/!#:1.backup This works for both bash and (t)csh. --Inyeol -- http://mail.python.org/mailman/listinfo/python-list
Re: OT: unix newbie questions
> * I'm using the tcsh shell and have no problems with it, but bash seems > more popular - any reason to change? (I don't intend writing many shell > scripts) You can do this in bash: $ python myprog > stdout.txt 2> stderr.txt and have output to sys.stdout and sys.stderr go in separate files. Quite handy for separating output and debugging comments. I believe that this is impossible in tcsh (where you only can do $ python myprog &> stdout_and_stderr.txt to catch stdout and stderr at the same time). Also: bash_completions. It keeps track of arguments and options for commonly used programs and commands. If you type "cd " and hit tab for completions you will only see directories, since bash_completions knows that this is all cd accepts. Don't know if tcsh has anything similar. Cheers, Joel Hedlund -- http://mail.python.org/mailman/listinfo/python-list
Re: OT: unix newbie questions
> * If I want to do : > > mv mypackage-1.0.2.tar.gz subdir/mypackage-1.0.2.tar.gz > > then tab-completion gives me the first occurrence of the file, but I > have to type the second occurrence - is there a way of not having to > type it? No need to give it the name the second time. # touch foo # mkdir d # mv foo d # ls d foo # Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: OT: unix newbie questions
Gerard Flanagan: >* To create an empty __init__.py file I do 'vim __init__.py' then >immediately exit vim, is there a shell or vim command which will create >an empty file without opening the editor? touch __init__.py >* cd ~ brings me to my home directory, is there a means by which I can >set up a similar alias for, say, /usr/local/www, so I can do: eg. cd ^ >to get to that directory? You could create an alias in your shell. -- René Pijlman Wat wil jij leren? http://www.leren.nl -- http://mail.python.org/mailman/listinfo/python-list