What's a handy terminal command you use often?

209 points · 255 comments · view on lemmy.world

255 Comments

papertowels@lemmy.one · 68 pts · 1y (5 replies)

sudo !! to rerun last command as sudo.

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

kellyaster@lemmy.world · 5 pts · 1y (1 reply)

@papertowels@lemmy.one I've been working in the bash shell since 1993 and did not know sudo !! was a thing. Good lord, I no longer have to press up, press crtl-left a bunch of times, then type sudo enter space anymore. And I can give it an easy-to-remember alias like 'resu' or 'redo'! Ahahaha, this changes everything! Thank you!!

papertowels@lemmy.one · 2 pts · 1y

We're all learning tricks in this thread! Grateful for all y'all nerds.

communism@lemmy.ml · 5 pts · 1y (1 reply)

Fifth as in fifth most recent command or fifth oldest?

papertowels@lemmy.one · 7 pts · 1y

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.

olafurp@lemmy.world · 1 pts · 1y

Love these, I used a terminal select from history with fuzzy finding to do the !5 as redo

LazaroFilm@lemmy.world · 56 pts · 1y (5 replies)

cd then ls then cd then ls maybe I’ll throw a ls -a

vrighter@discuss.tchncs.de · 13 pts · 1y

I use -A instead, which doesn't show "." and ".."

blackbirdbiryani@lemmy.world · 9 pts · 1y (1 reply)

Nah you gotta alias ls -a to la for more efficiency.

JackbyDev@programming.dev · 3 pts · 1y

l

papertowels@lemmy.one · 2 pts · 1y (1 reply)

Don't forget your pwd thrown in to get back your bearings!

JackbyDev@programming.dev · 1 pts · 1y

Done be silly, that's part of my prompt.

emb@lemmy.world · 44 pts · 1y (11 replies)

I really like that cd command. :P

unknowing8343@discuss.tchncs.de · 19 pts · 1y (8 replies)

You'll love zoxide then.

velox_vulnus@lemmy.ml · 0 pts · 1y (7 replies)
[ removed ]
Yoddel_Hickory@lemmy.ca · 20 pts · 1y (4 replies)

The command is 'z'

velox_vulnus@lemmy.ml · 7 pts · 1y (3 replies)
[ removed ]
unknowing8343@discuss.tchncs.de · 5 pts · 1y (1 reply)

It's in the official docs for zoxide, you are supposed to use the z alias, and many distros just set it up directly like that. I love doing z notes from wherever I am.

7dev7random7@suppo.fi · 1 pts · 1y

Description fifth point (5.)

