Table of Contents

Resize image using imagemagick

source: .http://www.cyberciti.biz/faq/bash-loop-over-file/

   
   for f in *.c; do echo "Processing $f file.."; done
#!/bin/bash
FILES=/path/to/*
for f in $FILES
do
  echo "Processing $f file..."
  # take action on each file. $f store current file name
  cat $f
done

convert rose.jpg -resize 50% rose.png

cannon raw image cr2

http://marc.merlins.org/linux/technotes/cr2_dcraw_jhead.html

yum install dcraw
for i in *.cr2; do dcraw -c -q 0 -w -H 5 -b 8 $i | cjpeg -quality 80 > $i.jpg; done

mkdir jpgs
for i in *.CR2; do dcraw -c -q 3 -w -H 5 -b 10 $i | cjpeg -quality 90 > ./jpgs/$i.jpg; done
 

Watch dd

source: .http://de.wikipedia.org/wiki/Dd_%28Unix%29

sudo killall -USR1 dd

Alternatively, you can use the watch command to execute kill at a set interval.

watch -n 2 kill -USR1 8789
watch -n 2 killall -USR1 dd

   

Convert ogv to mp4

ffmpeg -i INPUT -vcodec libx264 "OUTPUT.mp4"
ffmpeg -i openstack_workflow_cem.ogv -vcodec mpeg4 -qscale 0 -acodec libmp3lame openstack_workflow_cem.avi

Append Date time to filename

  now=$(date +"%m_%d_%Y")
  echo "Filename : /nas/backup_$now.sql"
  

Perl modules installation

.https://developer.fedoraproject.org/tech/languages/perl/perl-modules.html

1. Tee

tee: read from stdin and write to stdout AND file.

 ls -lsa | tee outfile

The following command will take a backup of the crontab entries, and pass the crontab entries as an input to sed command which will do the substituion. After the substitution, it will be added as a new cron job.

 crontab -l | tee crontab-backup.txt | sed 's/old/new/' | crontab –

2. Multiple default routes ip

2.1 Linux command

To view all the current rules, use the ip command as shown below:

# ip rule show
0:      from all lookup local
32766:  from all lookup main
32767:  from all lookup default

First, take a backup of the rt_Tables before making any changes.

cd /etc/iproute2
cp rt_tables rt_tables.orig

Next, create a new policy routing table entry in /etc/iproute2/rt_tables file:

echo "1 admin" | sudo tee -a /etc/iproute2/rt_tables

Remove old routes

  sudo ip route del 192.168.124.0/24
  sudo ip route del default via 192.168.124.1

Now add the routing entries in the admin table.

sudo ip route add 192.168.124.0/24 dev eth3 src 192.168.124.106 lookup main
ip route add default via 192.168.124.1 dev eth3 lookup admin

All the rules are executed in the ascending order. So, we will add rule entries above the “main” table.

ip rule add from 192.168.124.106/24 table admin
ip rule add to 192.168.124.106/24 table admin
ip route flush cache

Check the results

  ip route list table admin
  ip rule show

To make these changes persistent across reboot, you can add these commands to /etc/init.d/boot.local (for SUSE Linux), or /etc/rc.d/rc.local (for Redhat, CentOS).

2.2 Netplan

cat /etc/netplan/50-cloud-init.yaml 
# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    renderer: networkd
    ethernets:
        eth0:
            dhcp4: yes
        eth1:
            dhcp4: yes
            dhcp4-overrides:
                route-metric: 50
        eth2:
            dhcp4: yes
        eth3:
            dhcp4: yes
            dhcp4-overrides:
                route-metric: 100
            routing-policy:
                - from: 192.168.124.0/24
                  table: 200
                - to: 192.168.124.0/24
                  table: 200
            routes:
                - to: 0.0.0.0/0
                  via: 192.168.124.1
                  table: 200
    version: 2

Journal show Logs

ls /var/log

The gnome-system-log or Gnome System Log viewer can be very useful tools to view system log files on Fedora Linux Desktop (Gnome Desktop).

Open Gnome System Log using command:

Open the terminal on Linux Fedora desktop.

Execute the su -c "yum install gnome-system-log"

Execute gnome-system-log

the Gnome System Log viewer you enable you to view…

/var/log/cron - the cron log file /var/log/messages - the messages log file /var/log/secure - the secure log file /var/log/Xorg.0.log - the Xorg.0.log log file

and much more ….

On Fedora 20+, we use journalctl by default. Regular files such as /var/log/messages are no longer available by default. Of course, you can install rsyslog and journalctl will generate them for you if you want. journalctl itself has many many options. For example, you can filter the log based on different criteria. You can view the current or previous boot logs using the -b flag. Here are some examples from man journalctl (Please read the man page for more detailed information on the available options):

Without arguments, all collected logs are shown unfiltered:

journalctl

With one match specified, all entries with a field matching the expression are shown:

journalctl SYSTEMDUNIT=avahi-daemon.service

If two different fields are matched, only entries matching both expressions at the same time are shown:

journalctl SYSTEMDUNIT=avahi-daemon.service _PID=28097

If two matches refer to the same field, all entries matching either expression are shown:

journalctl SYSTEMDUNIT=avahi-daemon.service SYSTEMDUNIT=dbus.service

If the separator “+” is used, two expressions may be combined in a logical OR. The following will show all messages from the Avahi service process with the PID 28097 plus all messages from the D-Bus service (from any of its processes):

journalctl SYSTEMDUNIT=avahi-daemon.service PID=28097 + _SYSTEMDUNIT=dbus.service

Show all logs generated by the D-Bus executable:

journalctl /usr/bin/dbus-daemon

Show all logs of the kernel device node /dev/sda:

journalctl /dev/sda

Show all kernel logs from previous boot:

journalctl -k -b -1

There's also the new gnome-logs package in Fedora that's a frontend to journalctl but it looks like it's only available in F21+

tar

List content:

 tar -vztf ~/Downloads/eclipse-jee-kepler-SR2-linux-gtk-x86_64.tar.gz 
 

extract gz

 tar -C target_dir -xvzf ~/Downloads/eclipse-jee-kepler-SR2-linux-gtk-x86_64.tar.gz   

extract bz

 tar -C target_dir -xvjf ~/Downloads/eclipse-jee-kepler-SR2-linux-gtk-x86_64.tar.gz   

2>&1

In a unix shell, if I want to combine stderr and stdout into the stdout stream for further manipulation, I can append the following on the end of my command:

 2>&1
 

'head' on the output of g++:

 g++ lots_of_errors 2>&1 | head
 

1 is stdout. 2 is stderr.

Here is one way to remember this construct (altough it is not entirely accurate): at first, 2>1 may look like a good way to redirect stderr to stdout. However, it will actually be interpreted as “redirect stderr to a file named 1”. & indicates that what follows is a file descriptor and not a filename. So the construct becomes: 2>&1.

3. Change shell

Change user shell. As normal user.

chsh -s /bin/bash

As super user

chsh -s /bin/bash username

reset Terminal colors

reset
stty sane
tput init
tput reset

Networking

  ip addr show
  
  #delete addr
  ip addr del 192.168.50.5/24 dev eth1
  
  # enable
  ip link set eth1 up
  ip link set eth1 down
  
  # route table
  ip route show
  
  # add static route
  ip route add 10.10.20.0/24 via 192.168.50.100 dev eth0
  ip route del 10.10.20.0/24

Add persisted static route

Fedora:

 # vi /etc/sysconfig/network-scripts/route-eth0
 10.10.20.0/24 via 192.168.50.100 dev eth0

Debian:

  
  $ sudo vi /etc/network/interfaces
  auto eth0
  iface eth0 inet static
  address 192.168.50.2
  netmask 255.255.255.0
  gateway 192.168.50.100
  #########{Static Route}###########
  up ip route add 10.10.20.0/24 via 192.168.50.100 dev eth0
 

Mount davfs

.tubcloud.tu-berlin.de

nextcloud

C:\Users\Gordon>php -S 127.0.0.1:80 -t .
PHP 5.4.0 Development Server started at Sun Sep 02 14:20:28 2012
Listening on 127.0.0.1:80
Document root is C:\Users\Gordon
Press Ctrl-C to quit.
 python SimpleHTTPServer
 

Recovery from Power Outage

  yum history sync
  
  yum history list
[root@devnetwork fedora]# yum history list 
Loaded plugins: langpacks, refresh-packagekit
ID     | Command line             | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
    27 | history redo force-reins | 2015-01-28 17:46 | Reinstall      |    1   
    26 | -d 0 -e 0 -y install ope | 2015-01-28 17:33 | Install        |    1   
    25 | -d 0 -e 0 -y install ope | 2015-01-28 17:33 | Install        |    1   
    24 | -d 0 -e 0 -y install ope | 2015-01-28 17:33 | Install        |    1   
    23 | -d 0 -e 0 -y install ope | 2015-01-28 17:33 | Install        |    1   
    22 | -d 0 -e 0 -y install ope | 2015-01-28 17:33 | Install        |    2   
    21 | erase openstack-*        | 2015-01-28 17:32 | Erase          |    6 EE
    20 | -d 0 -e 0 -y install ope | 2015-01-28 17:27 | Install        |    1   
    19 | -d 0 -e 0 -y install ope | 2015-01-28 17:27 | Install        |    1   
    18 | erase openvswitch*       | 2015-01-28 17:26 | Erase          |    1 EE
    17 | update                   | 2015-01-28 17:04 | I, U           |  196 EE
    16 | -d 0 -e 0 -y install ope | 2015-01-28 17:00 | Install        |    1   
    15 | -d 0 -e 0 -y install ope | 2015-01-28 17:00 | Install        |    1  <
    14 | -d 0 -e 0 -y install ope | 2015-01-28 11:06 | Install        |    1 > 
    13 | -d 0 -e 0 -y install ope | 2015-01-28 11:06 | Install        |    1   
    12 | -d 0 -e 0 -y install ope | 2015-01-28 11:05 | Install        |   23   
    11 | -d 0 -e 0 -y install ntp | 2015-01-28 11:05 | Install        |    2   
    10 | -d 0 -e 0 -y install hap | 2015-01-28 11:05 | Install        |    1   
     9 | -d 0 -e 0 -y install ope | 2015-01-28 11:05 | Install        |    1   
     8 | -d 0 -e 0 -y install pyt | 2015-01-28 11:04 | Install        |   54   


Read the fine manual page and try the yum history commands.

The redo command might not work when it thinks that the packages are already installed, but after a rollback you should be able to (re)install the group. you can use the force-reinstall option on the yum history redo command

wget scrawl website

wget -r -np -l 1 -A zip http://example.com/download/
Options meaning:

-r,  --recursive          specify recursive download.
-np, --no-parent          don't ascend to the parent directory.
-l,  --level=NUMBER       maximum recursion depth (inf or 0 for infinite).
-A,  --accept=LIST        comma-separated list of accepted extensions.

Screen

.http://www.cyberciti.biz/tips/linux-screen-command-howto.html

Diff, patch merge files

ou don't need patch for this; it's for extracting changes and sending them on without the unchanged part of the file.

The tool for merging two versions of a file is merge, but as @vonbrand wrote, you need the "base" file from which your two versions diverged. To do a merge without it, use diff like this:

diff -DVERSION1 file1.xml file2.xml > merged.xml
It will enclose each set of changes in c-style #ifdef/#ifndef, like this:

#ifdef VERSION1
<stuff added to file1.xml>
#endif
...
#ifndef VERSION1
<stuff added to file2.xml>
#endif
If a line or region differs between the two files, you'll get a "conflict", which looks like this:

#ifndef VERSION1
<version 1>
#else /* VERSION1 */
<version 2>
#endif /* VERSION1 */
So save the output in a file, and open it in an editor. Search for any places where #else comes up, and resolve them manually. Then save the file and run it through grep -v to get rid of the remaining #if and #end tags:

