Linux - interesting console commands

last time edited: 2017-02-22

This is not a post about essential commands! For essential commands you can have a look at the Linux Pocket Guide or The Linux Command Line Beginner's Guide. This is about commands I - having worked with linux for some years now - didn't know about, and after learning about them, found them awesome.

Helpful

All the years you have been annoyed having forgotten to type sudo... Now the problem simply disappears:

sudo !!

will run the last command you typed (!!) with sudo rights.

An even more advanced version: the fuck command

console output of fuck

https://github.com/nvbn/thefuck


Display weather information on the console with:

curl http://www.wttr.in/Dresden

console output of wttr

Display your external IP:

wget http://ipinfo.io/ip -qO -

Both of them are candidates for custom commands.


A really helpful set of parameters for du:

du -hsc *

Network

Sometimes it can be a hazzle to exchange files with a colleague on another computer. Connected to the same network? Got python installed? Just type

python -m SimpleHTTPServer

... and your directory (including subfolders) will be provided by the SimpleHTTPServer at yourIP:8000 (for which you might have to set a temporary allow rule in your firewall)

Fun

The following commands are more a plaything. Also (therefore) they have to be installed with your package manager:

fortune | cowsay

console output of fortune | cowsay
cmatrix
espeak "give it a try"
tail /var/log/syslog -n 1 -f | espeak
and wait till something is written to syslog or eg mount a device)
cmatrix | espeak
sl
console output of sl

Not strictly a command, but still fun: You can activate insulting "wrong password" messages when promted for sudo password. In your /etc/sudoers file you have to add: Defaults insults

console output of wrong password

System monitoring tools (which have to be installed):

terminal multiplexer described here:

tmux

system monitor:

htop

network monitor (there are several but iftop has a low cpu profile):

sudo iftop

fancy version of tail (alternatively you could also give tail -f | espeak a try):

multitail -f /var/log/syslog

(in Arch Linux this would be journalctl -f without any tail)

I usually open a tty, split it with tmux or screen and run the programs above in different sections.

Productivity tools (with vim like syntax):

mail client:

mutt

file browser:

ranger

python ide:

vim with vundle and jedi as described here

vim

web browser (which compared to elinks supports images)

w3m

music player

mocp

vim commands:

split screen

:vs
:sp

navigation in split screen:

set the following in your .vimrc

nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>

to achieve easier navigation between split screens with Ctrl+h, Ctrl+j, Ctrl+k, Ctrl+l

open a browsable directory tree in vim

:e.

Copying to and from vim

check with:

vim --version

if your vim supports +clipboard and +xterm_clipboard you are ready to go, otherwise you might want to consider installing vim-gtk

Copy from vim to another program "+y

Paste to vim "+gP or just use middle mouse button or p or shift+insert

You could also define your own shortcuts to be able to use ctrl+y (or c) and ctrl+p (or v) with the following entry to your .vimrc

nnoremap <C-y> "+y
nnoremap <C-p> "+gP

Dangerous stuff:

I got this from the Unix haters handbook: please look it up there. In short - in Linux you can name files without restrictions. So you can name a file "-i". Now the fun part: if you try to move this file in shell with the mv command this will be recongnized as "mv -i". Also: this will also affect you when deleting all the files in the directory with an asterisk:

console output demonstrating this
You can imagine that you should be really careful with files named "-rf", since this can easily trigger a recoursive delete operation. By the way, try removing the "-i" file from shell.

Also you might want to read about forkbombs for the bash.

To be continued ...