Linux
October 9, 2012

How to pronounce Linux

Internet newsgroup participants have long debated the proper pronunciation of Linux. Because the name Linux was conferred by Linux kernel author Linus Torvalds, his pronunciation of the word should reign as standard as I see it. However, Linus is Finnish and his pronunciation of Linux is difficult for English speakers to approximate. Consequently, many variations in pronunciation have arisen. The most popular pronunciation sounds as though the word were spelled Linnucks, with the stress on the first syllable.

You can hear how Linus Torvalds pronounces Linux:

Andrew T. Baker - Demystifying Docker - PyCon 2015

How to pronounce Linux

Directory structure

  • /boot: Boot loader files
  • /etc: Configuration files
  • /home: User home directories
  • /root: Root home directory
  • /opt: Third-party applications
  • /dev: Device files
  • /var: Variable files
  • /bin: User binaries
  • /sbin: System binaries
  • /usr: User applications
  • /proc: Process information
  • /mnt: Mount directory
  • /sys: Virtual file system
  • /media: Removeable devices
  • /run: Temporary file system
  • /tmp: Temporary files
  • /lost+found: Recover broken files
  • /lib: System libraries
  • /srv: Service data directory

Changing locale

Edit locale.gen and comment out the locale you need, for example tr_TR.UTF-8 UTF-8

1
nano /etc/locale.gen

Then run locale-gen command for activation

1
locale.gen

Changing tzdata (time zone)

1
dpkg-reconfigure tzdata

Listening live stream

1
2
mplayer <stream>
mplayer -nocache -afm ffmpeg <stream>

Some internet radios

Converting video

1
ffmpeg -i video1.m4v -acodec copy -vcodec copy -f mov video1.mov

Splitting video

1
ffmpeg -i ORIGINALFILE.mp4 -acodec copy -vcodec copy -ss START -t LENGTH OUTFILE.mp4

where START is starting positing in seconds or in format hh:mm:ss LENGTH is the chunk length in seconds or in format hh:mm:ss

If let’s say your video is 31 minutes long and you want so split into 15 min chunks here is how you run it:

1
2
3
ffmpeg -i ORIGINALFILE.mp4 -acodec copy -vcodec copy -ss 0 -t 00:15:00 OUTFILE-1.mp4
ffmpeg -i ORIGINALFILE.mp4 -acodec copy -vcodec copy -ss 00:15:00 -t 00:15:00 OUTFILE-2.mp4
ffmpeg -i ORIGINALFILE.mp4 -acodec copy -vcodec copy -ss 00:30:00 -t 00:31:00 OUTFILE-3.mp4

Commands

To set home directory

1
usermod –d /home/user1/

To set root gid and groups for the user1

1
usermod –g 0 –G 0 user1

To change access rights for a directory

1
chmod 777 /var/www/directory

To remove package with configuration files

1
aptitude remove --purge package-name

To remove old configuration files

1
dpkg --purge package-name

To combine .rar files using unrar

1
unrar e -kb part01.rar

RarCrack

1
rarcrack p1r.part1.rar

Creating symbolic link (There is no “/” sign at the end)

1
ln -s /var/www/existing /var/www/newname

Burning an ISO image to CD-ROM

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
apt-get install cdrecord

cdrecord -scanbus
... snip ...

1,0,0 100) 'HDT72251' '6DLAT80 ' 'V43O' Disk

1,1,0 101) *

1,2,0 102) *

... snip ...


cdrecord -dev 1,0,0 /tmp/output.iso

Removing kernel

1
2
3
uname –a
dpkg --list 'linux-image*'
sudo aptitude remove linux-image-2.6.18-5-686

Sources List, http://www.debian.org/doc/manuals/apt-howto/ch-basico.en.html

1
nano /etc/apt/sources.list

Trace a program (ex. pidgin)

1
strace -v -i -s 9999 $( which pidgin ) >| strace.log 2>&1

nc

To check if a port is free, run the following command:

