From PersoWiki
Jump to: navigation, search


Port forward with iptables

iptables -t nat -I PREROUTING --src 0/0 --dst ""  -p tcp --dport 2222 -j REDIRECT --to-ports 22

How to replace FollowSymLinks with SymLinksIfOwnerMatch in all .htaccess file

find /home -name ".htaccess" -type f -exec sed -i 's/FollowSymLinks/SymLinksIfOwnerMatch/g' {} ";"

How To Set File Attributes In Linux Using Chattr Command =

To prevent anyone - even a root user - from deleting a file, you set the immutable bit of the file using the chattr command as follows

# chattr +i filename

To unset the immutable flag

# chattr -i filename

Every file in Linux have a number of attributes associated with it. The immutable bit attribute being just one of them. To see what all attributes are set for a particular file, you run the lsattr command as follows.

# lsattr filename
----i--------  filename

If the immutable flag is set, there will be an i in the listing.

chattr can be used to set/unset many more file attributes.

For example, if you want to allow everybody to just append data to a file and not change already entered data, you can set the append bit as follows:

# chattr +a filename

Now the filename can only be opened in append mode for writing data. You can unset the append attribute as follows:

# chattr -a filename

How to remove or delete all hidden file or directory without warning?

Remove all file and directory without any output to the screen,

[root@fedora /]# rm –rf .??*

With the option –rf and the use " .??* " will remove/delete all hidden files/directory. The initial " . " indicates a 'hidden' file and the " ?? " match at least two characters to exclude the parent-directory which is " .. " and to remove or delete everything the " * " will match all number or characters that used for files or directory name.

How to retain installed software between Ubuntu installations

sudo apt-get update
sudo apt-get install aptitude
dpkg --set-selections < ~/Desktop/YourFile.txt
sudo apt-get dselect-upgrade
sudo aptitude install $(cat ~/Desktop/YourFile.txt | awk '{print $1}')

with a note: This will reinstall ALL of your installed packages. So if you're using (for example) xubuntu 12.04 now, but your new machine will be kubuntu 14.04 you'll run into a number of problems with your desktop managers, and in this case you'll probably want to edit the YourFile.txt to get rid of some of those things

How to create UEFI-only bootable USB live media

You can do something like the following if 604A-00EA is your USB drive and you already have p7zip installed:

$ 7z x ubuntu-12.04-desktop-amd64.iso -o/media/$USER/604A-00EA/

You're done if you have only one partition on this USB drive, otherwise you need to flag the partition as bootable e.g. via parted:

# parted /dev/sdX set 1 boot on

Where /dev/sdX would be your USB stick and 1 the partition number that should be used to boot.

Check if Apache web server is listening on port 80 and 443

netstat -ln | grep -E ':80|443'

Linux Increase The Maximum Number Of Open Files / File Descriptors (FD)

Number Of Open File Descriptors:

cat /proc/sys/fs/file-max


# sysctl fs.file-max

To see the hard and soft values, issue the command as follows:

# ulimit -Hn
# ulimit -Sn

System-wide File Descriptors (FD) Limits

System-wide File Descriptors (FD) Limits

# sysctl -w fs.file-max=100000

Above command forces the limit to 100000 files. You need to edit /etc/sysctl.conf file and put following line so that after reboot the setting will remain as it is:

# vi /etc/sysctl.conf

Save and close the file. Users need to log out and log back in again to changes take effect or just type the following command:

# sysctl fs.file-max

Change Descriptors (FD) Limits for a specific user

# vi  /etc/security/limits.conf

List network established connections

# netstat -an |grep ESTABLISHED

Small scripts

Converting audio file formats from .ape with .cue to mp3

Since "Ubuntu 14.04 Trusty" FFmpeg is dropped and its fork adopted 'libav'.

To install FFmpeg in Ubuntu/Linux Mint open Terminal (Press Ctrl+Alt+T) and copy the following commands in the Terminal:

sudo add-apt-repository ppa:kirillshkrogalev/ffmpeg-next
sudo apt-get update
sudo apt-get install ffmpeg


apt-get install flac lame cuetools shntool flac bchunk



for file in "*.ape"; do
  ffmpeg -i $file ${file%.ape}.wav
  bchunk -w ${file%.ape}.wav ${file%.ape}.cue track

for file in track*.wav; do lame -V0 $file; done
rm *.wav