Discussion:
[Tutor] ls *.py[co] >> .hidden
Steven D'Aprano
2015-05-21 14:39:32 UTC
Permalink
Hi,
I would like to hide .pyc and .pyo files because they are visually
distracting. Is the aforementioned command the best way? [1].
It isn't clear what you mean by "hide them".

If you mean that you want to use the ls command to get a directory
listing, but just not see the .pyc files, then all you need is:

ls *.py

which will list the .py files and nothing else.

You can remove the .pyc and .pyo files, or move them elsewhere:

rm *.py[co]

mv *.py[co] some/other/directory/

and let Python recreate them as needed.

If you're using a GUI file manager, there may be an option to hide
certain files. I know that KDE 3, at least, hides files starting with a
leading dot, and backup files ending with ~ so it's quite likely that
there's a way to hide .pyc and .pyo files. Check the documentation for
your GUI file manager.

The command you give:

ls *.py[co] >> .hidden

doesn't hide anything. It lists the .pyc and .pyo files, but rather than
printing to the terminal, it appends them to a file called .hidden in
the current directory.

Ah, wait, I see! Nautilus uses the .hidden file to suppress the display
of those files.

I wonder whether putting a single line:

.*py[co]

inside .hidden will work? You need to try it, or ask a Gnome expert.
--
Steve
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Bod Soutar
2015-05-21 14:54:20 UTC
Permalink
Post by Steven D'Aprano
Hi,
I would like to hide .pyc and .pyo files because they are visually
distracting. Is the aforementioned command the best way? [1].
It isn't clear what you mean by "hide them".
If you mean that you want to use the ls command to get a directory
ls *.py
which will list the .py files and nothing else.
rm *.py[co]
mv *.py[co] some/other/directory/
and let Python recreate them as needed.
If you're using a GUI file manager, there may be an option to hide
certain files. I know that KDE 3, at least, hides files starting with a
leading dot, and backup files ending with ~ so it's quite likely that
there's a way to hide .pyc and .pyo files. Check the documentation for
your GUI file manager.
ls *.py[co] >> .hidden
doesn't hide anything. It lists the .pyc and .pyo files, but rather than
printing to the terminal, it appends them to a file called .hidden in
the current directory.
Ah, wait, I see! Nautilus uses the .hidden file to suppress the display
of those files.
.*py[co]
inside .hidden will work? You need to try it, or ask a Gnome expert.
--
Steve
_______________________________________________
https://mail.python.org/mailman/listinfo/tutor
ls *.pyc *.pso >> .hidden

should work

***@localhost:~# mkdir hide_test
***@localhost:~# cd hide_test/
***@localhost:~/hide_test# touch a.pyc b.pyc c.pyo d.py e.txt
***@localhost:~/hide_test# ls
a.pyc b.pyc c.pyo d.py e.txt
***@localhost:~/hide_test# ls *.pyc *.pyo >> .hidden
***@localhost:~/hide_test# cat .hidden
a.pyc
b.pyc
c.pyo
***@localhost:~/hide_test#

As this adds specific results of ls you will need to schedule the
command through cron to get it to automatically add new files

-- Bodsda
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Steven D'Aprano
2015-05-21 16:11:12 UTC
Permalink
Post by Bod Soutar
ls *.pyc *.pso >> .hidden
should work
[...]
Post by Bod Soutar
As this adds specific results of ls you will need to schedule the
command through cron to get it to automatically add new files
Yes, but that's the point isn't it? If Nautilus understands regular
expressions, then instead of listing every single .pyc file by name,
potentially thousands of them, you just need a single entry:

.*pyc

to hide *every* .pyc file. Or use .*py[co] for .pyc and .pyo files.

If Nautilus *doesn't* understand regular expressions, well, that's just
another example of why Gnome is not good enough for serious work.

This suggests that Nautilus doesn't accept wildcards:

http://ubuntuforums.org/showthread.php?t=1730696
--
Steve
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Emile van Sebille
2015-05-21 16:57:47 UTC
Permalink
alias hidepycs="ls *.py[co] > .hidden"
Close -- try

alias ls='ls --hide=*.py[co]'

and when you want to see them use ls -a.

Emile



_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Danny Yoo
2015-05-21 23:05:06 UTC
Permalink
Post by Emile van Sebille
alias hidepycs="ls *.py[co] > .hidden"
Close -- try
alias ls='ls --hide=*.py[co]'
and when you want to see them use ls -a.
+1 to Emile's approach. This seems to be the right approach, using
the "--hide" option built into ls:

--hide=PATTERN
do not list implied entries matching shell PATTERN
(overridden by -a or -A)
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Alan Gauld
2015-05-21 23:44:13 UTC
Permalink
Post by Emile van Sebille
alias hidepycs="ls *.py[co] > .hidden"
Close -- try
alias ls='ls --hide=*.py[co]'
I thought we'd established that this was to
control visibility in the File Manager GUI
not the CLI? So an 'ls' flag isn't going to
help there.

Or am I missing something?
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Danny Yoo
2015-05-22 16:56:15 UTC
Permalink
Post by Alan Gauld
I thought we'd established that this was to
control visibility in the File Manager GUI
not the CLI? So an 'ls' flag isn't going to
help there.
Yes, it was about the visibility in Nautilius. Much easier on the eye when the bytecode files are not visible.
Ah, I was confused then. Sorry: I just saw the word "Debian" and that
activated my Unix reptile brain.
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Laura Creighton
2015-05-21 15:52:35 UTC
Permalink
Post by Bod Soutar
ls *.pyc *.pso >> .hidden
should work
a.pyc b.pyc c.pyo d.py e.txt
a.pyc
b.pyc
c.pyo
As this adds specific results of ls you will need to schedule the
command through cron to get it to automatically add new files
-- Bodsda
If you keep appending the results of ls to your .hidden file
it will grow to enormous size. (Cron will be happy to do that
for you. :) ) So, if all you care about
is the files you have _today_ then use > not >> so that the
file is recreated. If, on the other hand, you want your .hidden
to list files that you had at one time, don't happen to have now,
but want to have hidden if ever you should make them again, then
you need to periodically run the commands
sort -u .hidden >newhidden #or whatever you want to call it
mv newhidden .hidden

Laura
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Cameron Simpson
2015-05-22 03:42:37 UTC
Permalink
Post by Laura Creighton
If you keep appending the results of ls to your .hidden file
it will grow to enormous size. [...]
sort -u .hidden >newhidden #or whatever you want to call it
mv newhidden .hidden
Or:

sort -u -o .hidden .hidden

Cheers,
Cameron Simpson <***@zip.com.au>

[...] post-block actions should be allowed everywhere, not just on
subroutines. The ALWAYS keyword was agreed upon as a good way of doing
this, although POST was also suggested. This lead to the semi-inevitable
rehash of the try- catch exception handling debate. According to John
Porter, "There is no try, there is only do. :-)"
- from the perl6 development discussion
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Danny Yoo
2015-05-21 23:01:17 UTC
Permalink
Post by Bod Soutar
ls *.pyc *.pso >> .hidden
should work
[My response is completely off topic of Python; apologies.]

Hi Bod,

Be careful about running as 'root' for normal exploratory programming
or system usage. 'root' should be treated as an emergency-mode kind
of thing.
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Loading...