Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Shell Scripting
  • Kali Linux
  • Ubuntu
  • Red Hat
  • CentOS
  • Docker in Linux
  • Kubernetes in Linux
  • Linux interview question
  • Python
  • R
  • Java
  • C
  • C++
  • JavaScript
  • DSA
Open In App

bind command in Linux with Examples

Last Updated : 01 Oct, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

bind command is a Bash shell builtin command. It is used to set Readline key bindings and variables. The keybindings are the keyboard actions that are bound to a function. So it can be used to change how the bash will react to keys or combinations of keys, being pressed on the keyboard.

Here, we’ll explore how to use the bind command effectively, its syntax, key options, and practical examples to enhance your workflow in Bash.

Syntax

bind [-lpsvPSVX] [-m keymap] [-q name] [-f filename] [-u name] [-r keyseq]      [-x keyseq:shell-command] [keyseq:readline-function or readline-command]

where,

  • keyseq: This refers to the key sequence or combination of keys that you want to bind to a specific function or command.
  • readline-function: These are functions provided by the Readline library, like moving the cursor, deleting characters, or cutting and pasting text.
  • shell-command: You can bind key sequences to execute shell commands when pressed.

Key Options for the bind Command

OptionDescriptionExample
-m keymapUses the specified keymap for the current command sequence. Acceptable keymaps: emacs, emacs-standard, emacs-meta, emacs-ctlx, vi, vi-move, vi-command, vi-insert.bind -m vi
-lLists all available Readline function names.bind -l
-PLists all function names along with their bindings.bind -P
-pLists functions and bindings in a reusable format as input.bind -p
-SLists key sequences that invoke macros and their values.bind -S
-sLists key sequences that invoke macros and their values in a reusable format as input.bind -s
-VLists all Readline variable names and their values.bind -V
-vLists Readline variables in a reusable format as input.bind -v
-q function-nameQueries which keys invoke the specified function.bind -q yank
-u function-nameUnbinds all keys bound to the specified function.bind -u yank
-r keyseqRemoves the binding for the specified key sequence.bind -r "\C-y"
-f filenameReads key bindings from the specified file.bind -f bindfile
-x keyseq:shell-commandExecutes the shell command when the specified key sequence is entered.bind -x '"\C-l":ls'
-XLists key sequences bound with -x and associated commands in a reusable format.bind -X

Practical Examples of the bind Command

1. -m:

It use KEYMAP as the keymap for the duration of this command. Here we are using vi keymapping in bash, which allows us to manipulate text on the command line as you would in vi.

bind -m vi
-m

2. -l:

List all the readline function names. There are around 150 functions that are available by default in this list.

bind -l
-l

3. -p:

It will display both the keybindings and the corresponding function names.

bind -p
-p

4. -P:

It will list of all functions along with the bindings where they appear. It is a little bit easier to read when liked to view all the keybindings for a particular function name.

bind -P
-P

5. -f:

It read key bindings from FILENAME. First of all, create a file containing keybindings.

cat > bind

and then write the keybinding in it for example "\C-i": yank. Now to load keybindings from FILENAME.

bind -f bind bind -p | grep yank 
-f

6. -q:

It is used to view keybindings only for a specific function.

bind -q yank
 -q

7. -r:

Remove all bindings for the particular key sequence.

bind -r "\C-y"
-r

8. -u:

It also unbinds a keybinding. It will remove the key combinations that is assigned to a particular function.

bind -u yank
-u

9. -v:

It is used to view all the readline variables.

bind -v
-v


Note: To check the help page of bind command, use the following command:

bind --help
bind --help

Conclusion

The bind command in Bash is an extremely versatile tool for customizing your command-line experience. By mastering keybindings, you can increase your productivity and make your terminal work the way you want it to.


M

Mandeep_Sheoran
Improve
Article Tags :
  • Linux-Unix
  • linux-command
  • Linux-misc-commands

Similar Reads

    atrm command in Linux with examples
    atrm command is used to remove the specified jobs. To remove a job, its job number is passed in the command. A user can only delete jobs that belong to him. Only superuser can delete any job even if that belongs to another user. Syntax: atrm [-V] job [job...] Options: -V : Used to print the version
    1 min read
    atq command in linux with examples
    atq displays the list of pending jobs which are scheduled by the user. If the user is the superuser then the pending jobs of all the users will be displayed. The output lines display Job number, date, hour, queue, and username for each job. Syntax: atq [-V] [-q queue] Options: -V: It will display th
    2 min read
    autoconf command in Linux with examples
    autoconf command is used in Linux to generate configuration scripts. Generate a configuration script from a TEMPLATE-FILE if given, or from ‘configure.ac’ if present, or 'configure.in'. The output is sent to the standard output if TEMPLATE-FILE is given, otherwise, it is sent into ‘configure’. To us
    1 min read
    autoheader command in Linux with Examples
    autoheader command in Linux is used to create a template file of C “#define” or any other template header for configure to use. If the user will give autoheader an argument, it reads the standard input instead of reading configure.ac and also writes the header file to the standard output. This comma
    3 min read
    automake command in Linux with Examples
    automake is a tool used for automatically generating Makefile.in files compliant with the set GNU Coding Standards. autoconf is required for the use of automake. automake manual can either be read on-line or downloaded in the PDF format. More formats are also offered for download or on-line reading.
    1 min read
    autoreconf command in Linux with examples
    autoreconf is a Autotool which is used to create automatically buildable source code for Unix-like systems. Autotool is a common name for autoconf, automake, etc. These all together are termed as Autotools. Important Points: Provides Portability of source code packages by automatic buildable capabil
    2 min read
    AWK command in Unix/Linux with examples
    Awk is a scripting language used for manipulating data and generating reports. The awk command programming language requires no compiling and allows the user to use variables, numeric functions, string functions, and logical operators. Awk is a utility that enables a programmer to write tiny but eff
    8 min read
    banner command in Linux with examples
    The 'banner' command in Linux is a simple yet powerful utility used to display text in large ASCII characters on the terminal. This command can be particularly useful for creating prominent messages or headings within scripts and outputs.Syntax of the 'banner' Commandbanner textbanner 'Command' Exam
    3 min read
    basename Command in Linux with examples
    The 'basename' command in Linux is a fundamental utility used in file manipulation and script writing. It simplifies file paths by stripping directory information and optional suffixes from file names. Here a detailed overview of the 'basename' command, including its syntax, options, and practical u
    3 min read
    batch command in Linux with Examples
    batch command is used to read commands from standard input or a specified file and execute them when system load levels permit i.e. when the load average drops below 1.5. Syntax: batch It is important to note that batch does not accepts any parameters. Other Similar Commands: atq: Used to display th
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences