@[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.
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.
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.
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.
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.
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.
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.
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.
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
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'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
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.
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...
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
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.
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.
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.
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.
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.
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.
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
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?
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.
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.
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!
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).
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.
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.
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 }
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.
... 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).
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)
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.
sudo !!to rerun last command as sudo.historycan be paired with!5to run the fifth command listed in history.@[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!!We're all learning tricks in this thread! Grateful for all y'all nerds.
Fifth as in fifth most recent command or fifth oldest?
I believe it's the fifth oldest - I think
!-5will 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 dockerto find docker commands I've ran, then use!followed by the number associated with the command I want to run in history.Love these, I used a terminal select from history with fuzzy finding to do the !5 as
redocdthenlsthencdthenlsmaybe I’ll throw als -aI use -A instead, which doesn't show "." and ".."
Nah you gotta alias ls -a to la for more efficiency.
lDon't forget your
pwdthrown in to get back your bearings!Done be silly, that's part of my prompt.
I really like that
cdcommand. :PYou'll love
zoxidethen.The command is 'z'
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 notesfrom wherever I am.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 usepushd .but even then other tooling should already cover your needs.It's also so easy that you can temporarly append to
$CDPATHfor a specific session. But again, then a second pane or pushd is already available.Now downvote me, lemmy.
You have to enable it in your shell config. For bash it's
eval "$(zoxide init bash)"That will give you the
zcommand.https://github.com/ajeetdsouza/zoxide?tab=readme-ov-file#installation
On arch the command is just
zWhen you set it up you tell it which command you want. Default is "cdi" but I changed it to "cd" immediately.
Hm I wonder, is it really a command? I thought it is just a function of the shell to change the working directory.
A command is anything you execute in the shell.
cdis just a built-in commandtldrbecause I am too impatient to read through man pages or google the exact syntax for what I want to do.There are exactly three kinds of manpages:
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.
grephelps 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 the first of 4 ways I rtfm. Then -h, man, and then the arch wiki
i never use man at all. It's just too confusing.
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.
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.
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.
If something is a bash built-in run
help blahfor 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 foois the equivalent ofman 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.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
tldris great. Basically a crowd-sourced alternative tomanwith much more concise entries. Example:Well....slap my ass and call me Mary.....
Thanks kind internet stranger!
:O
Woah, that's dope as heck. Thank you!
I went a little overboard and wrote a one-liner to accurately answer this question
Note:
historydisplays like this for me20622 2023-02-18 16:41:23 lsI don't know if that's because I setHISTTIMEFORMAT='%F %T 'in .bashrc, or if it's like that for everyone. If it's different for you change-f 5to target the command. Use-f 5-7to include flags and arguments.My top 5 (since last install)
gis 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
lstolcould have saved 2002 keystrokes :P) So I wrote another one-liner to check for available single characters to alias with:In .bash_aliases I've added
alias b='hx ${HOME}/.bash_aliases'to quickly edit aliases andalias r='source ${HOME}/.bashrc'to reload them.Helix?
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'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
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.
Holy shit, you're a madman
history -isudo udevadm monitor
Figuring out which usb device went on holiday.
Wow, super useful command. Starring this comment
Sudo !!
It reruns the last command as sudo.
Pretty useful since I'm always forgetting.
Most commands soon followed by sudo !!
I use this constantly
clearbecause apparently I am too scatterbrained to comprehend more than one full page of text in the terminalI 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.
I almost never use clear because i'm afraid if i will need the text later.(just like infinity tab number on firefox)
* 20
Oh god I also do this... See the comment below, I ran
history|cut -d " " -f 5|sort|uniq -c|sort -nr|lesson my personal laptop, my third most commonly used command (behindlsandcd) is just typing in nothing...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
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.
Try zellij. Not as popular as tmux, but very intuitive to use.
Maybe someone reading wants to now about
prefix+s. This doubles your excitement.In a similar vein,
nohuplets you send tasks to the background and seems to be everywhere.You can't mention
nohupwithout at least mentioningkill -9orpkillto slay the monster you created you madmanSometimes I'll just reboot the entire damn machine just to be safe ;)
shutdown -r nowEyyy, 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.
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
Also, screen can connect to an UART device or serial or anything that offers up a TTY
I Always forget to run screen first, so I just rely heavily on dtach
Simply change your terminal command to execute the terminal multiplexer of your choice.
man terminal_of_choice, look for (start) command.No thanks, I'm good
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?
You can find out by running screen and executing pstree, that way you can see how the screen process is run.
pushd and popd to change directory and go back when done there.
Even better when
cdautomatically invokespushd.cd -undoes the last cd. Not quite push/popd but still useful. Pro tip, works also: git checkout -Hell yeah. Every one of these threads makes me more inclined to read man pages
You should. These are the actually sources to learn.
what's your alias?
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/binis in your$PATHenvironment variable. You can add more paths that you'd like to execute scripts from, like a personal git repo that contains your scripts.I think the standard is ~/.local/bin, for the people that like standards.
or add it to path
After using too much WINE, I type
pwd,whoamiAs primarily a Windows admin (Yes, we exist on Lemmy ;) ) here are few I use often.
Enter-PSSesionGet-ADUser(also group and computer)CLS(aka the superiorclear)ii .(short forInvoke-Item .which runs the selected object using the default method. For paths (like.) the default is explorer, soii .opens the current directory using explorer.)ft(short forFormat-Tableformats piped input as a table.)fl(short forformat-like. Used likeftbut for lists.)Where-ObjectSelect-ObjectFucking hell Lol 😂
There are dozens of us.
Also, I'll add:
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.
Uhhh...
sudo suDon't be like me
sudo -i
clear. Constantly, and for no reason.Ctrl-L
Oh. I know. But you don't understand - I'm compelled to type it out. I must.
I used to, but the terminal clear is better, so I don't.
CMD/CTRL-K for me.
Someone who doesn't know the benefits of dedicated, unlimited scrollback buffers. This command is useful but has a bad effect (when unintentionally).
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.
i’d like to introduce you to your new best friend: reset… it doesn’t everything clear does and a LOT more
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.
cdevery single day.You haven't discovered
exa? Noob/s
ls and cd
I sometimes hit ls and then need to type dir.
The amount of times i tried to dir in linux and ls in windows is mire than I like to admit
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
Related: Alt +
., to cycle through arguments used in previous commandsI just use control C, is there a difference other than whether the line shows up or not?
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.
This is great for when you type in your root password incorrectly!
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 directoryxdg-open .. Should work on any compliant desktop environment (gnome/kde).ls
ls -ltrc
Show most recently modified files.
Choo choo!
A lemming of taste
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.
On my desktop:
df -hto check disk usagehtopto see resource usagelllist directory contentsI recently found btop and am trying to use that instead of htop.
looks up btop ooooo
sudo pacman -Syu
I just aliased "sudo pacman -Syu && yay -Syu --aur" to "update" cause I got tired of writing it every day.
You can just run
yaywith no arguments and it does exactly what your update script does.Huh, the more you know.
Wouldn't it make more sense to just yay -Syu to update everything, normal packages and AUR packages?
The reason I did it like this is because:
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.
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
ll
df -h
du -sch
Ctrl+r
Is an alias for
yea?
I set mine to
I have it as
ls -alFhBtop is an amazing resource monitor
Have you tried glances?
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.
Not a command but bang expansions. For example
!?is the args of last command useful for stuff likemkdir foo ; cd !?https://www.redhat.com/sysadmin/bash-bang-commands learn these. you suck at using your computer if you don't know them.
Is there something similar in fish shell?
ncdu
I recently learned to use a for loop on the command line to organize hundreds of files in a few seconds.
Example of said Black Magik?
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.
Check out
renameIn 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?
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.
renameis 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.
SED combinator, you win 🙌
xargsis also fun, and assuming your for loop doesn't update anything out of the loop, is highly parallelizableThe equivalent of the same command, that handles 10 tasks concurrently, using
%%as a variable placeholder.But for mass renaming files,
diredalong with rectangle-select and multicursors within Emacs is my goto.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.
you ever use ctrl+r ?
...I do now!
Install the fzf integration for ctrl+r fuzzy finding through your entire shell history:
https://thevaluable.dev/fzf-shell-integration/
Thanks friend, will do!
If you know it was the most recent rsync command: just type !rsync.
Laughs in fish
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.
nmtui. But that's because my router is trash.
sudo
Make me a sandwich.
LambdaRX is not in the sudoers file. This incident will be reported
Eh, guess I won't get anything for christmas.
For Debian based/descended distros:
And technically I also regularly use
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
Chuck the -y in there for extra lazy mode
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.
topgradedoes this and and a lot morejqNeofetch
let me guess, you either use arch or gentoo
You caught me. (I use arch btw)
I use
atuin(link) all the timeg-pushwhich is alias forWhich I'm writing on my phone without testing or looking
git push origin HEADis a slightly shorter way of doing the same thing, even though you have an alias anyway lolgit config --global alias.pusho 'push --set-upstream origin HEAD'You're welcome.
So that's making
git pushalways push to the current branch?When you're pushing a new branch you've never pushed before you need the
-ucommand. That's what this alias is for.As long as the config's
push.defaultisn'tmatching,git pushwithout arguments will only push the current branch.nano
The one downvote is from the Vim user
The one downvote is from the Vim user
I've recently started using
tmuxwhen starting a new SSH session to try to build the habit.https://github.com/tmux/tmux/wiki
ls -alI 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 isls -lhain addition to whatever color coding stuff is there by default.You might like
ezaeven more!Hmm, that's not working for me. You mean use those as options? 'ls -eza'?
No, it's like an ls replacement: https://github.com/eza-community/eza
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!
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 ezaCustom apt repo:
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.No,
ezais one of those modern Rust replacement programs. It replacesls.There's a whole bunch of cool modern replacements. Here's a handy list: altbox.dev
I personally use
batandrgall 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.
The mobile site doesn't have the list. I was so confused.
Ew, sorry. This list is similar and more accessible:
https://github.com/ibraheemdev/modern-unix
Even better than
rgisrga. Indeed, you have a fine list.You might like lsd even more than that!
A lot of distros include a .bashrc with common
lsaliases commented out, just waiting for you to activate them if you like.Another
lsalias I'm a fan of isls -latrwhich I alias tolt. It gives you a time sorted directory listing with the most recent next to your cursor (helpful for large directories).Seems like an appropriate place to share https://github.com/agarrharr/awesome-cli-apps
I'm a fan of ripgrep and lsd in particular.
GNU Parallel
du -sh /too/barto get size of files/folders.sudo !!inserts sudo into previous command when forgotten.yayfor full system update if yay is installed.catreads files.I have
cd && clearaliased ashomeLazy aliases unite!
exec $SHELL -lomz 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
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.
Getting cheatsheets via
curl cheat.sh/INSERT_COMMAND_HERENo install necessary, Also, you can quickly search within the cheatsheets via
~. For example if you copycurl cheat.sh/ls~findwill show all the examples oflsthat usefind. If you remove~find, then it shows all examples ofls.I have a function in my bash alias for it (also piped into
morefor readability):function cht() { curl cheat.sh/"$1"?style=igor|more }I use "ping" every time I suspect my internet might be going a bit slow.
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
I assume I'm on the wrong OS.
Linux tool. I use it on Ubuntu hosts
I do love
fuck.And you mistype it as fsck
Awesome, didn't know fzf yet
Fzf is so useful its ridiculous. I recreated the functionality of sshs with fzf and a small bash script.
Check out the fzf docs. It ships with helpers that offer better shell integration than you're getting here.
sudo rm -rf /
Very powerful yet helpful command :-)
Someone has to say this. Don't do it anyone
Agree. Don’t just copy and paste CLI commands you find on the internet, suggested by a stranger
Instructions unclear, dick now stuck in computer.
Lp0 on fire
For reference: https://en.m.wikipedia.org/wiki/Rm_(Unix)
The most deceptive joke I've seen on this is
sudo rm -fr /to remove the French language packI did this on my personal computer just to prove a point.
I really like how nushell can parse output into it's native structures called tables using the
detectcommand.Unlike string outputs, tables allow for easy data manipulation through pipes like
select foowill 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:
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
detectcommand.There's are few more shells that do that though nu is the most mature one I've seen so far.
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).
It sounds similar to one of my favorite commands! vidir 🙂
touch😏I remember
touchlocate, from themlocatepackage. So useful. Honorable mention goes out totldr.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
Control + D
Zoxide, dust, fd, rg, btm, tokei. So many newer Rust tools that are way better than the old stuff.
Saving this thread for later, but I use rsync -a a lot.
Have you heard of our lord and saviour rclone?
I haven't gone back to rsync in a long time.
I use it to mount cloud storage as network drives... I'll have to look into your implication though!
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.
Ctrl-R: (type something)
sudo
doas
rangerIf you change the colours to night mode, the song "Sister Christian" starts playing
$ z
A great cd alternative
Also $ sudo paru -Syu
I think you can run paru without sudo and it should still do privilege escalation no problem
oh yes, i was thinking about pacman when writing haha
Neofetch
Get on with the times, install fastfetch ;)
less,watchCtrl-r with https://github.com/atuinsh/atuin is amazing. Never forget a command you used ever again.
I trigger it with the up arrow.
qalcI 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 -autorsync
I use it to backup important work to an external drive.
plzfrom https://github.com/m1guelpf/plz-cliMore of a shortcut,
CTRL + A + Dto exit the current session (exits a sudo su first, then a ssh, then the actual terminal)One "exit" per press
Really? Then I must've been taught wrong and never noticed
gitNeofetch
I just think it's neat.
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
Works just fine for me
[2J[H
Is one of my favorites. Of course, most of you are too young to know what that means.
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.In the days before *nx, "terminal" meant a VT terminal and "clear" wasn't a thing.