I've been using, in equal amounts, Fedora and Ubuntu for well over a decade now, and there's one minor but irritating difference I noticed from their installs of midnight commander. When you change dirs inside it using Fedora, then exit, it has done the chdir for you but in Ubuntu it keeps it at the place you started. Googling threw up a solution for older Ubuntus here: http://ptspts.blogspot.co.uk/2010/01/how-to-make-midnight-commander-exit-to.html but trying that fails on 16. When I say fails, I mean the commands are accepted without complaint but it doesn't change mc's behaviour in Ubuntu.
7 Answers
The other responses are fine, but I feel like they are unsatisfying, here is my solution, which I think is the simplest:
Put this line into your ~/.profile
alias mc='source /usr/lib/mc/mc-wrapper.sh'

- 1,824
- 1
- 26
- 30

- 1,147
- 10
- 18
-
works, just restart putty after this operation, and all will work – jmp Nov 14 '18 at 19:56
-
Yes, I did not mention that. You can also put the same line in your current terminal as a normal bash command and it will start to work there too. – soger Nov 14 '18 at 23:07
-
3Thanks. Just want to note its not always work to put in ~/.profile. E.g. on ubuntu it can be ~/.bash_aliases – WowPress.host Nov 15 '18 at 13:43
-
1@Babblo Well, the developers of mc did everything they could with their mc-wrapper.sh script. It would be up to the creators of the various distros to actually use the wrapper but adding 3 lines to the skeleton would take away from their precious time to rewrite the boot sequence scripts for the 17th time. Yes, your comment is justified, we shouldn't have to deal with this. 15 years ago I had a Mandrake that did it but since then distros focus their efforts on making their GUI tackier with every release. – soger Nov 14 '19 at 13:46
-
Works folks on Ubuntu 18. – Adrian Goia Mar 31 '22 at 15:32
-
Just to note: after adding something to ~/.profile it usually worth to re-apply it to current bash (or other shell you like) session like: ````. ~/.profile```` or ````source ~/.profile```` Plese be careful - these commands re-applying ALL profile settings, not only string you've added. – Serj.by Sep 03 '22 at 15:09
Simple:
mcedit ~/.profile
Add this line at the end of file:
alias mc='source /usr/lib/mc/mc-wrapper.sh'
Type this command to execute changes
source ~/.profile
Then, to save both sides of mc
windows, click at the top of MC
Options -> Panel options -> Auto save panels setup

- 1,824
- 1
- 26
- 30

- 2,456
- 3
- 30
- 47
Create an executable with the following content:
MC_USER=`id | sed 's/[^(]*(//;s/).*//'`
MC_PWD_FILE="${TMPDIR-/tmp}/mc-$MC_USER/mc.pwd.$$"
/usr/bin/mc -P "$MC_PWD_FILE" "$@"
if test -r "$MC_PWD_FILE"; then
MC_PWD="`cat "$MC_PWD_FILE"`"
if test -n "$MC_PWD" && test -d "$MC_PWD"; then
cd "$MC_PWD"
fi
unset MC_PWD
fi
rm -f "$MC_PWD_FILE"
unset MC_PWD_FILE
Then define an alias pointing to that executable:
alias mc='. ~/.config/mc/exitcwd'
Don't forget to apply the alias:
source ~/.bashrc
-
2I'm not linux guru, but username is available in `USER` env variable, no need for `MC_USER=`, or? – Betlista Feb 11 '20 at 03:29
Here, in the article Use Midnight Commander like a pro, explains how to do it.
Basically, you have to create an alias for mc-wrapper.sh
.

- 45,055
- 107
- 359
- 626
For Ubuntu put this to .bashrc:
alias mc='. /usr/lib/mc/mc-wrapper.sh'
then:
source ~/.bashrc
(or relaunch the console)

- 1,160
- 10
- 12
While it's not exactly an answer to your question: just use ctrl+o to drop to the shell. It doesn't really quit mc, but that has the benefit that you can just hit ctrl+o again to go back where you were in mc.

- 1,286
- 1
- 9
- 5
-
1I hardly ever use the ctrl+o option because it creates a lot of confusion if you forget that you are already running mc or with programs using curses or what I always ended up doing, mc then ctrl+o then ssh some.server.com then ctrl+o and exit because I though I was running mc on the server but instead I lost the ssh connection. IMO it's cleaner if you exit mc when you don't need it. What I use ctrl+o instead is to read the screen after a program has run then I go back to mc immediately. – soger May 29 '19 at 17:16
-
1ctrl+o is very usefull for me, to address the problem (forgetting I'm using mc) I'm changing my PS1 in mc to prefix it with [mc] ;-) – Betlista Feb 11 '20 at 03:21
I want to add that this only works by existing with F10. If you exit by typing exit
the path will not be preserved.

- 590
- 6
- 16