Linux Tricks

Post tags: | linux |

Find OS version


        $ lsb_release -a
        No LSB modules are available.
        Distributor ID:	Debian
        Description:	Debian GNU/Linux 7.6 (wheezy)
        Release:	7.6
        Codename:	wheezy


mkfs for windows

FAT32 is the oldest file system here. It was introduced all the way back in Windows 95 to replace the older FAT16 file system.

NTFS is the modern file system Windows likes to use. When you install Windows, it formats your system drive with the NTFS file system. NTFS has file size and partition size limits that are so theoretically huge you won’t run up against them. NTFS first appeared in consumer versions of Windows with Windows XP.

exFAT was introduced in 2006, and was added to older versions of Windows with updates to Windows XP and Windows Vista. It’s a file system optimized for flash drives. It’s designed to be a lightweight file system like FAT32 without all NTFS’s extra features and overhead, but without FAT32’s limitations. Like NTFS, exFAT has very large file size and partition size limits. This means you can store files that are larger than 4 GB apiece on a flash drive or SD card if it’s formatted with exFAT. exFAT is a strict upgrade over FAT32, and should be the best choice for external drives where you want a lightweight file system without FAT32’s file size limits. exFAT is also more compatible than NTFS. While Mac OS X includes only read-only support for NTFS, Macs offer full read-write support for exFAT. exFAT drives can be accessed on Linux by installing the appropriate software.


        sudo apt-get install exfat-utils exfat-fuse
        mkexfatfs - create an exFAT file system
         -n volume-name
          --label label-name
          -U, --with-uuid
              Generate a random volume UUID.


$ groups craig
        craig : craig dialout cdrom floppy sudo audio dip video plugdev netdev lpadmin scanner vboxusers gammu

Add a User to a Group (or Second Group) on Linux

Changing the group a user is associated to is a fairly easy task, but not everybody knows the commands, especially to add a user to a secondary group. We’ll walk through all the scenarios for you.

Add a New Group

To add a new group, all you need to do is use the groupadd command like so:

groupadd <groupname>

Add an Existing User to a Group

Next we’ll add a user to the group, using this syntax:

usermod -a -G <groupname> username

For example, to add user geek to the group admins, use the following command:

usermod -a -G admins geek

Change a User’s Primary Group

Sometimes you might want to switch out the primary group that a user is assigned to, which you can do with this command:

usermod -g <groupname> username

View a User’s Group Assignments

If you’re trying to figure out a permissions issue, you’ll want to use the id command to see what groups the user is assigned to:

id <username>

This will display output something like this:

uid=500(howtogeek) gid=500(howtogeek) groups=500(howtogeek), 1093(admins)

You can also use the groups command if you prefer, though it is the same as using id -Gn .

groups <username>

View a List of All Groups

To view all the groups on the system, you can just use the groups command:


Add a New User and Assign a Group in One Command

Sometimes you might need to add a new user that has access to a particular resource or directory, like adding a new FTP user. You can do so with the useradd command:

useradd -g <groupname> username

For instance, lets say you wanted to add a new user named jsmith to the ftp group:

useradd -G ftp jsmith

And then you’ll want to assign a password for that user, of course:

passwd jsmith

Add a User to Multiple Groups

You can easily add a user to more than one group by simply specifying them in a comma-delimited list, as long as you are assigning the secondary groups:

usermod -a -G ftp,admins,othergroup <username>

That should cover everything you need to know about adding users to groups on Linux.

Debian System Groups

Scraping Web Sites

wget can get a local copy of a url.

wget  --convert-links --adjust-extension --page-requisites --no-parent
        wget  --convert-links --adjust-extension --page-requisites --no-parent

HTML Tidy can be used as part of editing the scraped HTML

Archive and Compression

7zip tar archives

        apt-get install p7zip-full
        7z a archive.tar.7z archive.tar

Research and sites and links


site Sed Tutorial by Bruce Barnett


Bruce Barnett - Grymoire Awk Tutorial

Grymoire Grymoire Awk Tutorial

This page includes Bruce Barnett’s tutorials on UNIX shell programming and various other arcane subjects of interest to wizards.

Since AWK is also an interpretor, like the shell, you can save yourself a step and make the file executable by add one line in the beginning of the file:

I prefer this format when possible. It’s shorter and simpler. It’s also easier to debug problems.

