Tag: Linux

  • Current Working Directory for Different OS and Tools

    • Bash: $(pwd)
    • fish: (pwd)
    • Windows Command Line (cmd): %cd%
    • PowerShell: $(PWD) (Case-insensitive)
  • Zip/Unzip Multi-volume Archives from Command Line

    Compress with level 0 means no compression, split then into 500 MB per slice.

    zip -0 -s 500m InstallESD InstallESD.dmg

    To merge/unzip them:

    zip -FF InstallESD.zip --out InstallESD-full.zip
  • Run Process in Background and Redirect Output to a Log – The Ease Way

    $ some_cmd > some_cmd.log 2>&1 &
    

    Source: https://unix.stackexchange.com/a/106641

  • Mount EBS Volumes To EC2 Linux Instances

    View all available volumes:

    $ lsblk
    NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    xvda    202:0    0   10G  0 disk 
    ├─xvda1 202:1    0    1M  0 part 
    └─xvda2 202:2    0   10G  0 part /
    xvdf    202:80   0  3.9T  0 disk 
    
    $ file -s /dev/xvdf
    /dev/xvdf: data
    

    If returns data it means the volume is empty. We need to format it first:

    $ mkfs -t ext4 /dev/xvdf
    mke2fs 1.42.9 (28-Dec-2013)
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    Stride=0 blocks, Stripe width=0 blocks
    262144000 inodes, 1048576000 blocks
    52428800 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=3196059648
    32000 block groups
    32768 blocks per group, 32768 fragments per group
    8192 inodes per group
    Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
        102400000, 214990848, 512000000, 550731776, 644972544
    
    Allocating group tables: done                            
    Writing inode tables: done                            
    Creating journal (32768 blocks): done
    Writing superblocks and filesystem accounting information: done       
    

    Create a new directory and mount it to EBS volume:

    $ cd / && mkdir ebs-data
    $ mount /dev/xvdf /ebs-data/
    

    Check volume mount:

    $ df -h
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/xvda2       10G  878M  9.2G   9% /
    devtmpfs        476M     0  476M   0% /dev
    tmpfs           496M     0  496M   0% /dev/shm
    tmpfs           496M   13M  483M   3% /run
    tmpfs           496M     0  496M   0% /sys/fs/cgroup
    tmpfs           100M     0  100M   0% /run/user/1000
    tmpfs           100M     0  100M   0% /run/user/0
    /dev/xvdf       3.9T   89M  3.7T   1% /ebs-data
    

    In order to make it mount automatically after each reboot, we need to edit /etc/fstab, first make a backup:

    $ cp /etc/fstab /etc/fstab.orig
    

    Find the UUID for the volume you need to mount:

    $ ls -al /dev/disk/by-uuid/
    total 0
    drwxr-xr-x. 2 root root 80 Nov 25 05:04 .
    drwxr-xr-x. 4 root root 80 Nov 25 04:40 ..
    lrwxrwxrwx. 1 root root 11 Nov 25 04:40 de4dfe96-23df-4bb9-ad5e-08472e7d1866 -> ../../xvda2
    lrwxrwxrwx. 1 root root 10 Nov 25 05:04 e54af798-14df-419d-aeb7-bd1b4d583886 -> ../../xvdf
    

    Then edit /etc/fstab:

    $ vi /etc/fstab
    

    with:

    #
    # /etc/fstab
    # Created by anaconda on Tue Jul 11 15:57:39 2017
    #
    # Accessible filesystems, by reference, are maintained under '/dev/disk'
    # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
    #
    UUID=de4dfe96-23df-4bb9-ad5e-08472e7d1866 /                       xfs     defaults        0 0
    UUID=e54af798-14df-419d-aeb7-bd1b4d583886 /ebs-data               ext4    defaults,nofail 0 2
    

    Check if fstab has any error:

    $ mount -a
    
  • Use cURL to view request headers

    curl -v -s -o - -X OPTIONS https://www.google.com/
    
  • List and Change Kernel in CentOS 7

    List kernels:

    $ egrep ^menuentry /etc/grub2.cfg | cut -f 2 -d \'
    CentOS Linux (3.10.0-327.10.1.el7.x86_64) 7 (Core)
    CentOS Linux (3.10.0-327.4.5.el7.x86_64) 7 (Core)
    CentOS Linux (3.10.0-327.3.1.el7.x86_64) 7 (Core)
    CentOS Linux (3.10.0-229.20.1.el7.x86_64) 7 (Core)
    CentOS Linux (3.10.0-123.9.3.el7.x86_64) 7 (Core)
    CentOS Linux, with Linux 0-rescue-45461f76679f48ee96e95da6cc798cc8
    

    Set kernel to the fourth:

    $ grub2-set-default 3
    
  • Shaving your RTT with TCP Fast Open – Bradley Falzon

    Check out the recently released RFC on TCP Fast Open, a spec that allows most TCP connections to send data during the initial SYN packet – reducing the initial round trips required from 2 to 1. Excellent for HTTPS connections.

    Source: Shaving your RTT with TCP Fast Open – Bradley Falzon