Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

My question is similar to this one, but I would like to exclude some directories recursively when copying/uploading files. Specifically I would like to exclude .git folders from the whole codebase I'm uploading (it contains subrepositories, some quite deep in the structure)

I can do it for the current directory with the "-" key and unselecting .git, but is there a way to do this recursively?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Midnight Commander doesn't have that sort of control over subdirectory operations. Kind of an 'all or none' type deal. Like you said, you can control the top level entries, but nothing more.

I suppose you could write some sort of script to be used in the F2 menu...

Another way, kinda of kludgy, but would work...

find . -type d -name ".git" -exec chmod 000 "{}" \;

Which would make all the .git subdirectories unreadable, MC would pop up an error dialog, tell it 'Continue' and keep processing.

Afterwards:

find . -type d -name ".git" -exec chmod 750 "{}" \;

to restore the desired permissions. (I use 750 & 640 myself, many prefer 755 & 644... use whatever you prefer in place of the '750' there)

Ha! and as a blending of my 'put it in the F2 menu' idea... you could put THOSE two commands in the F2 menu... making this almost (almost!) painless.


EDIT:

By request:

#
# Restore permissions for any .git subdirectories to 755
g   Restore .git directories to 755 permissions
    if [ "x$PWD" = "x$HOME" ]; then
        exit
    fi
    find . -type d -name ".git" -exec chmod 755 "{}" \; 2>/dev/null
#
# Remove permissions for any .git subdirectories
G   Hide .git directories with 000 permissions
    if [ "x$PWD" = "x$HOME" ]; then
        exit
    fi
    find . -type d -name ".git" -exec chmod 000 "{}" \; 2>/dev/null
#

Save this into file '~/.config/mc/menu'

If this file already exists, append it to the END (certain things must be first in the file, don't want to mess that up).

If this file did not exist, then the entries here will REPLACE all the default F2/User menu entries which were normally seen. If you need those menu entries back (some are handy!), then find the file named mc.menu (usually found in /etc/mc/), copy it to ~/.config/mc/menu, and again, append the above to the end. THE END!

If you're using an older version of mc, you may need to search for the mc.menu file, and the menu file needs to be in ~/.mc.menu ... complicated, yes, a bit. But recently, mc revised their config file locations to reflect best practices (XDG suggestions) and moved everything to ~/.config/mc/. The mc(1) man page is very helpful, search for user menu.

This adds two commands:

g (lowercase g)  which will RESTORE the 755 permissions for any .git subdirs
G (uppercase g)  which will REMOVE the permissions (set to 000) from any .git subdirs

I added a test to prevent performing this in your $HOME, although this isn't destructive... it just didn't sit well being able to do that there.

Enjoy!

share|improve this answer
    
Thanks, that could work! Could you please point me to some article about how to set up custom scripts for the F2 menu? –  Teo.sk Jul 1 '12 at 9:04
3  
give me moment and I'll add to the answer –  lornix Jul 1 '12 at 10:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.