grep -v '^#if' merged.xml | grep -v '^#endif' > clean.xml
In the future, save the original version of the file. merge can give you much better results with the help of the extra information. (But be careful: merge edits one of the files in-place, unless you use -p. Read the manual).

lsof

.http://www.akadia.com/services/lsof_quickstart.txt

List deleted files

  lsof -a +L1 mountpoint
  ...
  java      30255       demo    1w   REG  252,0 24105963520     0  131115 /home/demo/imacatlogs/catalina.out (deleted)
  

See which process causes that

  ps aux | grep 30255
  netstat -ntlp | grep 30255
  tcp6       0      0 :::50480                :::*                    LISTEN      30255/java  
  

Remove (deleted) files

use lsof to find the deleted, but open, file still consuming space

    lsof | grep deleted | grep etilqs_1IlrBRwsveCCxId
    chrome     3446       user  128u      REG              253,2              16400    2364626 /var/tmp etilqs1IlrBRwsveCCxId (deleted)  

find the entry in /proc/fd/ that cooresponds to the filehandle

    ls -l /proc/3446/fd/etilqs_1IlrBRwsveCCxId
    lrwx------. 1 user unix 64 Feb 11 15:31 128 -> /var/tmp/etilqs_1IlrBRwsveCCxId (deleted)