That doesn't require a separate package, especially one which uses eval on every new shell. And isn't messing with my distros or personal aliases (and doesn't introduce cargo-packaging).

Simply adding one to two (you get the gist) directories and a keybind for cd .. is more slick. There are cases where you might use pushd . but even then other tooling should already cover your needs.

It's also so easy that you can temporarly append to $CDPATH for a specific session. But again, then a second pane or pushd is already available.

Now downvote me, lemmy.

Noxious@fedia.io · 1 pts · 1y

You have to enable it in your shell config. For bash it's eval "$(zoxide init bash)"

That will give you the z command.

https://github.com/ajeetdsouza/zoxide?tab=readme-ov-file#installation

jeffreyosborne@lemm.ee · 3 pts · 1y

On arch the command is just z

alsimoneau@lemmy.ca · 3 pts · 1y

When you set it up you tell it which command you want. Default is "cdi" but I changed it to "cd" immediately.

jeena@piefed.jeena.net · 6 pts · 1y (1 reply)

Hm I wonder, is it really a command? I thought it is just a function of the shell to change the working directory.

ClassifiedPancake@discuss.tchncs.de · 8 pts · 1y

A command is anything you execute in the shell.

cd is just a built-in command

LaSirena@lemmy.world · 42 pts · 1y (8 replies)

tldr because I am too impatient to read through man pages or google the exact syntax for what I want to do.

pixelscript@lemm.ee · 26 pts · 1y (7 replies)

There are exactly three kinds of manpages:

  1. Way too detailed
  2. Not nearly detailed enough
  3. There is no manpage

I will take 1 any day over 2 or 3. Sometimes I even need 1, so I'm grateful for them.

But holy goddamn is it awful when I just want to use a command for aguably its most common use case and the flag or option for that is lost in a crowd of 30 other switches or buried under some modal subcommand. grep helps if you already know the switch, which isn't always.

You could argue commands like this don't have "arguably most common usecases", so manpages should be completely neutral on singling out examples. But I think the existence of tl;dr is the counterargument.

Tangent complaint: I thought the Unix philosophy was "do one thing, and do it well"? Why then do so many of these shell commands have a billion options? Mostly /s but sometimes it's flustering.

wuphysics87@lemmy.ml · 8 pts · 1y (6 replies)

tldr is the first of 4 ways I rtfm. Then -h, man, and then the arch wiki

vrighter@discuss.tchncs.de · 4 pts · 1y (5 replies)

i never use man at all. It's just too confusing.

wuphysics87@lemmy.ml · 5 pts · 1y (4 replies)

I can appreciate that. Appologies if you know this already, but just don't like them. Here are some tips.

It helps a lot to get title/subtitle/flag highlighting. By default man pages are hard to use simply because of how dense they are. It's much easier to skim when you can separate the parts you are looking for up front from the text.

Don't forget '/', 'n', and 'N'. First way to use man pages more effectively is to search them easily. And you can search via regex. Often I'm looking for more info on a particular flag. So I'll press '/' followed by '^ *-g'. For a g flag.

Take notes on the side. It saves you time later. Your future self will thank you. And you learn a lot by skimming them.

Man pages can be intimidating/confusing, but, imho, it's worth training that skill. Even if you are slower up front, it's totally worth it.

vrighter@discuss.tchncs.de · 2 pts · 1y (3 replies)

thanks for the advice. I knew about the search feature, but sometimes the stuff you need isn't even on the page. I have no idea how to find what I need when it's not in "man cmdname" how am I supposed to know that the feature i want has a dedicated page?

how could I find certain commands if i didn't already know it was a shell builtin and not a command? It's not like you get a manpage saying "this is not a command". And even if i did have the idea to open the bash page, it's still useless, because builtins are their own dedicated page. That sort of stuff. It rarely ever makes things easier for me.

edit, it is occasionally useful phen I have already found what I want on google and just want some more in depth details.

JackbyDev@programming.dev · 1 pts · 1y (1 reply)

If something is a bash built-in run help blah for it's "man page"

But yeah, man pages tick me off. Wait until you learn that there are sometimes more than one per command. I have to Google which page is which because they're all for specific things. man foo is the equivalent of man 1 foo. What's annoying is that the few times I've seen something referenced on another page the entry usually just says something like it's on "the relevant man page" rather than just telling you exactly which.

vrighter@discuss.tchncs.de · 1 pts · 1y

ok but that still entails trying random things until i find it. If I didn't already know it was a builtin i wouldn't know to search there. The bash thing was just an example. I have learned this stuff since i encountered the problem. This is just me recollecting my experience of trying to use man

wuphysics87@lemmy.ml · 1 pts · 1y

Unfortunately, sometimes (often) there is no man page for what you are looking for. So if you get a page not found, that's usually the case. You can usually find associated pages all the way at the bottom. That helps when what you are looking for isn't a command, but a reference. I don't remember exactly where it is, but man pages are stored in a directory. Probably /etc or /usr. You can always dump that list into fzf or use grep to search to see if there is a page for what you are looking for. It's not a perfect system by any means, but it's a good one to have in your toolbelt.

renzev@lemmy.world · 38 pts · 1y (3 replies)

tldr is great. Basically a crowd-sourced alternative to man with much more concise entries. Example:

$ tldr dhcpcd

  DHCP client.
  More information: <https://roy.marples.name/projects/dhcpcd>.

  Release all address leases:

      sudo dhcpcd --release

  Request the DHCP server for new leases:

      sudo dhcpcd --rebind
SturgiesYrFase@lemmy.ml · 9 pts · 1y

Well....slap my ass and call me Mary.....
Thanks kind internet stranger!

TriflingToad@lemmy.world · 4 pts · 1y

:O

clay_pidgin@sh.itjust.works · 3 pts · 1y

Woah, that's dope as heck. Thank you!

I_Miss_Daniel@lemmy.world · 36 pts · 1y (1 reply)

sudo udevadm monitor

Figuring out which usb device went on holiday.

tetris11@lemmy.ml · 8 pts · 1y

Wow, super useful command. Starring this comment

SinkingLotus@lemmy.world · 36 pts · 1y (1 reply)

Sudo !!

It reruns the last command as sudo.

Pretty useful since I'm always forgetting.

squid_slime@lemm.ee · 3 pts · 1y

Most commands soon followed by sudo !!

pemptago@lemmy.ml · 36 pts · 1y (7 replies)

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.

MigratingtoLemmy@lemmy.world · 10 pts · 1y (3 replies)

Helix?

pemptago@lemmy.ml · 6 pts · 1y (2 replies)

Yup! Migrated from VSCodium; wanted to learn a modal editor but didn't have the time or confidence to configure vim or neovim. It's been my go-to editor for 2+ years now.

MigratingtoLemmy@lemmy.world · 4 pts · 1y (1 reply)

I've been using vi (just the basics) for ~4 years, I don't think I could be arsed to pick up the keybindings the other way around lol. I've heard very good things about Helix, of course

HeartyOfGlass@lemm.ee · 3 pts · 1y

As another longtime Vi user - I had a hell of a time & wound up switching back lol

I think for a lot of folks Helix would be intuitive. Vi has her hooks in me, though.

flambonkscious@sh.itjust.works · 5 pts · 1y

Holy shit, you're a madman

JackbyDev@programming.dev · 1 pts · 1y

history -i

BaumGeist@lemmy.ml · 1 pts · 1y
[ removed ]
umbrella@lemmy.ml · 34 pts · 1y (1 reply)
[ removed ]
secret300@lemmy.sdf.org · 1 pts · 1y

I use this constantly

zlatiah@lemmy.world · 31 pts · 1y (7 replies)

clear because apparently I am too scatterbrained to comprehend more than one full page of text in the terminal

feddylemmy@lemmy.world · 6 pts · 1y

I like using CRTL+L to clear. It's nice because you can have a command typed out and still be able to press CTRL+L to clear the screen and keep the command typed out.

mexicancartel@lemmy.dbzer0.com · 4 pts · 1y (5 replies)

I almost never use clear because i'm afraid if i will need the text later.(just like infinity tab number on firefox)

pupbiru@aussie.zone · 2 pts · 1y (1 reply)

* 20

zlatiah@lemmy.world · 1 pts · 1y

Oh god I also do this... See the comment below, I ran history|cut -d " " -f 5|sort|uniq -c|sort -nr|less on my personal laptop, my third most commonly used command (behind ls and cd) is just typing in nothing...

BaumGeist@lemmy.ml · 1 pts · 1y (2 replies)
[ removed ]
mexicancartel@lemmy.dbzer0.com · 1 pts · 1y (1 reply)

100 tabs is in mobile. I don't even scroll back to clutter my brain but its there. Tabs are history for me... So I use firefox focus and if there is anything important, i open with firefox.

What script are you reffering to? To log all output? I don't wanna store that but need an assurance that its there till i close terminal window lol

BaumGeist@lemmy.ml · 2 pts · 1y
[ removed ]
notfromhere@lemmy.ml · 28 pts · 1y (15 replies)

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@feddit.org · 8 pts · 1y (2 replies)

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.

krash@lemmy.ml · 3 pts · 1y

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

7dev7random7@suppo.fi · 1 pts · 1y

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

papertowels@lemmy.one · 7 pts · 1y (5 replies)

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

pyr0ball@sh.itjust.works · 3 pts · 1y (4 replies)

You can't mention nohup without at least mentioning kill -9 or pkill to slay the monster you created you madman

papertowels@lemmy.one · 2 pts · 1y (1 reply)

Sometimes I'll just reboot the entire damn machine just to be safe ;)

Sorse@discuss.tchncs.de · 2 pts · 1y

shutdown -r now

olafurp@lemmy.world · 1 pts · 1y (1 reply)

Eyyy, don't hate, this is how I start all my work programs. That command is really nice and creates all work programs as children of a single terminal session for easy closing later.

pyr0ball@sh.itjust.works · 2 pts · 1y

No hate! Just need to make sure people know so they don't create a bazillion threads without realizing it, or how to stop them effectively

tetris11@lemmy.ml · 4 pts · 1y

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

muzzle@lemm.ee · 2 pts · 1y (2 replies)

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

7dev7random7@suppo.fi · 1 pts · 1y (1 reply)

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

man terminal_of_choice, look for (start) command.

muzzle@lemm.ee · 1 pts · 1y

No thanks, I'm good

krash@lemmy.ml · 1 pts · 1y (1 reply)

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@lemmy.darvit.nl · 1 pts · 1y

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

Jozav@lemmy.world · 24 pts · 1y (5 replies)

pushd and popd to change directory and go back when done there.

jbrains@sh.itjust.works · 3 pts · 1y (4 replies)

Even better when cd automatically invokes pushd.

lluki@feddit.org · 28 pts · 1y (2 replies)

cd - undoes the last cd. Not quite push/popd but still useful. Pro tip, works also: git checkout -

med@sh.itjust.works · 4 pts · 1y (1 reply)

Hell yeah. Every one of these threads makes me more inclined to read man pages

7dev7random7@suppo.fi · 2 pts · 1y

You should. These are the actually sources to learn.

tetris11@lemmy.ml · 2 pts · 1y

what's your alias?

Bougie_Birdie@lemmy.blahaj.zone · 23 pts · 1y (3 replies)

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.

friend_of_satan@lemmy.world · 23 pts · 1y

This is because $HOME/bin is in your $PATH environment variable. You can add more paths that you'd like to execute scripts from, like a personal git repo that contains your scripts.

unknowing8343@discuss.tchncs.de · 16 pts · 1y

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

potentiallynotfelix@lemmy.fish · 2 pts · 1y

or add it to path

LambdaRX@sh.itjust.works · 22 pts · 1y

After using too much WINE, I type pwd, whoami

lud@lemm.ee · 20 pts · 1y (3 replies)

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@lemmy.dbzer0.com · 24 pts · 1y (1 reply)

lud@lemm.ee · 5 pts · 1y

Fucking hell Lol 😂

hactar42@lemmy.world · 8 pts · 1y

There are dozens of us.

Also, I'll add:

  • Get-Help
  • Get-Command
  • Get-Member
sgtnasty@lemmy.ml · 19 pts · 1y

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@lemmy.ca · 19 pts · 1y (1 reply)

Uhhh...sudo su

Don't be like me

vrighter@discuss.tchncs.de · 7 pts · 1y

sudo -i

HeartyOfGlass@lemm.ee · 18 pts · 1y (8 replies)

clear. Constantly, and for no reason.

igorette@lemmy.ml · 29 pts · 1y (5 replies)

Ctrl-L

HeartyOfGlass@lemm.ee · 24 pts · 1y (1 reply)

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

ripcord@lemmy.world · 1 pts · 1y

I used to, but the terminal clear is better, so I don't.

ripcord@lemmy.world · 2 pts · 1y (2 replies)

CMD/CTRL-K for me.

7dev7random7@suppo.fi · 1 pts · 1y (1 reply)

Someone who doesn't know the benefits of dedicated, unlimited scrollback buffers. This command is useful but has a bad effect (when unintentionally).

ripcord@lemmy.world · 2 pts · 1y

No, I do. Clearing the scrollback because I want a new, very clear start point for a new activity and don't care about the rest is frequently the goal.

If I do care about the history I'll do something else or possibly been saving history to disk, although that's far more rare.

pupbiru@aussie.zone · 1 pts · 1y

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

omxxi@feddit.org · 1 pts · 1y

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.

some_guy@lemmy.sdf.org · 17 pts · 1y (1 reply)

cd every single day.

InternetCitizen2@lemmy.world · 5 pts · 1y

You haven't discovered exa? Noob

/s

Appoxo@lemmy.dbzer0.com · 16 pts · 1y (2 replies)

ls and cd

AdNecrias@lemmy.pt · 4 pts · 1y (1 reply)

I sometimes hit ls and then need to type dir.

Appoxo@lemmy.dbzer0.com · 5 pts · 1y

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

RagingRobot@lemmy.world · 15 pts · 1y (5 replies)

CTR + u will delete the whole command. I use that a lot so I don't have to backspace. It's saved me a ton of time

call_me_xale@lemmy.zip · 16 pts · 1y

Related: Alt + ., to cycle through arguments used in previous commands

potentiallynotfelix@lemmy.fish · 5 pts · 1y

I just use control C, is there a difference other than whether the line shows up or not?

darvit@lemmy.darvit.nl · 4 pts · 1y

How about ctrl+c to cancel and clear the command you are typing? It's much easier because you only need 1 hand, and does not impact your shell's history.

emergencybird@lemmy.world · 2 pts · 1y

This is great for when you type in your root password incorrectly!

anindefinitearticle@sh.itjust.works · 2 pts · 1y
[ removed ]
lluki@feddit.org · 13 pts · 1y

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).

