
You can protect yourself from the fact that you have no visual control of the line that you are going to execute if you have enabled in advance the shell options histverify with shopt -s histverify. That will execute the last command finished in your history. If your purpose is to build your commandline piece after piece, so you have done ls, after ls | grep google, and only after you checked your output you can execute it in a subshell $(.) with rm -i $(ls | grep google)Ī faster and more dangerous way, is to use !! ls | grep google The option -i (interactive) will prompt for the confirmation, a good habit when you delete files with the parameter expansion.Ī solution close to the philosophy of your attempt

That will select each filename with "google" in the middle that will finish for. deb) with "google" inside you can build your request with the wildcard * *google*.deb and do a simple rm -i *google*.deb The output of ls is not well-specified for the range of all possible filenames, so grepping it is innately unreliable.

Since you want to select all the packages (that finish with. By the way - I really do hope your use of ls in this manner is as an example.

It's better to use find, the tab expansion (start to write the name and press Tab), the file name expansion as *MyKey*. This for many reasons mainly related to unexpected and not usual characters allowed in the file name.Įven when you should expect that the filenames belonging to Linux packages will "behave well", this problem can nonetheless appears if other files are present in the same directory but you didn't know or notice. My suggestion is to avoid to parse the output of ls, even more if in conjunction with the del command.
