[Tutor] ls *.py[co] >> .hidden

Bod Soutar bodsda at googlemail.com
Thu May 21 16:54:20 CEST 2015


On 21 May 2015 at 15:39, Steven D'Aprano <steve at pearwood.info> wrote:
> On Thu, May 21, 2015 at 12:55:13PM +0000, Albert-Jan Roskam via Tutor wrote:
>> 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  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor

ls *.pyc *.pso >> .hidden

should work

root at localhost:~# mkdir hide_test
root at localhost:~# cd hide_test/
root at localhost:~/hide_test# touch a.pyc b.pyc c.pyo d.py e.txt
root at localhost:~/hide_test# ls
a.pyc  b.pyc  c.pyo  d.py  e.txt
root at localhost:~/hide_test# ls *.pyc *.pyo >> .hidden
root at localhost:~/hide_test# cat .hidden
a.pyc
b.pyc
c.pyo
root at 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


More information about the Tutor mailing list