now, just cat /dev/null into the fd

cat /dev/null > /proc/3446/fd/128

Note that the inode is still open, but now it's 0 length

chrome     3446       user  128u      REG              253,2         0    2364626

Get streaming Firefox file

Get the process id

  ps aux | grep firefox
  ps aux | grep firefox
  dang      3224 10.5 18.7 4975896 3043840 tty2  Rl+  Dec06 811:15 /usr/lib64/firefox/firefox
  root     10006  0.0  0.0 114332  2320 pts/0    S+   19:51   0:00 grep --color=auto firefox
  dang     31850  1.3  1.7 1342864 287844 tty2   Sl+  Dec09  43:13 /usr/lib64/firefox/plugin-container /usr/lib64/flash-plugin/libflashplayer.so -greomni /usr/lib64/firefox/omni.ja -appomni /usr/lib64/firefox/browser/omni.ja -appdir /usr/lib64/firefox/browser 3224 true plugin

31850 is the process

  ls -ls /proc/31850/fd
  

This will show the /tmp/Flash…

.http://www.ibm.com/developerworks/aix/library/au-lsof.html

Alternatives

[root@dai142 gtarc_auvegos]# alternatives --config javaws

There are 3 programs which provide 'javaws'.

  Selection    Command
-----------------------------------------------
*  1           /usr/java/latest/jre/bin/javaws
   2           /usr/java/jdk1.8.0_66/jre/bin/javaws
 + 3           /usr/java/jdk1.8.0_66/bin/javaws

