The Command Line - Less to Remember

The Command Line - Less to Remember

The Linux command line can be quite complex at times. Many commands, options, switches to remember. For example, listing only the first 3 files, with their details:

$ ls -l
-rwxrwxrwx 1 mio mio  18824 Sep  5 17:43 apt
-rwxrwxrwx 1 mio mio 704984 Aug 17  2023 gawk
-rwxrwxrwx 1 mio mio 146088 Jun 26  2024 sftp        

What if I want it sorted by name in reverse?

$ ls -lr
-rwxrwxrwx 1 mio mio 146088 Jun 26  2024 sftp
-rwxrwxrwx 1 mio mio 704984 Aug 17  2023 gawk
-rwxrwxrwx 1 mio mio  18824 Sep  5 17:43 apt        

But only those with a name containing the letter "t", again sorted by name in reverse. This becomes a bit more complicated:

$ find . -name "*t*" -print0 | xargs -0 ls -lr
-rwxrwxrwx 1 mio mio 146088 Jun 26  2024 ./sftp
-rwxrwxrwx 1 mio mio  18824 Sep  5 17:43 ./apt        

AI To The Rescue

If you don't remember the switch to sort by name in reverse, you can use a LLM instead:

$ ls -l | llm "sorted by name in reverse"
Based on the details provided, you want the files sorted by their names in reverse order. Here is the sorted list:
-rwxrwxrwx 1 mio mio 146088 Jun 26  2024 sftp
-rwxrwxrwx 1 mio mio 704984 Aug 17  2023 gawk
-rwxrwxrwx 1 mio mio  18824 Sep  5 17:43 apt        

And the complicated command:

$ ls -l | llm "keeping only the files with the letter 't' in the name, sorted by name in reverse"
You need to keep only the files with 't' in their names and sort them in reverse order by name:
1. Files with the letter 't':
   - apt
   - sftp
2. Now, sort these file names in reverse order:
   - sftp
   - apt
So, your sorted list of files meeting the criteria would be:
-rwxrwxrwx 1 mio mio 146088 Jun 26  2024 sftp
-rwxrwxrwx 1 mio mio  18824 Sep  5 17:43 apt        

Now, all that is left is to cleanup the "helpful insights" the model left behind in the answer.


Would I use this? Probably not on a daily basis, but it looks promising.

Will we forget about the command line in a couple of years? Probably not, since it provides one of the most reliable and consistently repeatable ways of doing tasks on a computer.

I used https://github.com/simonw/llm. There are other similar programs, but this looked like the best to me at this time.


要查看或添加评论,请登录

Mihai-Gabriel Ionita的更多文章

  • GitOps Style

    GitOps Style

    What Is It? According to https://about.gitlab.

  • AEO: the New SEO or Does Not Matter

    AEO: the New SEO or Does Not Matter

    What I asked this question: I got (from gpt-4): and (from gpt-4o): How I wanted to see where this is coming from, so I…

  • Sharing Your Development Environment

    Sharing Your Development Environment

    Getting a colleague up-to-speed on what you are doing is not only about explaining what you have done so far and where…

  • Testing the AI Challenge

    Testing the AI Challenge

    Until such time when human conversational languages become the new programming languages, we find ourselves on an…

社区洞察

其他会员也浏览了