Is there any way to run a program without pressing enter?

I could then have a script that cd's one folder up. Then I could hold down ctrl and every time i would hit a button, that script would run.

That could make life easier in the shell as I could go up the folder structure faster. And could even clear the screen each time and run ls. Or do whatever with just a single click of a button, while in the shell.

I'm using bash and my terminal emulator is Linux Mint, Xfce's default.


You can do this using bash's .inputrc file, the readline startup configuration file. First, edit the file ~/.inputrc (this means a file named .inputrc in your $HOME directory; create it if it doesn't exist) and add this line:

Control-u: "cd ../\n"

That sets the keyboard shortcut Ctrl+u to insert cd ../ followed by a newline (enter). Now, open a new terminal and you can use Ctrl+u to move one directory up. So yes, you can hold down Ctrl and then move one directory up every time you press u.

  • 1
    Custom things you put in .inputrc are also available in other programs that use readline for interactive use, such as rlwrap. Oct 7 at 17:37
  • @glennjackman that seems like a good thing, right? Or do you mean it can cause conflicts or something?
    – terdon
    Oct 7 at 19:50
  • No it's a plus. The only things I have in my .inputrc are set editing-mode vi and set show-mode-in-prompt on Oct 7 at 21:17
  • 11
    I don't think it is a plus, because in other utilities that use Readline (and thus .inputrc) cd .. makes no sense. To work around that, you could put bind 'Control-u:"cd ..\n"' in .bashrc, so it only affects Bash. Nice answer nonetheless.
    – Quasímodo
    Oct 8 at 12:16

If you don't have a specific task that you want to automate, but you want to speed up some command right now by executing it with a single keypress, why not simply use copy-paste:

  1. Type the command you want to repeat, and type <enter>.
  2. Highlight the command to the end of the line (including the newline at the end), and copy the selection to the clipboard.
  3. Type control-V to paste and execute the copied command. Repeat.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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