This post contains some tips and tricks that helps resolve problems that i've encountered when working with Linux, mostly Ubuntu.
Some of my applications are 32 bits only which sometime depend on several 32 bits libraries. By default, ubuntu installed only the 64 bits version of these libraries. To installed the 32 bit ones, we need enable the i386 architecture using dpkg
, these following commands should be executed as root:
dpkg --add-architecture i386
apt-get update
Then to install a 32 bits version of a library:
apt-get install lib_name:i386
# for example
apt-get install libcairo2:i386
This is a copy of an answer found from StackOverflow.
Do the following:
grep -rnw '/path/to/somewhere/' -e "pattern"
Along with these, --exclude, --include, --exclude-dir or --include-dir parameters could be used for efficient searching:
This will only search through the files which have .c or .h extensions:
grep --include=\*.{c,h} -rnw '/path/to/somewhere/' -e "pattern"
grep --exclude=*.o -rnw '/path/to/somewhere/' -e "pattern"
grep --exclude-dir={dir1,dir2,*.dst} -rnw '/path/to/somewhere/' -e "pattern"
Move the file out of git and simply remove the file from the git cache with the following command:
git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch path/to/large/file.ext'
#! /bin/sh
iptables --append OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# create a new chain
iptables --new-chain chk_demo_user
# use new chain to process packets generated by apache
iptables -A OUTPUT -m owner --uid-owner demo -j chk_demo_user
# allow user use the port 5901
iptables -A chk_demo_user -p tcp --syn -d 127.0.0.1 --dport 5901 -j RETURN
# reject everything else and stop hackers downloading code into our server
iptables -A chk_demo_user -j REJECT
Extracting the partition information from the image using fdisk:
$ fdisk -lu image.img
Disk image.img: 4096 MB, 4096000000 bytes, 8000000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000a1bc7
Device Boot Start End Blocks Id System
image.img1 2048 5872026 5869978 b W95 FAT32
We see, that the partition has a size of about 2,8Gb (5872026 * 512), the rest is unpartitioned.
So, everything after the end of the partition can be removed.
This will be done with the tool truncate. Don't forget to add 1 to the number of sectors, as block-numbers start at 0.
$ truncate --size=$[(5872026+1)*512] image.img