Tips & tricks
-
When entering a password in a terminal, if you realize there's a typo, type
ctrl + u
to undo the password just entered and enter it again. -
Escaping strings in bash using
!:q
(TODO) -
reverse search (TODO)
-
Hiding passwords in scripts (TODO)
-
Create a simple chat with
netcat
(TODO) -
Bash allows you to ignore history entries that begin with a space if you set the
HISTCONTROL
variable toignorespace
. Type a space before a command before running it in the bash shell and the command will run normally, but won't appear in your history if you have this variable enabled. This allows you to keep your history a bit cleaner, choosing to run commands without them appearing in your history. Bash also allows you to ignore duplicate commands that can clutter your history. To do so, setHISTCONTROL
toignoredups
. To use both the ignorespace and ignoredups feature, set theHISTCONTROL
variable toignoreboth
. -
Always check if a piece of hardware is compatible with Linux, before buying it. For printers, have a look at this list or check the OpenPrinting database. A recent project which aims help people to collaboratively debug hardware related issues, check for Linux-compatibility and find drivers is Hardware for Linux. If you are currently not able to write your own printer driver but you have some interest in it, consider starting from here.
-
Find out neighbours in your local network:
sudo nmap -sn 192.168.1.0/24
-
Use floating-point arithmetich in bash:
bc <<< 'scale=2; 61/14'
-
Encrypt your emails with GnuPG to protect yourself from mass surveillance.
-
Playgrounds to fiddle around with:
-
Capture (unencrypted) HTTP traffic on localhost with nc, e.g.:
# listen fon incoming communication on a specific port in a shell
:~$ nc -l 8080
# send a request to this port from another shell in your machine
:~$ curl -X POST -H "Content-Type: application/json" -d '{"hello": "world"}' http://localhost:8080
# return to the main shell to see the received request
:~$ nc -l 8080
POST / HTTP/1.1
Host: localhost:8080
User-Agent: curl/7.68.0
Accept: */*
Content-Type: application/json
Content-Length: 18
{"hello": "world"}
- Beware of commands with the same name, especially command shell built-in vs- external command as
time
:
:~$ type -a time
time is a shell keyword
time is /usr/bin/time
time is /bin/time
Use the full path to execute to not execute the built-in command:
/usr/bin/time [OPTIONS] COMMAND [ARG]...
#or
/bin/time [OPTIONS] COMMAND [ARG]...
-
Take a screenshot from the command line on a X Window System (and with
imagemagick
):sleep 5; xwd -root | convert xwd:- test.png
-
Cat without cat:
echo "$(<file.txt)"
(credits @jarv)