advanced-bash-techniques

JSON

rev 8  |  foxhop  |  1343046280000  |  JSON

rev 7
rev 8
6666
6767
nn68Get a coma separated list of libvirt guests
69==================================================
70 
71.. code-block:: bash
72 
73 virsh list | egrep -v 'Domain|Name|----|^$' | awk '{printf "%s," , $2}' > /tmp/
 >virthosts
6874
6975
7076
tt77 
78 
rev 7  |  foxhop  |  1333187242000  |  JSON

rev 6
rev 7
63.. code-block:: sed63.. code-block:: sed
6464
t65  sed -i'' -e 's/\:80/\:8080/g' *t65  sed -i'' -e 's/search/replace/g' *
6666
6767
rev 6  |  foxhop  |  1333187178000  |  JSON

rev 5
rev 6
5858
5959
tt60Bash sed search and replace multiple files one liner
61============================================================
62 
63.. code-block:: sed
64 
65  sed -i'' -e 's/\:80/\:8080/g' *
66 
67 
68 
69 
70 
rev 5  |  foxhop  |  1333063662000  |  JSON

rev 4
rev 5
3535
3636
tt37Bash Perl search and replace multiple files one liner
38=======================================================
39 
40.. code-block:: perl
41 
42 perl -pi -w -e 's/search/replace/g;' *.extension
43 
44explanation:
45 
46 **-e** 
47  means execute the following line of code.
48 
49 **-i**
50  means edit in-place
51 
52 **-w**
53  write warnings
54 
55 **-p**
56  loop
57 
58 
59 
rev 4  |  foxhop  |  1331682803000  |  JSON

rev 3
rev 4
26   done26   done
2727
t28apache logs count uniquet28apache logs count unique ip addresses
29=============================29=========================================
3030
31.. code-block:: bash 31.. code-block:: bash 
rev 3  |  foxhop  |  1331682699000  |  JSON

rev 2
rev 3
26   done26   done
2727
tt28apache logs count unique
29=============================
30 
31.. code-block:: bash 
32 
33 sudo cat access.log | awk '{ print $1; }' | sort | uniq -c | sort -n
34 
35 
36 
rev 2  |  foxhop  |  1331675006000  |  JSON

rev 1
rev 2
1313
14 sudo find . -type d -print0 | xargs -0 sudo chmod 077514 sudo find . -type d -print0 | xargs -0 sudo chmod 0775
tt15 
16Remove a particular line from all files in a directory
17============================================================
18 
19.. code-block:: bash
20 
21 for file in /tmp/test/*
22   do
23     cp -p $file $file.tmp
24     egrep -v "RegexToRemove" $file.tmp > $file
25     rm -rf $file.tmp
26   done
27 
rev 1  |  foxhop  |  1308529956000  |  JSON

empty
rev 1
tt1advanced bash techniques
2============================
3 
4find and change all files:
5 
6 sudo find . -type f -print0 | xargs -0 ls -hal
7 
8 sudo find . -type f -print0 | xargs -0 sudo chown www-data:www-data
9 
10 sudo find . -type f -print0 | xargs -0 sudo chmod 0644
11 
12find and change all directories:
13 
14 sudo find . -type d -print0 | xargs -0 sudo chmod 0775