Shimon@slrpnk.net · 12 pts · 1y (2 replies)
sl
nailbar@sopuli.xyz · 4 pts · 1y

Choo choo!

berryjam@lemmy.world · 2 pts · 1y

A lemming of taste

ripcord@lemmy.world · 12 pts · 1y (1 reply)

ls

ace_garp@lemmy.world · 3 pts · 1y

ls -ltrc

Show most recently modified files.

kittenzrulz123@lemmy.blahaj.zone · 9 pts · 1y (2 replies)

Btop is an amazing resource monitor

daq@lemmy.sdf.org · 1 pts · 1y (1 reply)

Have you tried glances?

kittenzrulz123@lemmy.blahaj.zone · 1 pts · 1y

Never heard of it, looks cool but not as pretty as btop. Also has a ton of information I don't personally care about so for me it doesn't seem great.

blackstrat@lemmy.fwgx.uk · 9 pts · 1y (3 replies)

ll

df -h

du -sch

Ctrl+r

notfromhere@lemmy.ml · 3 pts · 1y (2 replies)

ll

Is an alias for

ls -al

yea?

subtext@lemmy.world · 2 pts · 1y

I set mine to

ls -lAh
blackstrat@lemmy.fwgx.uk · 1 pts · 1y

I have it as ls -alFh

