Category: Bash / Terminal / Scripts

14.07.2017

display ip and ip only of the host computer the script is running on. ifconfig eth0|grep inet| awk ‘{print $2}’ | cut -d: -f2 172.20.0.8 root@debian9:~# IP=$(ifconfig eth0|grep inet| awk ‘{print $2}’ | cut -d: -f2); echo $IP; 172.20.0.8

05.07.2017

there are some special automatically set environment variabels that might be interesting to know… echo $$; # PID of currently running shell echo $?; # return error code of last run program (before echo) echo $0; # return /path/and/way the […]

13.06.2017

vi countdown.sh; # create a new file with those lines #!/bin/bash COUNT=10 while (( COUNT > 0 )) do      echo -e “$COUNT \c”     sleep 1;     (( COUNT — )) done echo -e “\n\nWe have lift off!!” ESC […]

09.06.2017

# all these commands will modify /etc/passwd su – root # disable login for user usermod -s /usr/sbin/nologin username # change login-shell of username to bash usermod -s /bin/bash username # change login-shell of username to sh usermod -s /bin/sh […]

07.06.2017

 stat /etc/hosts   File: ‘/etc/hosts’   Size: 249             Blocks: 8          IO Block: 4096   regular file Device: 801h/2049d      Inode: 5506941     Links: 1 Access: (0644/-rw-r–r–)  Uid: (    0/    root)   Gid: (    0/    root) Access: 2017-06-06 15:37:06.896148382 +0200 Modify: 2017-06-06 15:37:04.728130437 +0200 Change: […]

apt cheat sheet
06.06.2017

about package.deb & apt update: 2025-01: apt got a massive rewrite in Debian 13 Trixie (66% C++ 30% shell) # check the changelog with su – root apt-get changelog apt Apt is a mainly-online-repository-based (“AppStore”) software installation & package management […]

xargs
30.05.2017

one practical usage example of xargs: … to process every file that find found further # this would backup/pack all jpg files on your system into all.jpg.tar.gz find / -name “*.jpg” | xargs tar -czvf all.jpg.tar.gz # delete all jpg […]

GNU Linux howto lvm lvm2 logical volumen management + concept + man pages + dynamic resizing partitions + snapshots + how to upgrade lvm2 encrypted to larger harddisk – what physical blockdevice is used for what logical volume?
29.05.2017

lvm2 concept: tested on: debian 8-9 and compatible, manpages from centos7/rhel7 in general backup! backup! backup! before fiddeling with partitions and the filesystem… logical volumes basically allow you to span partitions over several disks/partitions as well as resize those partitions. […]

24.05.2017

what is umask? umask defines what what access rights newly created files “are born”. we are all supposed to be created equal – but depending if you are a son of Rothchild, Rockefeller or born in Namibia – your previleges […]

Yum cheat sheet – the future of Yum is Dnf
24.05.2017

update: 2021-1 yum -> dnf hostnamectl; # tested on Virtualization: kvm Operating System: CentOS Linux 8 CPE OS Name: cpe:/o:centos:centos:8 Kernel: Linux 5.4.11 Architecture: x86-64 ll /usr/bin/yum -> dnf-3 all those yum commands still work with dnf (nice work!) DNF […]

23.05.2017

reboot [cc lang=”bash” escaped=”true” width=”600″] reboot; # simply reboots the system 😉 init 6; # does the same telinit 6; # shutdown -r now; # “standard” way shutdown -r +1 “the system is going to reboot in one minute”; # […]

22.05.2017

Table 4-1. Regular expression operators Operator Effect . Matches any single character. ? The preceding item is optional and will be matched, at most, once. * The preceding item will be matched zero or more times. + The preceding item […]

22.05.2017

cool apt-get install fortune cowsay; # will have to be installed first then you can let your dinosaur speak 😀  /usr/games/cowsay -f stegosaurus “Hello World”  _____________ < Hello World >  ————- \                             .       .  \                           / `.   .’ ”   […]

19.05.2017

these commands are equally valid, both commands add “content” to the end of file – if file does not exists it will be created. ls -l . /ect > listing.txt #send the output from ls -l to a file called […]

gnu linux server and partitioning – stability and security
19.05.2017

yeah one knows sometimes making fun of distributions that have a partition for every /root/folder but well yes it has it’s reasons, like when a program accumulates to much data (mailbox full), the /root partition and the system will not […]

19.05.2017

there are plenty 😀 debian8.8 [cc lang=”bash” escaped=”true” width=”600″] uname -a; # tested with Linux debian 3.16.0-4-686-pae #1 SMP Debian 3.16.43-2 (2017-04-30) i686 GNU/Linux find / -type d -iname bin /bin /usr/local/bin /usr/bin /usr/share/doc/libintl-perl/examples/simplecal/bin /usr/lib/klibc/bin [/cc] suse12 [cc lang=”bash” escaped=”true” […]

19.05.2017

rpm is a powerful Package Manager for Red Hat, Suse and Fedora Linux. It can be used to build, install, query, verify, update, and remove/erase individual software packages. A Package consists of an archive of files, and package information, including […]