sudo !!
to rerun last command as sudo.history
can be paired with!5
to run the fifth command listed in history.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.
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.
no, tmux is a newer screen. some of us havent switched cos we're too lazy i guess? i think the common wisdom is that it's better. i havent tried cos i already know enough of screen and it's fine for me
Or you can learn both and spend the rest of your life trying screen commands in tmux and vice versa.
In a similar vein,
nohup
lets you send tasks to the background and seems to be everywhere.Also, screen can connect to an UART device or serial or anything that offers up a TTY
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?
Simply change your terminal command to execute the terminal multiplexer of your choice.
man terminal_of_choice
, look for (start) command.
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 me20622 2023-02-18 16:41:23 ls
I 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 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
tol
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 andalias r='source ${HOME}/.bashrc'
to reload them.control+R
in bash, it lets you quickly search for previously executed commands.
its very useful and makes things much quicker, i recommend you give it a try.
i rely on this in my job. if i really need it, i'll be using it often enough that it'll always be in ^R distance :)
Oh. I know. But you don't understand - I'm compelled to type it out. I must.
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.
Agree. Don’t just copy and paste CLI commands you find on the internet, suggested by a stranger
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.
doesnt actually do anything on gnu rm, and hasnt in like a decade. but yeah, dont do it.
The most deceptive joke I've seen on this is
sudo rm -fr /
to remove the French language pack
The amount of times i tried to dir in linux and ls in windows is mire than I like to admit
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.- man
- fd
- entr
- rg
- gitui
- nvim
- tee
- cd
- mv
- rm
- ls
- tmux
- btop
- yazi
- du
- xargs
- cat
- less
Seems like an appropriate place to share https://github.com/agarrharr/awesome-cli-apps
I'm a fan of ripgrep and lsd in particular.
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
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.