Enter to keep the current selection[+], or type selection number: 
[root@dai142 gtarc_auvegos]# alternatives --remove javaws /usr/java/jdk1.8.0_66/jre/bin/javaws
[root@dai142 gtarc_auvegos]# alternatives --config javaws

There are 2 programs which provide 'javaws'.

  Selection    Command
-----------------------------------------------
*  1           /usr/java/latest/jre/bin/javaws
 + 2           /usr/java/jdk1.8.0_66/bin/javaws

Enter to keep the current selection[+], or type selection number: 
[root@dai142 gtarc_auvegos]# 

4. Disable suspend on laptop

5. Latex

Boot kernel version

Comments:

Run grubby to see a list of bootable kernels:

  grubby --info=ALL | grep '^title=' | sed 's/title=//'

Imagine these are numbered 1, 2, 3, etc. Set a variable to capture the title using the sed command. This example uses

sed -n 2p

for the #2 kernel, but you could substitute 3 or whatever instead:

NEWDEFAULT=$(!! | sed -n 2p)

Check to make sure the variable is a kernel title. If not, do the above two commands again correctly, one following the other immediately.

echo ${NEWDEFAULT}

Replace the default in the GRUB defaults file:

sudo sed -i "s/GRUB_DEFAULT=.*/GRUB_DEFAULT="${NEWDEFAULT}"/"

Rewrite the GRUB configuration:

sudo grub2-mkconfig -o /boot/grub2/grub.cfg

the above rewrite command for GRUB only applies for legacy BIOS installations with MBR partition layout.

EFI with GPT layout system users should do the following instead

grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg

Now you can reboot into the locked kernel. The above process works independently of versionlock. It uses a kernel title instead of a numbered slot, so that if kernel index order changes, the desired default should still boot.