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.
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
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.
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.
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.
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.)
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).
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.
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.
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.
atools, which includes als, aunpack, apack. so you can stop caring about the kind of archive and just unpack it. it also saves you from shit archives that have multiple files/dirs in their root.
perl -e / perl -lne / ...
units
bc - a calculator that's actually good
pass - the only non-shit password store tool i've found so far. no gui, uses gpg and git to do the encrypting and storage/sharing
alias lr='ls -lrth' - so you can easily find the newest file, cos that's frequently what you want
unip - my script to look up things in the unicode db
find -type f -exec xzgrep 're' {} + - because xzgrep cant do -r
oh yeah, and for the shell readline, alt-b, alt-f, ctrl-w, ctrl-u, ctrl-k, ctrl-a, ctrl-e
... 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).
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)