1
$ nc localhost 56733 < /dev/null; echo $?

If the output of the command above is 1, then the port is free and usable.

xattr (extended attributes)

Delete ‘Where From’ metadata from files

1
xattr /Path/To/File

You’ll get a key named com.apple.metadata:kMDItemWhereFroms. To delete this key in the Terminal, run:

1
xattr -d com.apple.metadata:kMDItemWhereFroms /Path/To/File

Mount External HDD (NTFS)

Install ntfs-3g library

1
aptitude install ntfs-3g

Shows all the disk drives

1
fdisk -l

To make writable mount

1
mount /dev/sda1 /mnt/sda1 -t ntfs-3g -o rw,umask=0022,uid=dev,gid=dev

Mount NTFS partition

umask is a filter of permissions, so it works in the opposite way to chmod. Full permissions are equivalent to 777 (rwxrwxrwx). A umask of 0222 (-w–w–w-) leaves 555 (r-xr-xr-x).

1
mount /dev/sda1 /mnt/sda1 -t ntfs -r -o umask=0222,uid=dev,gid=dev

-rwxr-x— 1 dev dev 28096 Aug 24 1996 chkdsk.exe

1
umount /mnt/sda1/

To make writable mount

1
mount /dev/sda1 /mnt/sda1 -t ntfs-3g -o rw,umask=0022,uid=dev,gid=dev

Mount an ISO image

Under UNIX and Linux like oses a loop device (a pseudo-device) can make a file accessible as a block device. It is is often used for CD / DVD ISO images and floppy disc images. Mounting a file containing a filesystem via such a loop mount makes the files within that filesystem accessible. They appear in the mount point directory.

Open terminal and create a mount point:

1
sudo mkdir /home/user/iso

If your iso image is at /tmp/file.iso, type the following to mount it:

1
sudo mount -o loop /tmp/file.iso /home/user/iso

To unmount type the command:

1
sudo umount /home/user/iso

Accurate Platform Detection

