Bash is one of the best shell available in Linuix and Unix OS. This is due to it’s capabilities such as
We already discussed about history and shortcuts in some older posts. Today we will see how we can use BASH Shell to do auto complete and file wild-cards.
When we are at prompt we can press press TAB to autocomplete commands, chang directories, removing files/directories etc. We will see these as examples below for better understanding.
Example1: Execute lsdiff command to see if any files are modified by using auto complete without executing entire command.
Below commands are displayed to see which commands starts with ls
ls lsb_release lshw lsof lspgpot
lsattr lscpu lsinitramfs lspci lss16toppm
lsblk lsdiff lsmod lspcmcia lsusb
Now if you type d then press <tab> it will complete the lsdiff command as shown below because there is no other command which start with lsd name.
Example2: Directory structure autocompletion. Suppose I want to open smb.conf which is located in /etc/samba folder we can open this by just typing /et<tab>/sa<tab>/sm<tab> to open /etc/samba/smb.conf file.
Example3: Bash support wildcards. Delete all the files which are .sh file extension by using *.
rm -rf *.sh
Example4: I want to list all the files which starts with file and ends with .txt and having one character in between them.
ls -l file?.txt
This command will list all the files such as file1.txt, filea.txt, filez.txt etc.
Example5: List all the files which ends with a or b or c and start with file.
ls -l file[abc]
This will list filea, fileb and filec
Example6: List all the files which end with a to z, how can I do that?
ls -l file[a-z]
lists the files from filea, fileb to filec.
Latest posts by Surendra Anne (see all)
- Docker: How to copy files to/from docker container - June 30, 2020
- Anisble: ERROR! unexpected parameter type in action:
Fix- June 29, 2020
- FREE: JOIN OUR DEVOPS TELEGRAM GROUPS - August 2, 2019
- Review: Whizlabs Practice Tests for AWS Certified Solutions Architect Professional (CSAP) - August 27, 2018
- How to use ohai/chef-shell to get node attributes - July 19, 2018