Beehaw
  • Communities
  • Create Post
  • search
    Search
  • Login
  • Sign Up
cybercitizen4 ( cybercitizen4@lemm.ee )  to Asklemmy@lemmy.ml · 2 years ago

What's a handy terminal command you use often?

message-square
message-square
116
link
fedilink
136
message-square

What's a handy terminal command you use often?

cybercitizen4 ( cybercitizen4@lemm.ee )  to Asklemmy@lemmy.ml · 2 years ago
message-square
116
link
fedilink
alert-triangle
You must log in or # to comment.
  • papertowels ( papertowels@lemmy.one ) 
    link
    fedilink
    arrow-up
    39
    ·
    2 years ago

    sudo !! to rerun last command as sudo.

    history can be paired with !5 to run the fifth command listed in history.

    • communism ( communism@lemmy.ml ) 
      link
      fedilink
      arrow-up
      3
      ·
      2 years ago

      Fifth as in fifth most recent command or fifth oldest?

      • papertowels ( papertowels@lemmy.one ) 
        link
        fedilink
        arrow-up
        4
        ·
        2 years ago

        I believe it’s the fifth oldest - I think !-5 will get you the fifth impost recent, but I was shown that and haven’t put it into practice.

        The most common usecase I do is something like history | grep docker to find docker commands I’ve ran, then use ! followed by the number associated with the command I want to run in history.

  • pemptago ( pemptago@lemmy.ml ) 
    link
    fedilink
    English
    arrow-up
    23
    ·
    2 years ago

    I went a little overboard and wrote a one-liner to accurately answer this question

    history|cut -d " " -f 5|sort|uniq -c|sort -nr|head -5
    

    Note: history displays like this for me 20622 2023-02-18 16:41:23 ls I don’t know if that’s because I set HISTTIMEFORMAT='%F %T ' in .bashrc, or if it’s like that for everyone. If it’s different for you change -f 5 to target the command. Use -f 5-7 to include flags and arguments.

    My top 5 (since last install)

       2002 ls
       1296 cd
        455 hx
        427 g
        316 find
    

    g is an alias for gitui. When I include flags and arguments most of the top commands are aliases, often shortcuts to a project directory.

    Not to ramble, but after doing this I figured I should alias the longest, most-used commands (even aliasing ls to l could have saved 2002 keystrokes :P) So I wrote another one-liner to check for available single characters to alias with:

    for c in a b c d e f g h i j k l m n o p q r s t u v w x y z; do [[ ! $(command -v $c) ]] && echo $c; done
    

    In .bash_aliases I’ve added alias b='hx ${HOME}/.bash_aliases' to quickly edit aliases and alias r='source ${HOME}/.bashrc' to reload them.

    • BaumGeist ( BaumGeist@lemmy.ml ) 
      link
      fedilink
      arrow-up
      1
      ·
      2 years ago

      deleted by creator

    • JackbyDev ( JackbyDev@programming.dev ) 
      link
      fedilink
      English
      arrow-up
      1
      ·
      2 years ago

      history -i

  • notfromhere ( notfromhere@lemmy.ml ) 
    link
    fedilink
    arrow-up
    23
    ·
    2 years ago

    Since nobody has said yet, I use screen pretty heavily. Want to run a long running task, starting it from your phone? Run screen to create a detachable session then the long running command. You can then safely close out of your terminal or detach with ctrl a, d and continue in your terminal doing something else. screen -r to get back to it.

    • gitamar ( gitamar@feddit.org ) 
      link
      fedilink
      Deutsch
      arrow-up
      6
      ·
      2 years ago

      I recently switched to tmux and boy, it’s way better. I basically use only tmux now anymore. Creating panes to have two processes in one glance, multiple windows, awesome. Plus all the benefits of screen.

      • 7dev7random7 ( 7dev7random7@suppo.fi ) 
        link
        fedilink
        arrow-up
        1
        ·
        2 years ago

        Maybe someone reading wants to now about prefix+s. This doubles your excitement.

      • krash ( krash@lemmy.ml ) 
        link
        fedilink
        arrow-up
        1
        ·
        2 years ago

        Try zellij. Not as popular as tmux, but very intuitive to use.

    • papertowels ( papertowels@lemmy.one ) 
      link
      fedilink
      arrow-up
      6
      ·
      2 years ago

      In a similar vein, nohup lets you send tasks to the background and seems to be everywhere.

    • tetris11 ( tetris11@lemmy.ml ) 
      link
      fedilink
      arrow-up
      3
      ·
      2 years ago

      Also, screen can connect to an UART device or serial or anything that offers up a TTY

    • verdare [he/him] ( verdare@beehaw.org ) 
      link
      fedilink
      arrow-up
      3
      ·
      2 years ago

      Don’t use screen, but I do use tmux pretty heavily.

    • muzzle ( muzzle@lemm.ee ) 
      link
      fedilink
      arrow-up
      2
      ·
      2 years ago

      I Always forget to run screen first, so I just rely heavily on dtach

      • 7dev7random7 ( 7dev7random7@suppo.fi ) 
        link
        fedilink
        arrow-up
        1
        ·
        2 years ago

        Simply change your terminal command to execute the terminal multiplexer of your choice.

        man terminal_of_choice, look for (start) command.

        • muzzle ( muzzle@lemm.ee ) 
          link
          fedilink
          arrow-up
          1
          ·
          2 years ago

          No thanks, I’m good

    • krash ( krash@lemmy.ml ) 
      link
      fedilink
      arrow-up
      1
      ·
      2 years ago

      How does screen / tmux work when detached from a session, how does it keep the session alive (both when running locally, and while ssh:ing to a server)? Is there a daemon involved?

      • darvit ( darvit@lemmy.darvit.nl ) 
        link
        fedilink
        arrow-up
        1
        ·
        2 years ago

        You can find out by running screen and executing pstree, that way you can see how the screen process is run.

  • BougieBirdie ( Bougie_Birdie@lemmy.blahaj.zone ) 
    link
    fedilink
    English
    arrow-up
    22
    ·
    2 years ago

    Not a specific command, but I learned recently you can just dump any executable script into ~/bin and run it from the terminal.

    I suffer greatly from analysis paralysis, I have a very hard time making decisions especially if there’s many options. So I wrote a script that reads a text file full of tasks and just picks one. It took me like ten minutes to write and now I spend far more time doing stuff instead of doing nothing and feeling badly that I can’t decide what to do.

    • unknowing8343 ( unknowing8343@discuss.tchncs.de ) 
      link
      fedilink
      arrow-up
      16
      ·
      2 years ago

      I think the standard is ~/.local/bin, for the people that like standards.

    • potentiallynotfelix ( potentiallynotfelix@lemmy.fish ) 
      link
      fedilink
      English
      arrow-up
      2
      ·
      2 years ago

      or add it to path

  • ☂️- ( umbrella@lemmy.ml ) 
    link
    fedilink
    arrow-up
    20
    ·
    edit-2
    1 year ago

    deleted by creator

    • secret300 ( secret300@lemmy.sdf.org ) 
      link
      fedilink
      arrow-up
      1
      ·
      2 years ago

      I use this constantly

  • sgtnasty ( sgtnasty@lemmy.ml ) 
    link
    fedilink
    arrow-up
    15
    ·
    2 years ago

    pv (Pipe Viewer) is a command line tool to view verbose information about data streamed/piped through it. The data can be of any source like files, block devices, network streams etc. It shows the amount of data passed through, time running, progress bar, percentage and the estimated completion time.

  • Revan343 ( Revan343@lemmy.ca ) 
    link
    fedilink
    arrow-up
    14
    ·
    2 years ago

    Uhhh…sudo su

    Don’t be like me

    • vrighter ( vrighter@discuss.tchncs.de ) 
      link
      fedilink
      arrow-up
      6
      ·
      2 years ago

      sudo -i

  • HeartyOfGlass ( HeartyOfGlass@lemm.ee ) 
    link
    fedilink
    English
    arrow-up
    14
    ·
    2 years ago

    clear. Constantly, and for no reason.

    • igorette ( igorette@lemmy.ml ) 
      link
      fedilink
      arrow-up
      21
      ·
      2 years ago

      Ctrl-L

      • HeartyOfGlass ( HeartyOfGlass@lemm.ee ) 
        link
        fedilink
        English
        arrow-up
        15
        ·
        2 years ago

        Oh. I know. But you don’t understand - I’m compelled to type it out. I must.

    • Pup Biru ( pupbiru@aussie.zone ) 
      link
      fedilink
      English
      arrow-up
      1
      ·
      2 years ago

      i’d like to introduce you to your new best friend: reset… it doesn’t everything clear does and a LOT more

    • carg ( omxxi@feddit.org ) 
      link
      fedilink
      English
      arrow-up
      1
      ·
      2 years ago

      haha, I can relate to that :). formerly I had the compulsion to execute sync frequently. Now my compulsion is to push Ctrl-C like 4 times every time I need it. I read somewhere that’s common because of ^C has a lack of feedback to the user, so, a script showing an alert that the clipboard received some information helped with this compulsion.

  • sp451 ( sp451@lemmy.sdf.org ) 
    link
    fedilink
    arrow-up
    13
    ·
    2 years ago

    sudo rm -rf /

    Very powerful yet helpful command :-)

    • makingStuffForFun ( makingStuffForFun@lemmy.ml ) 
      link
      fedilink
      arrow-up
      17
      ·
      2 years ago

      Someone has to say this. Don’t do it anyone

      • sp451 ( sp451@lemmy.sdf.org ) 
        link
        fedilink
        arrow-up
        14
        ·
        2 years ago

        Agree. Don’t just copy and paste CLI commands you find on the internet, suggested by a stranger

      • Hux ( Hux@lemmy.ml ) 
        link
        fedilink
        arrow-up
        4
        ·
        2 years ago

        For reference: https://en.m.wikipedia.org/wiki/Rm_(Unix)

        The rm -rf / variant of the command, if run by a superuser, would cause every file accessible from the present file system to be deleted from the machine.

    • papertowels ( papertowels@lemmy.one ) 
      link
      fedilink
      arrow-up
      9
      ·
      2 years ago

      The most deceptive joke I’ve seen on this is sudo rm -fr / to remove the French language pack

    • potentiallynotfelix ( potentiallynotfelix@lemmy.fish ) 
      link
      fedilink
      English
      arrow-up
      7
      ·
      2 years ago

      I did this on my personal computer just to prove a point.

  • lud ( lud@lemm.ee ) 
    link
    fedilink
    arrow-up
    11
    ·
    edit-2
    2 years ago

    As primarily a Windows admin (Yes, we exist on Lemmy ;) ) here are few I use often.

    • Enter-PSSesion
    • Get-ADUser (also group and computer)
    • CLS (aka the superior clear)
    • ii . (short for Invoke-Item . which runs the selected object using the default method. For paths (like .) the default is explorer, so ii . opens the current directory using explorer.)
    • ft (short for Format-Table formats piped input as a table.)
    • fl (short for format-like. Used like ft but for lists.)
    • Where-Object
    • Select-Object
    • mexicancartel ( mexicancartel@lemmy.dbzer0.com ) 
      link
      fedilink
      English
      arrow-up
      18
      ·
      2 years ago

      • lud ( lud@lemm.ee ) 
        link
        fedilink
        arrow-up
        2
        ·
        2 years ago

        Fucking hell Lol 😂

  • Appoxo ( Appoxo@lemmy.dbzer0.com ) 
    link
    fedilink
    arrow-up
    10
    ·
    2 years ago

    ls and cd

    • AdNecrias ( AdNecrias@lemmy.pt ) 
      link
      fedilink
      arrow-up
      2
      ·
      2 years ago

      I sometimes hit ls and then need to type dir.

      • Appoxo ( Appoxo@lemmy.dbzer0.com ) 
        link
        fedilink
        arrow-up
        4
        ·
        2 years ago

        The amount of times i tried to dir in linux and ls in windows is mire than I like to admit

  • Shimon ( Shimon@slrpnk.net ) 
    link
    fedilink
    arrow-up
    9
    ·
    2 years ago
    sl
    
    • Nailbar ( nailbar@sopuli.xyz ) 
      link
      fedilink
      arrow-up
      4
      ·
      2 years ago

      Choo choo!

  • lluki ( lluki@feddit.org ) 
    link
    fedilink
    arrow-up
    9
    ·
    2 years ago

    xdg-open FILE - opens a file with the default GUI app. I use it for example to open PDFs and PNG. I have a one letter alias for that. It can also open a file explorer in the current directory xdg-open . . Should work on any compliant desktop environment (gnome/kde).

  • some_guy ( some_guy@lemmy.sdf.org ) 
    link
    fedilink
    arrow-up
    9
    ·
    2 years ago

    cd every single day.

  • blackstrat ( blackstrat@lemmy.fwgx.uk ) 
    link
    fedilink
    arrow-up
    8
    ·
    2 years ago

    ll

    df -h

    du -sch

    Ctrl+r

    • notfromhere ( notfromhere@lemmy.ml ) 
      link
      fedilink
      arrow-up
      3
      ·
      2 years ago

      ll

      Is an alias for

      ls -al
      

      yea?

      • blackstrat ( blackstrat@lemmy.fwgx.uk ) 
        link
        fedilink
        arrow-up
        1
        ·
        2 years ago

        I have it as ls -alFh