beirdobaggins@lemmy.world · 9 pts · 1y

diff -y -W 200 file1 file2

Shows a side by side diff of 2 files with enough column width to see most of what I need usually.

I have actually aliased this command as diffy

ctrl-r

searching bash history

du -sh * | sort -h

shows size of all files and dirs in the current dir and sorts them in ascending order so you can easily see the largest files or dirt ant the end of the list

ls -ltr

Shows the most recently modified files at the end of the listing.

hit_the_rails@reddthat.com · 9 pts · 1y (6 replies)

sudo pacman -Syu

sneezycat@sopuli.xyz · 3 pts · 1y (5 replies)

I just aliased "sudo pacman -Syu && yay -Syu --aur" to "update" cause I got tired of writing it every day.

MinFapper@startrek.website · 14 pts · 1y (1 reply)

You can just run yay with no arguments and it does exactly what your update script does.

sneezycat@sopuli.xyz · 3 pts · 1y

Huh, the more you know.

Noxious@fedia.io · 1 pts · 1y (2 replies)

Wouldn't it make more sense to just yay -Syu to update everything, normal packages and AUR packages?

sneezycat@sopuli.xyz · 1 pts · 1y (1 reply)

The reason I did it like this is because:

  • I didn't know yay could invoke pacman
  • I didn't want yay "upgrading" my pacman packages with AUR packages.

But I was just misunderstanding yay. As another comment said before you, one can just run yay without any arguments and it accomplishes the same thing.

Noxious@fedia.io · 2 pts · 1y

Yay doesn't replace normal packages with AUR packages. Btw It's not just an AUR helper, it's a wrapper for Pacman with AUR support built-in. Check out paru btw, it's a more modern version of yay that basically works the same way: https://github.com/Morganamilo/paru

technocat@lemm.ee · 9 pts · 1y
  • man
  • fd
  • entr
  • rg
  • gitui
  • nvim
  • tee
  • cd
  • mv
  • rm
  • ls
  • tmux
  • btop
  • yazi
  • du
  • xargs
  • cat
  • less
majestictechie@lemmy.fosshost.com · 9 pts · 1y (2 replies)

On my desktop: df -h to check disk usage htop to see resource usage ll list directory contents

Albbi@lemmy.ca · 10 pts · 1y (1 reply)

I recently found btop and am trying to use that instead of htop.

majestictechie@lemmy.fosshost.com · 8 pts · 1y

looks up btop ooooo

anonymouse2@sh.itjust.works · 8 pts · 1y (7 replies)

I recently learned to use a for loop on the command line to organize hundreds of files in a few seconds.

makingStuffForFun@lemmy.ml · 1 pts · 1y (6 replies)

Example of said Black Magik?

anonymouse2@sh.itjust.works · 9 pts · 1y (5 replies)

