Random useful Linux stuff
Exiting VIM
:wq
or :x
The only commands you need to know - then switch to Emacs.
Random Linux stuff
sha256sum file | diff - shafile # generate sha-256
export PATH=$PATH:~/opt/bin:~/opt/node/bin # export PATH
history -c # reset history
reset
time
time a.out
# real 0m0.003s # user + system: often 'stopwatch'
# not 'accurate' - fork(), program might
# not be running at all
# user 0m0.000s # in userland
# sys 0m0.001s # kernel time e.g. syscalls, interrupts
Adding user to another group
usermod -aG additional_groups username
Be sure you don't omit the
-a
flag, otherwise it will also remove the user from groups not inadditional_groups
List of groups in
/etc/groups
Adding your scripts to PATH
Create your
~/bin
directoryIn your
.bashrc
, add it to yourPATH=$PATH:~/bin
(this is appending it to PATH)Add a shebang
#!/bin/bash
to your scriptBetter to use
#!/usr/bin/env bash
Give it exec permissions:
chmod +x script
Redirection
./somescript >/dev/null 2>&1
To break it up:
2
is the handle for standard error orSTDERR
1
is the handle for standard output orSTDOUT
2>&1
is asking to direct all theSTDERR
asSTDOUT
, (i.e. to treat all the error messages generated from the script as its standard output).Now we already have
>/dev/null
at the end of the script which means allSTDOUT
will be written to/dev/null
.Since
STDERR
is now going toSTDOUT
(because of2>&1
) bothSTDERR
andSTDOUT
go to/dev/null
.
File handlers
Integer value
Name
<unistd.h>
symbolic constant
<stdio.h>
file stream
0
Standard input
STDIN_FILENO
stdin
1
Standard output
STDOUT_FILENO
stdout
2
Standard error
STDERR_FILENO
stderr
Last updated