From time to time I want to change my display resolution, so I type these commands in terminal:

xrandr --newmode [newmodedetailsbs]
xrandr --addmode [display] [newmodeid]
xrandr --output [display] --mode [newmodeid]

I know what variables to use and they work perfectly, but it's a nuisance to retype them every time I want to change display modes. I'd prefer to create a simple script containing these commands but am having trouble finding basic information on scripting so that I can create the script. Can someone help?

1 Answer 1


The quick answer is put the commands that you type in a file, for example, chres, then, at the prompt, tell the shell to execute the commands like this:

$ sh chres

If you want to be able to execute the command from any directory, put the command into your personal bin directory ($HOME/bin) and make it executable (~ expands to the full path of your HOME directory:

$ mkdir -p ~/bin
$ mv chres ~/bin
$ chmod +x ~/bin/chres

Make sure $HOME/bin is in your PATH. This will usually be done in you ~.profile or ~.bashrc. Your ~/bin directory may be added to you PATH automatically if the directory exists. You can completely log out and log in again to find out if you need to modify your .profile. Type echo "$PATH" to find out.

  • Sorry, that was an oversight. I clicked the checkmark and the upvote caret, but don't have enough rep points for my vote-up to display yet.
    – Nobhdy
    Dec 2, 2015 at 3:11

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.