Let's say, for example, you have a directory of files named x01-001; x01-002; x02-001; x02-002; x03-001... and so on.

I want to create subdirectories for each 'x' iteration and move each set to the corresponding subdirectory. My loop would look like this:

for i in {1..3}; do mkdir Data_x0$i && mv x0$i* Data_x0$i; done

I've also been using it if I need to rename large batches of files quickly.

friend_of_satan@lemmy.world · 9 pts · 1y (3 replies)

Check out rename

$ touch foo{1..5}.txt
$ rename -v 's/foo/bar/' foo*
foo1.txt renamed as bar1.txt
foo2.txt renamed as bar2.txt
foo3.txt renamed as bar3.txt
foo4.txt renamed as bar4.txt
foo5.txt renamed as bar5.txt
$ rename -v 's/\.txt/.text/' *.txt
bar1.txt renamed as bar1.text
bar2.txt renamed as bar2.text
bar3.txt renamed as bar3.text
bar4.txt renamed as bar4.text
bar5.txt renamed as bar5.text
$ rename -v 's/(.*)\.text/1234-$1.txt/' *.text
bar1.text renamed as 1234-bar1.txt
bar2.text renamed as 1234-bar2.txt
bar3.text renamed as 1234-bar3.txt
bar4.text renamed as 1234-bar4.txt
bar5.text renamed as 1234-bar5.txt
electric_nan@lemmy.ml · 1 pts · 1y (1 reply)

In your second example, it looks like you have an escape character before the first 'dot', but not the second one. Is this a typo, or am I misunderstanding the command?

friend_of_satan@lemmy.world · 4 pts · 1y

It's not a typo. The first section of the regex is a matching section, where a dot means "match any character", and an escaped dot is a literal dot character. The second section is the replacement section, and you don't have to escape the dot there because that section isn't matching anything. You can escape it though if it makes the code easier to read.

rename is written in Perl so all Perl regular expression syntaxes are valid.

However, your comment did make me realize that I hadn't escaped a dot in the third example! So I fixed that.

0_0j@lemmy.world · 1 pts · 1y

SED combinator, you win 🙌

tetris11@lemmy.ml · 4 pts · 1y

xargs is also fun, and assuming your for loop doesn't update anything out of the loop, is highly parallelizable

The equivalent of the same command, that handles 10 tasks concurrently, using %% as a variable placeholder.

seq 1 100 | xargs -I'%%' -P 10 sh -c 'mkdir Data_X0%% && mv x0%%* Data_X0%%;'

But for mass renaming files, dired along with rectangle-select and multicursors within Emacs is my goto.

NaevaTheRat@vegantheoryclub.org · 8 pts · 1y (1 reply)

Not a command but bang expansions. For example !? is the args of last command useful for stuff like mkdir foo ; cd !?

https://www.redhat.com/sysadmin/bash-bang-commands learn these. you suck at using your computer if you don't know them.

Andromxda@lemmy.dbzer0.com · 1 pts · 1y

Is there something similar in fish shell?

_thebrain_@sh.itjust.works · 8 pts · 1y (7 replies)

Not a command as much as I press the up arrow a lot. I'm.pretty lazy and hitting the up arrow 12 times is easier then retyping a complex rsync command.

waggz@programming.dev · 13 pts · 1y (3 replies)

you ever use ctrl+r ?

hit_the_rails@reddthat.com · 7 pts · 1y (2 replies)

...I do now!

naught@sh.itjust.works · 7 pts · 1y (1 reply)

Install the fzf integration for ctrl+r fuzzy finding through your entire shell history:

https://thevaluable.dev/fzf-shell-integration/

hit_the_rails@reddthat.com · 2 pts · 1y

Thanks friend, will do!

Nath@aussie.zone · 4 pts · 1y

If you know it was the most recent rsync command: just type !rsync.

Sorse@discuss.tchncs.de · 1 pts · 1y (1 reply)

Laughs in fish

_thebrain_@sh.itjust.works · 2 pts · 1y

I actually use fish on my personal machine. But the servers I manage are pretty basic to save space and all just use stock bash.

nichtburningturtle@feddit.org · 8 pts · 1y

nmtui. But that's because my router is trash.

pocopene@lemmy.world · 8 pts · 1y

ncdu

NauticalNoodle@lemmy.ml · 7 pts · 1y (3 replies)

For Debian based/descended distros:

sudo apt-get update && sudo apt-get upgrade

And technically I also regularly use

redshift -O 3000

all of the blue light filter programs try to align themselves with a user's geographic location and time, but I don't keep normal hours

sirico@feddit.uk · 8 pts · 1y (1 reply)

Chuck the -y in there for extra lazy mode

NauticalNoodle@lemmy.ml · 6 pts · 1y

I would but much like somebody else's recent post I have in the past nuked my install by blindly agreeing to some recommended software removals before. These days I like to double check what packages are being updated and replaced.

igorette@lemmy.ml · 2 pts · 1y

topgrade does this and and a lot more

JoMiran@lemmy.ml · 7 pts · 1y (3 replies)

sudo

LambdaRX@sh.itjust.works · 12 pts · 1y (2 replies)

Make me a sandwich.

nichtburningturtle@feddit.org · 15 pts · 1y (1 reply)

LambdaRX is not in the sudoers file. This incident will be reported

LambdaRX@sh.itjust.works · 5 pts · 1y

Eh, guess I won't get anything for christmas.