Asklemmy@lemmy.ml

asklemmy@lemmy.ml

Subscribe from Remote Instance

Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !asklemmy@lemmy.ml

A loosely moderated place to ask open-ended questions

Search asklemmy 🔍

If your post meets the following criteria, it’s welcome here!

  1. Open-ended question
  2. Not offensive: at this point, we do not have the bandwidth to moderate overtly political discussions. Assume best intent and be excellent to each other.
  3. Not regarding using or support for Lemmy: context, see the list of support communities and tools for finding communities below
  4. Not ad nauseam inducing: please make sure it is a question that would be new to most members
  5. An actual topic of discussion

Looking for support?

  • !lemmy_support@lemmy.ml
  • !fediverse@lemmy.ml
  • !selfhosted@lemmy.world

Looking for a community?

  • Lemmyverse: community search
  • sub.rehab: maps old subreddits to fediverse options, marks official as such
  • !lemmy411@lemmy.ca: a community for finding communities

Icon by @Double_A@discuss.tchncs.de

Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 83 users / day
  • 566 users / week
  • 1.73K users / month
  • 4.42K users / 6 months
  • 1.49K local subscribers
  • 55.8K subscribers
  • 6.92K Posts
  • 153K Comments
  • Modlog
  • mods:
  • Evan ( Cloak@lemmy.ml ) 
  • mekhos ( mekhos@lemmy.ml ) 
  • tmpod ( tmpod@lemmy.pt ) 
  • OrangeSlice ( 14specks@lemmy.ml ) 
  • BE: 0.19.15
  • Modlog
  • Legal
  • Instances
  • Docs
  • Code