1
2
shtool platform -v -F "%sc (%ac) %st (%at) %sp (%ap)"
cat /etc/*-release

Network Testing Basics

Install netkit-ping, traceroute, dnsutils, ipchains (for 2.2 kernel), iptables (for 2.4 kernel), and net-tools packages and:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
ping google.com           # check Internet connection
traceroute google.com     # trace IP packets
ifconfig                  # check host config
route -n                  # check routing config
dig [@dns-server.com] host.dom [{a|mx|any}] |less # check host.dom DNS records by dns-server.com for a {a|mx|any} record
ipchains -L -n |less      # check packet filter (2.2 kernel)
iptables -L -n |less      # check packet filter (2.4 kernel)
netstat -a                # find all open ports
netstat -l --inet         # find listening ports
netstat -ln --tcp         # find listening TCP ports (numeric)

How to format a hard drive in linux

To create partition on hard drive B

1
cfdisk /dev/sdb

Choose New, Primary and then Write and Quit

To format 1st partition on hard drive B

1
mkfs /dev/sdb1

convert images to pdf

Use convert program (it is an executable installed as part of Imagemagick suite of tools):

1
2
convert 'p%d.jpg[1-148]' file.pdf
convert "*.{ext1,ext2,ext3,...}" -quality 100 outfile.pdf

Create favicon.ico

Using netpbm and GIMP

Install netpbm and GIMP

1
aptitude install netpbm gimp

Step # 1: Convert logo to ppm raw format

  1. Open your logo using GIMP
  2. Now cut and paste logo in square
  3. Next resize logo by visiting Image > Scale image option. Set pixel size to 16 x 16 or 32 x 32 or 48 x 48.
  4. Next click on File > Save as > Enter file name as favicon.ppm > Click on Save > Raw Encoding > Ok

Step # 2: Convert portable pixmaps into a Windows .ico file

1
ppmtowinicon -output favicon.ico favicon.ppm

Using imagemagick

Install imagemagick first

1
brew install imagemagick

and use convert tool

1
convert -background transparent icon.png -define icon:auto-resize=16,32,48,64,256 icon.ico

How to cycle through reverse-i-search in BASH?

To cycle through alternatives by repeatedly hitting Ctrl+R

E.g.:

1
Ctrl+R grep Ctrl+R Ctrl+R ...

Convert png image to jpg with white background

1
mogrify -format jpg -background white -flatten *.png

xattr

Using the xattr command, you can inspect the extended attributes:

1
2
3
$ xattr s.7z
com.apple.metadata:kMDItemWhereFroms
com.apple.quarantine

and use the -d option to delete one extended attribute:

1
2
3
$ xattr -d com.apple.quarantine s.7z
$ xattr s.7z
com.apple.metadata:kMDItemWhereFroms

you can also use the -c option to remove all extended attributes:

1
2
$ xattr -c s.7z
$ xattr s.7z

Checking the SHA-256 checksum

You can compare the SHA-256 checksum of your downloaded binary against the checksums that are provided for every release. To generate a SHA-256 checksum of your downloaded binary, then open the corresponding checksum file and ensure that it contains the same number.

1
$ shasum -a 256 downloaded_binary.tar.gz

Getting all files from a web page using wget

For downloading files from a directory listing, use -r (recursive), -np (don’t follow links to parent directories), and -k to make links in downloaded HTML or CSS point to local files

1
wget -r -np -k [web_address]

Other useful options:

  • -nd (no directories): download all files to the current directory
  • -e robots.off: ignore robots.txt files, don’t download robots.txt files
  • -A png,jpg: accept only files with the extensions png or jpg
  • -m (mirror): -r –timestamping –level inf –no-remove-listing
  • -nc, –no-clobber: Skip download if files exist

How to Format a USB Stick

To find out which disk is your USB drive

1
diskutil list

If the disk is /dev/disk2, to format the disk

1
sudo diskutil eraseDisk FAT32 MBRFormat /dev/disk2

How to Make a Bootable USB Stick from an ISO File

from Mac

  1. Download the desired file
  2. Convert the .iso file to .img using the convert option of hdiutil:
1
hdiutil convert -format UDRW -o /path/to/target.img /path/to/source.iso

Note: OS X tends to put the .dmg ending on the output file automatically. Rename the file by typing:

1
mv /path/to/target.img.dmg /path/to/target.img
  1. Run diskutil list to get the current list of devices

  2. Insert your flash media 5 .Run diskutil list again and determine the device node assigned to your flash media (e.g. /dev/disk2)

  3. Run diskutil unmountDisk /dev/diskN (replace N with the disk number from the last command - in the previous example, N would be 2)

  4. Execute sudo dd if=/path/to/downloaded.img of=/dev/rdiskN bs=1m (replace /path/to/downloaded.img with the path where the image file is located; for example, ./ubuntu.img or ./ubuntu.dmg).

Note: Using /dev/rdisk instead of /dev/disk may be faster.

Note: If you see the error dd: Invalid number ‘1m’, you are using GNU dd. Use the same command but replace bs=1m with bs=1M.

Note: If you see the error dd: /dev/diskN: Resource busy, make sure the disk is not in use. Start the ‘Disk Utility.app’ and unmount (don’t eject) the drive.

  1. Run diskutil eject /dev/diskN and remove your flash media when the command completes

Now the USB stick is ready. Boot the device that you want from the USB stick.

sha3sum: Keccak, SHA-3, SHAKE, and RawSHAKE checksum utilities

1
2
3
sha3sum somefile.txt > somefile.txt.sha3
cat somefile.txt.sha3
765597429418c1b6e4a0d1ad52f2e3feb39c09e0709290571afad07f  somefile.txt

Log Parsing Cheat Sheet

Log Parsing Cheat Sheet 1

Log Parsing Cheat Sheet 2

Finding and counting duplicate filenames

1
find . -name "*.java"|awk -F"/" '{a[$NF]++}END{for(i in a)if(a[i]>1)print i,a[i]}'