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 […]

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 sheed
06.06.2017

About: apt is a mainly-online-repository-based („AppStore“) software installation – package management system used by Debian and Ubuntu. But – you can also manually download a package.deb and install it with dpkg -i package.deb. What might be confusing – it consists […]

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 […]

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 […]

24.05.2017

What is yum? yum is used under CentOS7, Fedora, RedHat RHEL, Oracle). It’s written in python and it stands for “Yellowdog Updater, Modified”, as it was originally called “yup”, the package manager for Yellow Dog Linux. In addition to rpm […]

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

vim stresscpu.sh; # create new script file #!/bin/bash while true; do echo -n "+."; done; save and quit chmod u+x stresscpu.sh; # mark it runnable nohup stresscpu.sh & # run in background htop # streeeeeeessss! it is also a harddisk-stress […]

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 >  ————- \                             .       .  \                           / `.   .‘ “   […]

21.05.2017

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 vim /scripts/partitions_overview.sh; # create new script #!/bin/bash PARTITIONS=/dev/sd* for f in $PARTITIONS do   echo "_______________________________________________________________________________"   blkid $f   hdparm -I $f | grep […]

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 […]

19.05.2017

yeah i know i sometimes make fun of distributions that have like a partition for every /root/folder but well yes it has it’s reasons. suse12 uname -a; # tested with Linux suse 4.4.21-69-default #1 SMP Tue Oct 25 10:58:20 UTC […]

19.05.2017

there are plenty 😀 debian8.8 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 suse12 uname -a; # tested with Linux suse 4.4.21-69-default […]

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 […]

16.05.2017

messing with text files test content # test if /path/file contains SEARCH_PATTERN if grep -q SEARCH_PATTERN „/path/file“; then cat /path/file; # do something fi paste basically line-wise combines two files into one. (first line of two files will end up […]