@[email protected] 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!!
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.
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.
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
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.
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.
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.
Use script instead, you can even have it in your .*shrc to run automatically whenever a shell is invoked (make sure to add a check that the shell wasn't invoked by script, so you don't inadvertently forkbomb yourself)
Alternatively, just use Terminator as yout terminal emulator and enable the logger anytime you need it to record the shell session.
Also, use bookmarks. That's what they're there for. 100 tabs is a great way to clutter your brain, but terrible for productivity. If you forget about it after bookmarking, it wasn't important to begin with.
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.
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.
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?
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.
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.
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.)
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.
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.
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.
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).
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.
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.
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.
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.
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).
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 }
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.
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.
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.
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)
... 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).
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.