- The
^
(carat) symbol is often used to denote theCtrl
button so^C
meansCtrl+C
NO_PUBKEY
error? Make sure to add keys via something like
wget http://download.opensuse.org/repositories/PATH/TO/KEY/Release.key
apt-key add - < Release.key
-
Use
^L
(Ctrl+L
) to clear the terminal, even if using a sub-program like mongo or python's interactive shells. -
<(echo "hello world")
will put the results of your process in a temp file and pass the file path to a different process,cat <(echo "Hello world")
for instance will invoke something likecat /proc/self/fd/11
. Very useful for diffs, etc.
Accidentally spew the entire HTTP header, including the Authentication header, to a log file?
This will look for Api-Key: THEKEY
and replace THEKEY
with a redaction, in-place.
gawk -i inplace '{IGNORECASE=1; r = gensub(/(Api-Key:)\s*(.+)$/, "\\1 ***REDACTED***", "g"); print r;}' oops.log
References: http://www.hypexr.org/linux_scp_help.php
Copy the file "foobar.txt" from the local host to a remote host
scp foobar.txt [email protected]:/some/remote/directory
To copy a directory:
scp -r "path/to/directory" [email protected]:/some/remote/directory
Copy your ssh key to another machine to avoid typing in passwords
ssh-copy-id -i ~/.ssh/id_rsa.pub remote-host
Alternatively use my script the_keymaker.sh
to automate this process a bit. Also maintains a nicer ssh config file.
untar
tar -xvf filename
Find all the processes that contain a word, such as all python processes
ps aux | grep <search string>
- shows a lot of output including the path of the file and args (more detailed)
ps -e | grep <search string>
- shows the PID and the process name (much cleaner)
Parallelize processes.
Using the code below command1 and command2 will be run in the background and command3 will be run normally. The benefit is when a SIGINT (via ^C
) is sent, all 3 commands will be killed.
trap 'kill %1 kill %2' SIGINT
command1 & command2 & command3
Use status code to determine if that line of text exists in that file.
grep -Fxq "line of text" /path/to/file
Search a directory recursively for a term. (Ignores case, only searches text files, and shows a line above and below the matched term)
grep -ainr -B 1 -A 1 "TERM" /DIR/TO/SEARCH
If you want to move everything in the current working directory into a sub-folder named newdir
and want an exit status code of 0
, you can't use mv
because it will try to move newdir
into itself and error. Instead use this
find . -maxdepth 1 ! -path . | grep -v "newdir" | xargs -i mv {} newdir
- Woof
- Simple file server
- mpv
- Commandline media player
- tmux
- Terminal multiplexer. Better than screen (debatably) and useful for servers.
- jq
- like
sed
for JSON data
- like
- Eventually split this into better chunks/files.
- Add useful snippets for diffregits