Wuttin@lemmy.ml · 7 pts · 1y

jq

pineapplelover@lemm.ee · 7 pts · 1y (2 replies)

Neofetch

potentiallynotfelix@lemmy.fish · 9 pts · 1y (1 reply)

let me guess, you either use arch or gentoo

pineapplelover@lemm.ee · 4 pts · 1y

You caught me. (I use arch btw)

Spider89@lemm.ee · 6 pts · 1y (2 replies)

nano

black0ut@pawb.social · 5 pts · 1y

The one downvote is from the Vim user

black0ut@pawb.social · -1 pts · 1y

The one downvote is from the Vim user

Cruxil@aussie.zone · 6 pts · 1y

I've recently started using tmux when starting a new SSH session to try to build the habit.

https://github.com/tmux/tmux/wiki

olafurp@lemmy.world · 6 pts · 1y (4 replies)

g-push which is alias for

git push origin `git branch --show`

Which I'm writing on my phone without testing or looking

JackbyDev@programming.dev · 2 pts · 1y (2 replies)

git config --global alias.pusho 'push --set-upstream origin HEAD'

You're welcome.

olafurp@lemmy.world · 1 pts · 1y (1 reply)

So that's making git push always push to the current branch?

JackbyDev@programming.dev · 1 pts · 1y

When you're pushing a new branch you've never pushed before you need the -u command. That's what this alias is for.

As long as the config's push.default isn't matching, git push without arguments will only push the current branch.

Cruxil@aussie.zone · 2 pts · 1y

git push origin HEAD is a slightly shorter way of doing the same thing, even though you have an alias anyway lol

nameisnotimportant@lemmy.ml · 6 pts · 1y (1 reply)

I use atuin (link) all the time

seth@lemmy.world · 0 pts · 1y
[ removed ]
unionagainstdhmo@aussie.zone · 6 pts · 1y
[ removed ]
korthrun@lemmy.sdf.org · 6 pts · 1y (1 reply)

Seems like an appropriate place to share https://github.com/agarrharr/awesome-cli-apps

I'm a fan of ripgrep and lsd in particular.

x00za@lemmy.dbzer0.com · 5 pts · 1y
[ removed ]
DirigibleProtein@aussie.zone · 6 pts · 1y (14 replies)

ls -al

walden@sub.wetshaving.social · 6 pts · 1y (12 replies)

I learned you can edit .bashrc (in your home dir) and update the alias for ls to include what I like. It has saved me lots of keystrokes. Mine is ls -lha in addition to whatever color coding stuff is there by default.

jbrains@sh.itjust.works · 7 pts · 1y (10 replies)

You might like eza even more!

walden@sub.wetshaving.social · 2 pts · 1y (8 replies)

Hmm, that's not working for me. You mean use those as options? 'ls -eza'?

babeuh@lemmy.world · 4 pts · 1y (2 replies)

No, it's like an ls replacement: https://github.com/eza-community/eza

walden@sub.wetshaving.social · 1 pts · 1y (1 reply)

Aha. Well, I guess I'm not the target audience because I can't be bothered to go through the installation steps. It's not in the LMDE repository, but I wish it were!

Noxious@fedia.io · 1 pts · 1y

It's pretty easy. You either get it from Cargo (the Rust package manager) or add a custom repo to apt.

Cargo is the easier and safer option: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh && cargo install eza

Custom apt repo:

sudo apt update
sudo apt install -y gpg

sudo mkdir -p /etc/apt/keyrings
wget -qO- https://raw.githubusercontent.com/eza-community/eza/main/deb.asc | sudo gpg --dearmor -o /etc/apt/keyrings/gierens.gpg
echo "deb [signed-by=/etc/apt/keyrings/gierens.gpg] http://deb.gierens.de stable main" | sudo tee /etc/apt/sources.list.d/gierens.list
sudo chmod 644 /etc/apt/keyrings/gierens.gpg /etc/apt/sources.list.d/gierens.list
sudo apt update
sudo apt install -y eza

In my opinion though, you should also try lsd. It's even better than eza. You can also get it from Cargo, just a simple cargo install lsd.

jbrains@sh.itjust.works · 3 pts · 1y (4 replies)

No, eza is one of those modern Rust replacement programs. It replaces ls.

emb@lemmy.world · 1 pts · 1y (3 replies)

There's a whole bunch of cool modern replacements. Here's a handy list: altbox.dev

I personally use bat and rg all the time, and find them much more suitable for everyday tasks.

Edit: And to clarify, I didn't create either list, they're just ones I'd bookmarked at some point.

jbrains@sh.itjust.works · 2 pts · 1y

Even better than rg is rga. Indeed, you have a fine list.

bradboimler@lemmy.world · 2 pts · 1y (1 reply)

The mobile site doesn't have the list. I was so confused.

emb@lemmy.world · 2 pts · 1y

Ew, sorry. This list is similar and more accessible:

https://github.com/ibraheemdev/modern-unix

Noxious@fedia.io · 2 pts · 1y

You might like lsd even more than that!

4am@lemm.ee · 2 pts · 1y

A lot of distros include a .bashrc with common ls aliases commented out, just waiting for you to activate them if you like.

avguser@lemmy.world · 3 pts · 1y

Another ls alias I'm a fan of is ls -latr which I alias to lt. It gives you a time sorted directory listing with the most recent next to your cursor (helpful for large directories).

macattack@lemmy.world · 5 pts · 1y

