I run into this scenario a lot:
I'm in a big directory, and I am looking for a specific file that I forgot the exact name of, so I type
ls
to see all files in there.I see the file that I want
I need to pass this file to the command-line as an argument. The file name is complex.
What I currently do is just highlight the ls
output using the cursor/mouse, right click, and hit copy then paste it to my commandline prompt. I'd rather avoid this if there is a better way. I am aware of tab autocompletion, but sometimes its a situation where there are e.g. abcd abce abcf abcg abcz23 type of files, so the tab completion can be a bit unwieldy, unless you also have some advice there. Even if for example, I was able to copy the output of ls
to the clipboard, I would need some way to narrow it down to my desired file so as to not copy other filenames to the clipboard also.
$(...)
in order to keep the result as a single word. You also don't needls | grep tar
when you can just use a glob such asls *tar*
. And then you can just dispense with the subshell entirely, somain_command_to_run *name_of_file*
ortar -xvzf *.tar*
– Chris Davies Nov 24 '20 at 17:01glob
anyway. I'll add that on as an edit, if that's fine by you. – Bongotz Nov 26 '20 at 16:47ls
then? I realised that you have a point in that the output ofls
can be tricky to deal with – Bongotz Nov 26 '20 at 17:22