This is your very common but also important one-liners that helps you get the job done using shell/bash commands.
cat /tmp/testerror.txt | tail -n30 | awk '{ sub($2, "19:55:01") }1' >> /var/log/mailarchiva/core/debug/debug.log
. | | | | | \
. | | | | | \
. | | | | | \
. | | | | | \
. | / / | \ \
. | / / | \ \
. | / / | \ \
. | | / | \ \
. | | / | \ \
. | | / | | \
. | | / | | \
. | | | | | \
. | | | | | \
. | | | | | \
. | | | | | \
. | | | | | \
grep current file | show last 30 lines | substitute | 2ndfield | with time of 19:55:01 | only first occuorance
awk '!NF {print;next}; !($0 in a) {a[$0];print}' file-Name
openssl enc -ciphers | grep aes | tr -s ' ' '\n'0
for TTT in `seq 01 37`; do TTT=$( printf '%02d\n' ${TTT} );
echo "We will touch: ${TTT}"; echo " file: $(ls -n | tr -s [:space:] | cut -d' ' -f9- | grep ${TTT}\- ) ";
FILES="$(ls -n | tr -s [:space:] | cut -d' ' -f9- | grep ${TTT}\- )"; touch "$FILESS";
sleep 1;done
just add the below to /etc/fstab
tmpfs /var/lib/spamban/tmp tmpfs rw,noatime,size=100M 0 0
#-OR- run
mount -t tmpfs -o rw,noatime,remount,size=100M tmpfs /var/lib/spamban/tmp tmpfs
journalctl -xr "_SYSTEMD_UNIT=icinga2.service"
-- Logs begin at Sat 2017-03-04 23:14:49 SAST, end at Sat 2017-03-04 23:35:07 SAST. --
Mar 04 23:25:16 monitoring.raffbrains.com icinga2[4422]: .
Mar 04 23:25:16 monitoring.raffbrains.com icinga2[4422]: [2017-03-04 23:25:16 +0200] information/ConfigItem: Checked 1
Mar 04 23:25:16 monitoring.raffbrains.com icinga2[4422]: [2017-03-04 23:25:16 +0200] information/ConfigItem: Checked 1
Mar 04 23:25:16 monitoring.raffbrains.com icinga2[4422]: [2017-03-04 23:25:16 +0200] information
modify /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="net.ifnames=0 biosdevname=0 ipv6.disable=1"
uname -a # Get the kernel version (and BSD version)
lsb_release -a # Full release info of any LSB distribution
cat /etc/debian_version # Get Debian version
Use /etc/DISTR-release with DISTR= lsb (Ubuntu) /etc/issue.
uptime # Show how long the system has been running + load
hostname # system's host name
hostname -i # Display the IP address of the host.
man hier # Description of the file system hierarchy
last reboot # Show system reboot history
dmesg # Detected hardware and boot messages
lsdev # information about installed hardware
dd if=/dev/mem bs=1k skip=768 count=256 2>/dev/null | strings -n 8 # Read BIOS
cat /proc/cpuinfo # CPU model
cat /proc/meminfo # Hardware memory
grep MemTotal /proc/meminfo # Display the physical memory
watch -n1 'cat /proc/interrupts' # Watch changeable interrupts continuously
free -m # Used and free memory (-m for MB)
cat /proc/devices # Configured devices
lspci -tv # Show PCI devices
lsusb -tv # Show USB devices
lshal # Show a list of all devices with their properties
dmidecode # Show DMI/SMBIOS: hw info from the BIOS
The following commands are useful to find out what is going on on the system.
top # display and update the top cpu processes
mpstat 1 # display processors related statistics
vmstat 2 # display virtual memory statistics
iostat 2 # display I/O statistics (2 s intervals)
systat -vmstat 1 # BSD summary of system statistics (1 s intervals)
systat -tcp 1 # BSD tcp connections (try also -ip)
systat -netstat 1 # BSD active network connections
systat -ifstat 1 # BSD network traffic through active interfaces
systat -iostat 1 # BSD CPU and and disk throughput
sar -r -s 06:00:00 -e 07:00:00 -f /var/log/sa/sa18 # find out on the 18th of the month between 06 - 07 am with memory
sar -u -s 06:00:00 -e 07:00:00 -f /var/log/sa/sa18 # find out on the 18th of the month between 06 - 07 am with CPU
tail -n 500 /var/log/messages # Last 500 kernel/syslog messages
tail /var/log/warn # System warnings messages see syslog.conf
id # Show the active user id with login and group
last # Show last logins on the system
who # Show who is logged on the system
groupadd admin # Add group "admin" and user colin
useradd -c "Colin Barschel" -g admin -m colin
usermod -a -G # Add existing user to group (Debian)
userdel colin # Delete user colin
groupmod admin -m newmember # Add a new member to a group
useradd colin -c "Colin Barschel" -g admin -m -s /bin/tcsh
userdel colin; groupdel admin
passwd -d username # Clear or Delete the password of the user(to allow only Key-auth)
lsmod # List all modules loaded in the kernel
modprobe isdn # To load a module (here isdn)
modinfo wmi
cd /usr/src/linux
make mrproper # Clean everything, including config files
make oldconfig # Reuse the old .config if existent
make menuconfig # or xconfig (Qt) or gconfig (GTK)
make # Create a compressed kernel image
make modules # Compile the modules
make modules_install # Install the modules
make install # Install the kernel
So you broke grub? Boot from a live cd, [find your linux partition under /dev and use fdisk to find the linux partion] mount the linux partition, add /proc and /dev and use grub-install /dev/xyz. Suppose linux lies on /dev/sda6:
mount /dev/sda6 /mnt # mount the linux partition on /mnt
mount --bind /proc /mnt/proc # mount the proc subsystem into /mnt
mount --bind /dev /mnt/dev # mount the devices into /mnt
chroot /mnt # change root to the linux partition
grub-install -v --allow-floppy --boot-directory /run/media/raffbrains/940D-2B0B --recheck --removable --target x86_64-efi --efi-directory /run/media/raffbrains/940D-2B0B /dev/sda # reinstall grub with your old settings
Each process has a unique number, the PID. A list of all running process is retrieved with ps.
ps -auxefw # Extensive list of all
ps axww | grep cron
586 ?? Is 0:01.48 /usr/sbin/cron -s
ps axjf # All processes in a tree format
ps aux | grep 'ss[h]' # Find all ssh pids without the grep pid
pgrep -l sshd # Find the PIDs of processes by (part of) name
echo $$ # The PID of your shell
fuser -va 22/tcp # List processes using port 22 (Linux)
pmap PID # Memory map of process (hunt memory leaks) (Linux)
fuser -va /home # List processes accessing the /home partition
strace df # Trace system calls and signals
truss df # same as above
fuser -mv /home # List processes accessing /home
lsof +d /home # List processes accessing /home
lsof / | egrep -i 'del.*libpam\.so' # list of processes waiting to be closed
Terminate or send a signal with kill or killall.
kill -s TERM 4712 # same as kill -15 4712
killall -1 httpd # Kill HUP processes by exact name
pkill -9 http # Kill TERM processes by (part of) name
pkill -TERM -u www # Kill TERM processes owned by www
fuser -k -TERM -m /home # Kill every process accessing /home (to umount)
Important signals are:
======================
1 HUP (hang up)
2 INT (interrupt)
3 QUIT (quit)
9 KILL (non-catchable, non-ignorable kill)
15 TERM (software termination signal)
Change permission and ownership with chmod and chown. The default umask can be changed for all users in /etc/profile for Linux. The default umask is usually 022. The umask is subtracted from 777, thus umask 022 results in a permission 0f 755.
1 --x execute # Mode 764 = exec/read/write | read/write | read
2 -w- write # For: |-- Owner --| |- Group-| |Other|
4 r-- read
ugo=a u=user, g=group, o=others, a=everyone
chmod [OPTION] MODE[,MODE] FILE # MODE is of the form [ugoa]*([-+=]([rwxXst]))
chmod 640 /var/log/maillog # Restrict the log -rw-r-----
chmod u=rw,g=r,o= /var/log/maillog # Same as above
chmod -R o-r /home/* # Recursive remove other readable for all users
chmod u+s /path/to/prog # Set SUID bit on executable (know what you do!)
find / -perm -u+s -print # Find all programs with the SUID bit
chown user:group /path/to/file # Change the user and group ownership of a file
chgrp group /path/to/file # Change the group ownership of a file
chmod 640 `find ./ -type f -print` # Change permissions to 640 for all files
chmod 751 `find ./ -type d -print` # Change permissions to 751 for all directories
hdparm -I /dev/sda # information about the IDE/ATA disk (Linux)
fdisk /dev/ad2 # Display and manipulate the partition table
smartctl -a /dev/ad2 # Display the disk SMART info
mount | column -t # Show mounted file-systems on the system
df -mT # display free disk space and mounted devices
cat /proc/partitions # Show all registered partitions
du -sh * # Directory sizes as listing
du -csh # Total directory size of the current directory
du -ks * | sort -n -r # Sort everything by size in kilobytes
mount -t tmpfs -osize=64m tmpfs /memdisk
ls -lSr # Show files, biggest last
ls -ltr # show files , last modifed show last
mount -t iso9660 -o loop file.iso /mnt # Mount a CD image
mount -t ext3 -o loop file.img /mnt # Mount an image with ext3 fs
for GITDIRS in $(find -maxdepth 1 -type d -print|grep './'); do echo $GITDIRS ; pushd $GITDIRS; git status ; popd; done
for GITDIRS in $(find -maxdepth 1 -type d -print|grep './'); do echo $GITDIRS ; pushd $GITDIRS; git push -u ; popd; done
To force diff to output similar to what you used to on git.
diff -prU3 --suppress-common-lines --left-column my-scripts oldscripts
Only in my-scripts: .git
diff -prU3 --suppress-common-lines --left-column my-scripts/localbash/bashrc oldscripts/localbash/bashrc
--- my-scripts/localbash/bashrc 2022-05-12 13:35:01.230649996 +0200
+++ oldscripts/localbash/bashrc 2022-05-10 00:15:31.566616017 +0200
@@ -85,11 +85,11 @@ fi
#Nice prompt from Parrot OS:
if [ "$color_prompt" = yes ]; then
- PS1="\[\033[0;31m\]\342\224\214\342\224\200\$([[ \$? != 0 ]] && echo \"[\[\033[0;31m\]\342\234\227\[\033[0;31m\]]\342\224\200\")[$(if [[ ${EUID} == 0
]]; then echo '\[\033[01;31m\]root\[\033[01;33m\]@\[\033[01;96m\]\h'; else echo '\[\033[0;34m\]\u\[\033[01;33m\]@\[\033[01;96m\]\h'; fi)\[\033[0;31m\]]\3
42\224\200[\[\033[0;32m\]\w\[\033[0;31m\]]\[\e[1;33m\] [\[\D{%Y-%m-%d %H:%M.%S}]\[\e[0m\]\n\[\033[0;31m\]\342\224\224\342\224\200\342\224\200\342\225\274\
356\202\260\[\033[0m\]\[\e[01;33m\]\$(_gp 2)\\$\[\e[0m\] "
+ PS1="\[\033[0;31m\]\342\224\214\342\224\200\$([[ \$? != 0 ]] && echo \"[\[\033[0;31m\]\342\234\227\[\033[0;31m\]]\342\224\200\")[$(if [[ ${EUID} == 0
]]; then echo '\[\033[01;31m\]root\[\033[01;33m\]@\[\033[01;96m\]\h'; else echo '\[\033[0;34m\]\u\[\033[01;33m\]@\[\033[01;96m\]\h'; fi)\[\033[0;31m\]]\3
42\224\200[\[\033[0;32m \360\237\223\202 \w\[\033[0;31m\]]\[\e[1;33m\] [\[\D{%Y-%m-%d %H:%M.%S}]\[\e[0m\]\n\[\033[0;31m\]\342\224\224\342\224\200\342\224\
200\342\225\274\356\202\260\[\033[0m\]\[\e[01;33m\]\$(_gp 2)\\$\[\e[0m\] "
#PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
#PS1="\[\033[0;31m\]\342\224\214\342\224\200\$([[ \$? != 0 ]] && echo \"[\[\033[0;31m\]\342\234\227\[\033[0;31m\]]\342\224\200\")[$(if [[ ${EUID} ==
0 ]]; then echo '\[\033[01;31m\]root\[\033[01;33m\]@\[\033[01;96m\]\h'; else echo '\[\033[0;34m\]\u\[\033[01;33m\]@\[\033[01;96m\]\h'; fi)\[\033[0;31m\]]\
342\224\200[\[\033[0;32m\]\w\[\033[0;31m\]]\[\e[1;33m\] [\[\D{%Y-%m-%d %H:%M.%S}]\[\e[0m\]\n\[\033[0;31m\]\342\224\224\342\224\200\342\224\200\342\225\274
\342\236\244 \[\033[0m\]\[\e[01;33m\]$(__git_ps1 " (%s)")\\$\[\e[0m\] "
- PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w (color-els)\$ '
+ PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w \$ '
fi
unset color_prompt force_color_prompt
To allow your ssh keys to be able to login to servers passwordless, a below onliner can help
cat ~/.ssh/id_rsa.pub | ssh <user>@<hostname> 'umask 0077; mkdir -p .ssh; cat >> .ssh/authorized_keys && echo "Key copied"'
OR using ssh tool
ssh-copy-id -i ~/.ssh/id_rsa <user>@<hostname>
xzcat 2022-04-04-raspios-bullseye-armhf-full.img.xz | sudo dd of=/dev/mmcblk0 conv=noerror,sync,notrunc obs=1024 status=progress
device="/dev/mmcblk0"
full_size=$(parted ${device} print | grep "Disk ${device}" | awk '{print $3}')
parted ${device} resizepart 2 ${full_size}
linux_partition=${device}p2
e2fsck -f ${linux_partition}
resize2fs ${linux_partition}
On new systemD booting systems, many still don't know how to switch between text and gui mode.
In the init.RC systems we used the init 3 and init 5 commands.
Below is how to do it in systemD.
Text mode
sudo systemctl isolate multi-user.target
GUI mode
sudo systemctl isolate graphical.target
Text
sudo systemctl set-default multi-user.target
Gui
sudo systemctl set-default graphical.target
echo | \
openssl s_client -servername www.myservername.com -connect www.myservername:443 2>/dev/null | \
openssl x509 -text
nc -l -k -p 8080 -c "nc 172.0.1.3 22"
-l listen
-k keep the connect alive
-p tcp port to listen on
-c forward by running this command forward to ip and port