Getting cheatsheets via curl cheat.sh/INSERT_COMMAND_HERE

No install necessary, Also, you can quickly search within the cheatsheets via ~. For example if you copy curl cheat.sh/ls~find will show all the examples of ls that use find. If you remove ~find, then it shows all examples of ls.

I have a function in my bash alias for it (also piped into more for readability):

function cht() { curl cheat.sh/"$1"?style=igor|more }

squid_slime@lemm.ee · 5 pts · 1y

du -sh /too/bar to get size of files/folders. sudo !! inserts sudo into previous command when forgotten. yay for full system update if yay is installed. cat reads files.

kionite231@lemmy.ca · 5 pts · 1y (3 replies)
history | fzf
gitamar@feddit.org · 3 pts · 1y

Awesome, didn't know fzf yet

krash@lemmy.ml · 2 pts · 1y

Fzf is so useful its ridiculous. I recreated the functionality of sshs with fzf and a small bash script.

korthrun@lemmy.sdf.org · 1 pts · 1y

Check out the fzf docs. It ships with helpers that offer better shell integration than you're getting here.

toastal@lemmy.ml · 5 pts · 1y

GNU Parallel

alsimoneau@lemmy.ca · 5 pts · 1y (1 reply)

I do love fuck.

mexicancartel@lemmy.dbzer0.com · 1 pts · 1y

And you mistype it as fsck

MadBob@feddit.nl · 5 pts · 1y (3 replies)

I use "ping" every time I suspect my internet might be going a bit slow.

LordCrom@lemmy.world · 1 pts · 1y (2 replies)

Try mtr . It'll run kinda like a trace route but will show you where the delay is happening. Still relys in icmp not being blocked

MadBob@feddit.nl · 1 pts · 1y (1 reply)

'mtr' is not recognized as an internal or external command, operable program or batch file.

I assume I'm on the wrong OS.

LordCrom@lemmy.world · 1 pts · 1y

Linux tool. I use it on Ubuntu hosts

sp451@lemmy.sdf.org · 5 pts · 1y (7 replies)

sudo rm -rf /

Very powerful yet helpful command :-)

makingStuffForFun@lemmy.ml · 17 pts · 1y (4 replies)

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

sp451@lemmy.sdf.org · 13 pts · 1y

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

Diplomjodler3@lemmy.world · 7 pts · 1y (1 reply)

Instructions unclear, dick now stuck in computer.

JetpackJackson@feddit.org · 2 pts · 1y

Lp0 on fire

Hux@lemmy.ml · 4 pts · 1y

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@lemmy.one · 9 pts · 1y

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

potentiallynotfelix@lemmy.fish · 7 pts · 1y

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

seth@lemmy.world · 5 pts · 1y (6 replies)
[ removed ]
worsedoughnut@lemdro.id · 5 pts · 1y

I have cd && clear aliased as home

Lazy aliases unite!

JackbyDev@programming.dev · 2 pts · 1y

exec $SHELL -l

BaumGeist@lemmy.ml · 2 pts · 1y (3 replies)
[ removed ]
theshatterstone54@feddit.uk · 1 pts · 1y (2 replies)

omz is bloat and slows fown your shell a lot. Just do this: https://www.youtube.com/watch?v=21_WkzBErQk

And I'd recommend starship for a custom prompt, it's really good: https://starship.rs

Edit: For other ZSH nice-to-haves: https://www.youtube.com/watch?v=eLEo4OQ-cuQ

BaumGeist@lemmy.ml · 1 pts · 1y (1 reply)
[ removed ]
theshatterstone54@feddit.uk · 1 pts · 1y

How slow, because I neved noticed

