Linux Tips

Linux LPIC

# file -s /dev/sda2
/dev/sda2: Linux/i386 swap file (new style) 1 (4K pages) size 140031 pages

# file -s /dev/sda
/dev/sda: x86 boot sector; GRand Unified Bootloader, stage1 version 0x3, boot drive 0x80, 1st sector stage2 0x11cb38, GRUB version 0.94; partition 1: ID=0x83, active, starthead 32, startsector 2048, 3072000 sectors; partition 2: ID=0x82, starthead 89, startsector 3074048, 1120256 sectors, code offset 0x48

If file -s doesn’t show a valid file system inside a disk partition, then you can’t mount the file system

#vi +11 ~/.ssh/known_hosts

mount -o loop rhel-server-7.2-x86_64-dvd.iso /mnt/
mount -t tmpfs -o size=1G tmpfs /ramdisk/

# fuser -m /media/cdrom
/media/cdrom: 1793 2013 2022 2435 10532c 10672c

Extract a single file
$ tar xvf test.tar -C anotherDirectory/ testfile1

find the largefiles on your system
du -ahx / | sort -rh | head -20

dig mx in alias

echo ‘alias mxdig=”dig mx +short”‘ >> ~/.bashrc
source ~/.bashrc


list only directories

ls -d */
ls -l | egrep ‘^d’
find / -type d -ls (include sub directories)

find /var/qmail/alias/ -iname “*zaicheng*” -exec cat {} \;


sysctl -p
lsof -i


Find total hard disk space – fdisk -l | grep Disk

Find the highest file size –
du -hs * | sort -rh | head -10
find /path/to/dir/ -printf ‘%s %p\n’| sort -nr | head -10

show files above certain size
find . -type f -size +1000000 -ls

show files less certain size (1,000,000 bytes = 1 M)
find . -type f -size -1000000 -ls


-N – view line no
100g – goto line no 100
100G – goto line no 100 from end of file


ps -A | grep —thunderbirddos

nohup cmd &
In Linux I have in folder /home/Johtd/.Skype/myacc#/ many files with “dbb” extension, call256.dbb, chat564.dbb and chatmsg654.dbb, etc.



recursively add file extension to all files
find /path -type f -not -name “*.*” -exec mv “{}” “{}”.jpg \;

Mount on same file system

[root@localhost ~]# mount --bind /opt/mountpoint/ /var/www/html/
[root@localhost ~]# cat /proc/mounts | grep bsec
/dev/mapper/rhel-root /var/www/html/ xfs rw,relatime,attr2,inode64,noquota 0 0
[root@localhost ~]# findmnt -n -o SOURCE --target /var/www/html/

Add in fstab (example below)

/proc /chroot/mysql/proc none defaults,bind 0 0






for d in ccm_hard certmanager_auscert comodo_esmlanding comodocoin; do echo ${d}; pg_dump93 -h -Fc -c -C ${d} | pg_restore93 -c -C -j=32 -d postgres; done

pg_dump93 -h /run/postgresql/9.3/ comodo_sasp | gzip > /var/lib/postgresql/comodo_sasp_$(date +%F).sql.gz

pg_dump93 MLB-768-80079 | gzip – > /var/tmp/ccm_hard-MLB-768-80079.gz

pg_ctl reload -D /var/lib/postgresql/9.3/data/

postgres@csdbase1 /var/tmp $ pg_dump92 -h /run/postgresql/9.2/ -Fc -Z6 dbSas | gzip > /var/tmp/dbSas.dump$(date +$Y-%m-%d).sql.gz



mysqldump blogscomodocom | gzip > blogscomodocom_dump_2015-02-04.sql.gz

mysql kayako_wl 4_tables_dump_2015-01-09.sql
mysql -u root blogcomodocom < 4_table_dump_2015-01-09.sql


mcsql2 ~ # sed -re 's/(.*)\s(10.34.*)/\1 \2\n\1\/24 md5\n\1\/24 md5/g' -i.nodc /var/lib/postgresql/9.3/data/pg_hba.conf

Replace ".*10.34.*" with ".*10.34.*" and ".**" and ".**"