Stand alone awk script
        #!/usr/bin/awk -f
        BEGIN 	{
          print "BEGIN here";

Daniel Robbins - Awk Tutorial at IBM Developer Works

Tutorial at IBM Developer Works Common threads: Awk by example, Part 1

Awk is a very nice language with a very strange name. In this first article of a three-part series, Daniel Robbins will quickly get your awk programming skills up to speed.

Linux Performance Analysis in 1 min.

Linux Performance Analysis in 1 min.
        dmesg | tail
        vmstat 1
        mpstat -P ALL 1
        pidstat 1
        iostat -xz 1
        free -m
        sar -n DEV 1
        sar -n TCP,ETCP 1

SD Cards

Debian groups

plugdev: Allows members to mount (only with the options nodev and nosuid, for security reasons) and umount removable devices through pmount.

cdrom: This group can be used locally to give a set of users access to a CDROM drive and other optical drives.

floppy: This group can be used locally to give a set of users access to a floppy drive and other removable (non-optical) drives (like USB flash drives). Starting with Debian 8 (Jessie) it is not used anymore for USB and flash memories.

staff: Allows users to add local modifications to the system (/usr/local) without needing root privileges (note that executables in /usr/local/bin are in the PATH variable of any user, and they may “override” the executables in /bin and /usr/bin with the same name). Compare with group “adm”, which is more related to monitoring/security.

disk: Raw access to disks. Mostly equivalent to root access.


Plug in the storage device. Look for the attached disk device.

        [598127.074709] sd 26:0:0:0: [sde] Attached SCSI removable disk
        [618067.958840] usb 3-2: new high-speed USB device number 19 using xhci_hcd
        [618068.087458] usb 3-2: New USB device found, idVendor=0781, idProduct=5530
        [618068.087462] usb 3-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
        [618068.087464] usb 3-2: Product: SanDisk Cruzer
        [618068.087466] usb 3-2: Manufacturer: SanDisk
        [618068.087468] usb 3-2: SerialNumber: 1738000A80108BA7
        [618068.087937] usb-storage 3-2:1.0: USB Mass Storage device detected
        [618068.088052] scsi27 : usb-storage 3-2:1.0
        [618069.088024] scsi 27:0:0:0: Direct-Access     SanDisk  SanDisk Cruzer   8.02 PQ: 0 ANSI: 0 CCS
        [618069.088534] sd 27:0:0:0: Attached scsi generic sg6 type 0
        [618069.088796] sd 27:0:0:0: [sdg] 7913471 512-byte logical blocks: (4.05 GB/3.77 GiB)
        [618069.088946] sd 27:0:0:0: [sdg] Write Protect is off
        [618069.088951] sd 27:0:0:0: [sdg] Mode Sense: 45 00 00 08
        [618069.089123] sd 27:0:0:0: [sdg] No Caching mode page found
        [618069.089131] sd 27:0:0:0: [sdg] Assuming drive cache: write through
        [618069.093609]  sdg: sdg1
        [618069.094681] sd 27:0:0:0: [sdg] Attached SCSI removable disk

So [618069.093609] sdg: sdg1

        /dev/sdg1 on /media/craig/MP3_1 type vfat (rw,nosuid,nodev,relatime,uid=1000,gid=1000,fmask=0022,dmask=0077,codepage=437,iocharset=utf8,shortname=mixed,showexec,utf8,flush,errors=remount-ro,uhelper=udisks2)

My usage

  • unmount with thunar
  • as root: gparted /dev/sdg


File information

List jpg file names and create date

        List jpg file names and create date
        ls *JPG 
          |xargs identify -verbose 
          |egrep Image:
          | paste -sd ' \n' 
        Image: DSC_0038.JPG     date:create: 2015-11-15T18:52:14-07:00
        Image: DSC_0039.JPG     date:create: 2015-11-15T18:52:28-07:00
        Image: DSC_0040.JPG     date:create: 2015-11-15T18:53:00-07:00
        Image: DSC_0041.JPG     date:create: 2015-11-15T18:53:40-07:00
        Image: DSC_0042.JPG     date:create: 2015-11-15T18:54:42-07:00
        Image: DSC_0043.JPG     date:create: 2015-11-15T18:55:08-07:00
        Image: DSC_0044.JPG     date:create: 2015-11-15T18:55:32-07:00


        apt-cache search freecad

        dpkg --get-selections

To see all the files the package installed onto your system, do this:

        dpkg-query -L 
        To see the files a .deb file will install

        dpkg-deb -c 
        To see the files contained in a package NOT installed, do this once (if you haven't installed apt-file already:

        sudo apt-get install apt-file
        sudo apt-file update

        apt-file list 
        ## android ptp mtp
        ### jmtpfs
        sudo apt-get install jmtpfs
        sudo mkdir /media/craig/mtp
        sudo chown craig:craig /media/craig/mtp
          connect phone with usb
        jmtpfs /media/craig/mtp
        jmtpfs on /media/craig/mtp type fuse.jmtpfs (rw,nosuid,nodev,relatime,user_id=1000,group_id=1000)
        sudo umount /media/craig/mtp
# imap article
         openssl s_client -crlf -connect
         tag login password
         tag LIST "" "*"
 How to use sed to find and replace text in files in Linux / Unix shell