- Reload bash profile
source ~/.bash_profile
- Display environment variable
echo $VARNAME
- Dir by date
ls -Ghaltr
- Copy with SCP
scp username@host:/some/remote/dir/\{a,b,c} ./
- Copy with SCP
scp {foo,bar}.txt username@host:/some/remote/dir/
- Generate SHA256 hash
openssl sha -sha256 <file>
- Status of network interfaces
netstat -i
(Local, Broadcast, Multicast, Promiscuous, Running, Up) - Set network promiscous mode
ifconfig eth0 promisc
- Show physical and logical network devices
iw dev
- Map logical network device to physical
iw phy phy0 interface add mon0 type monitor
- Update expired Kali repo keys
wget -q -O - https://archive.kali.org/archive-key.asc | apt-key add
- Biggest files and directories
du -ah /home | sort -hr | head -n 5
- IP Address on login screen - Add to /etc/issues
eth0: \4{eth0}
- Auto refresh a command -
watch [command]
- CentOS DeltaRPM -
yum install deltarpm
- Shell loop -
for f in *.txt; do echo "Processing $f file..."; done
- Byte revers file -
< file.gnp xxd -p -c1 | tac | xxd -p -r > file.png
/dev/tcp/host/port
If host is a valid hostname or Internet address, and port is an integer port number
or service name, bash attempts to open a TCP connection to the corresponding socket.
/dev/udp/host/port
If host is a valid hostname or Internet address, and port is an integer port number
or service name, bash attempts to open a UDP connection to the corresponding socket.
xenon-lornix:~> cat < /dev/tcp/127.0.0.1/22
SSH-2.0-OpenSSH_6.2p2 Debian-6
^C pressed here
-
Profiles Understanding .bashrc and .bash_profile
/etc/profile
is a global file that gets run before~/.profile
/etc/profile.d/
is a folder that contains scripts called by/etc/profile
When/etc/profile
is called (when you start/login a shell), it searches for any files ending in.sh
in/etc/profile.d/
and runs them with one of these commands:source /etc/profile.d/myfile.sh
. /etc/profile.d/myfile.sh
Putting00-
before the file name to make it execute before the rest of the scripts.
You can also add your aliases in/etc/profile
, but this isn't recommended.
-
Convert EPOCH time -
date -d @<timestamp>
-
Recursive Hashing - `find ./dir/ -type f -exec sha1sum {} \; > files.sha1
-
Recursive Hashing 2 - `find ./dir/ -type f -print0 | xargs -0 sha1sum > /files.sha1
-
Recursive Hashing 3 -
shopt -s globstar dotglob; sha1sum **
(Sets variables "globstar" for recursive match on **, and "dotglob" to enable matching hidden files) -
Time a command runtime -
time <command>
(Returns real/user/sys times) -
Set default editor -
export VISUAL=vim; export EDITOR="$VISUAL"
-
Test if is running from shell script
if !(systemctl -q is-active <service> )
then
echo "Service is not running."
exit 1
fi
- Test if user is running as root from shell script
if [[ $EUID -ne 0 ]]
then
echo "Must be run as root."
exit 1
fi
- interface to promiscuous mode:
ip link set eth1 promisc on
ifconfig eth1 promisc
Flags BMPRU will be updated:
B Broadcast
M Multicast
P Promiscuous
R Running
U Up