Trust me, it's noticeable. Or at least it was for me. Numbers wise, it doesn't sound like much, but the difference between 0.05s and 0.5s (which are roughly the times I was experiencing) is very noticeable, at least for me. One is done before you've even fully lifted the finger off the key, while with the other you're preparing to press (or maybe you're already pressing pressing) the next key, by the time you see a reaction.

Your mileage may vary.

pyr0ball@sh.itjust.works · 4 pts · 1y

Going to shamelessly plug my custom bashrc setup which has a ton of little scripting helpers and a few useful aliases. Remember to clone recursively if you want to try it out. (Still very much a work in progress, but it's getting to be pretty robust)

https://GitHub.com/pyr0ball/PRbL-bashrc.git

plumcreek@lemmy.ml · 4 pts · 1y (1 reply)

qmv -f do ${dir}

... for quickly moving and renaming files. The default 'qmv' opens up your preferred text editor with a list of the source and destination name of the directory of files you want to move/rename. The '-f do' tells the command we only want to see/edit the [d]estination [o]nly. If you need to rename/move a bunch of files, it's much quicker to do it in vim (at least for me).

drcouzelis@lemmy.zip · 1 pts · 1y

It sounds similar to one of my favorite commands! vidir 🙂

drmoose@lemmy.world · 4 pts · 1y

I really like how nushell can parse output into it's native structures called tables using the detect command.

Unlike string outputs, tables allow for easy data manipulation through pipes like select foo will select foo key and you can filter and even reshape the datasets.

This is great if you need to work with large data pipes like kuberneters so you can do something like:

kubectl get pods --all-namespaces | detect columns | where $it.STATUS !~ "Running|Completed" | par-each { |it| kubectl -n $it.NAMESPACE delete pod $it.NAME }

This looks complex but it parses kubectl table string to table object -> filters rows only where status is not running or completed -> executes pod delete task for each row in parallel.

Nushell take a while to learn but having real data objects in your terminal pipes is incredible! Especially with the detect command.

There's are few more shells that do that though nu is the most mature one I've seen so far.

CameronDev@programming.dev · 4 pts · 1y (1 reply)

touch 😏

sem@lemmy.blahaj.zone · 6 pts · 1y

I remember touch

z3rOR0ne@lemmy.ml · 4 pts · 1y

locate, from the mlocate package. So useful. Honorable mention goes out to tldr.

this@sh.itjust.works · 3 pts · 1y (1 reply)

not sure if it counts as a command, but i use the up arrow to scroll through previous commands like, almost every time I open a terminal.

tetris11@lemmy.ml · 5 pts · 1y

Ctrl-R: (type something)

friend_of_satan@lemmy.world · 3 pts · 1y
[ removed ]
jbrains@sh.itjust.works · 3 pts · 1y (1 reply)

ranger

tetris11@lemmy.ml · 3 pts · 1y

If you change the colours to night mode, the song "Sister Christian" starts playing

SorteKanin@feddit.dk · 3 pts · 1y

Zoxide, dust, fd, rg, btm, tokei. So many newer Rust tools that are way better than the old stuff.

electric_nan@lemmy.ml · 3 pts · 1y (2 replies)

Saving this thread for later, but I use rsync -a a lot.

blackbirdbiryani@lemmy.world · 2 pts · 1y (1 reply)

Have you heard of our lord and saviour rclone?

I haven't gone back to rsync in a long time.

electric_nan@lemmy.ml · 1 pts · 1y

I use it to mount cloud storage as network drives... I'll have to look into your implication though!

ColdWater@lemmy.ca · 3 pts · 1y (1 reply)

sudo

kaidenshi@lemmy.world · 2 pts · 1y

doas

unionagainstdhmo@aussie.zone · 3 pts · 1y (1 reply)
[ removed ]
jbk@discuss.tchncs.de · 2 pts · 1y

Control + D

berryjam@lemmy.world · 2 pts · 1y

qalc

ICastFist@programming.dev · 2 pts · 1y (4 replies)

More of a shortcut, CTRL + A + D to exit the current session (exits a sudo su first, then a ssh, then the actual terminal)

BaumGeist@lemmy.ml · 1 pts · 1y (3 replies)
[ removed ]
ICastFist@programming.dev · 1 pts · 1y (2 replies)

One "exit" per press

BaumGeist@lemmy.ml · 1 pts · 1y (1 reply)
[ removed ]
ICastFist@programming.dev · 1 pts · 1y

Really? Then I must've been taught wrong and never noticed

FrostyCaveman@lemm.ee · 2 pts · 1y
spittingimage@lemmy.world · 2 pts · 1y

I often play an old DOS game in DOSBox, and when I exit it doesn't reset the screen resolution. So I reset it manually by typing

xrandr -output e-DP1 -auto

Hackerman_uwu@lemmy.world · 2 pts · 1y

rsync

I use it to backup important work to an external drive.

LEVI@feddit.org · 2 pts · 1y
[ removed ]
potentiallynotfelix@lemdro.id · 2 pts · 1y

less, watch

1984@lemmy.today · 2 pts · 1y (1 reply)

Ctrl-r with https://github.com/atuinsh/atuin is amazing. Never forget a command you used ever again.

eric@lemmy.ca · 2 pts · 1y

I trigger it with the up arrow.

kang@lemmy.ml · 2 pts · 1y (2 replies)

$ z

A great cd alternative

Also $ sudo paru -Syu

theshatterstone54@feddit.uk · 3 pts · 1y (1 reply)

I think you can run paru without sudo and it should still do privilege escalation no problem

kang@lemmy.ml · 1 pts · 1y

oh yes, i was thinking about pacman when writing haha

BigLime@lemmy.ml · 2 pts · 1y (1 reply)

Neofetch

sneezycat@sopuli.xyz · 7 pts · 1y

Get on with the times, install fastfetch ;)

smackjack@lemmy.world · 1 pts · 1y
[ removed ]
JackbyDev@programming.dev · 1 pts · 1y

git

daggermoon@lemmy.world · 1 pts · 1y
flac -t *
InSamsara@lemmy.world · 1 pts · 1y (2 replies)

Neofetch

I just think it's neat.

theshatterstone54@feddit.uk · 1 pts · 1y (1 reply)

It's been abandoned btw. People recommend to switch to alternatives. Fastfetch and hyfetch seem to be the best ones rn.

Though I can't confirm as I wrote my own minimal fetch

InSamsara@lemmy.world · 1 pts · 1y

Works just fine for me

10_0@lemmy.ml · 1 pts · 1y
[ removed ]
krash@lemmy.ml · 1 pts · 1y
[ removed ]
MapleEngineer@lemmy.world · -1 pts · 1y (2 replies)

[2J[H

Is one of my favorites. Of course, most of you are too young to know what that means.

JackbyDev@programming.dev · 3 pts · 1y (1 reply)

Is that easier than typing clear? Also, not sure why you'd say something like that about people's age. Anyone using terminals today is often going to run into weird quirks of them being around for decades even if they're young.

MapleEngineer@lemmy.world · 0 pts · 1y

In the days before *nx, "terminal" meant a VT terminal and "clear" wasn't a thing.