Showing posts with label LinuxCommandLineUbuntu. Show all posts
Showing posts with label LinuxCommandLineUbuntu. Show all posts

Friday, August 11, 2017

Batch renaming multiple files in Linux


[1] https://stackoverflow.com/questions/208181/how-to-rename-with-prefix-suffix

using 'rename'
rename 's/(.*)$/new.$1/' original.filename
shell script
for filename in *.jpg; do mv "$filename" "prefix_$filename"; done;
brace expansion
mv {,new.}original.filename


Friday, December 30, 2016

epoch and date conversion in Linux command line


http://stackoverflow.com/questions/14805591/how-to-convert-strings-like-19-feb-12-to-epoch-date-in-unix

date --date="19-FEB-12" +%s
Current epoch:
date +%s
So, since your dates are in the past:
NOW=`date +%s`
THEN=`date --date="19-FEB-12" +%s`

let DIFF=$NOW-$THEN
echo "The difference is: $DIFF"

Convert epoch seconds to date

Convert seconds since the epoch (1970-01-01 UTC) to a date

$ date --date='@2147483647'

Details see $man date


qyang@ubuntu:~$ date +%w
6                                                           0 is SUN, 6 is SAT
qyang@ubuntu:~$ date --date='2-JAN-2017' +%w
1                                                           1 is MON
qyang@ubuntu:~$ date --date='2-JAN-2017' +%s
1483275600


qyang@ubuntu:~$ date --date='2-JAN-2017' +%s
1483275600
qyang@ubuntu:~$ ipython
Python 2.7.12 (default, Nov 19 2016, 06:48:10) 

In [1]: 1483275600+60*24*60*60.
Out[1]: 1488459600.0

So, in 60 days from 2-Jan-2017 will be 3-Mar-2017:
qyang@ubuntu:~$ date --date='@1488459600.0'
Fri Mar  3 00:00:00 AEDT 2017

To calculate how many days between two dates:
qyang@ubuntu:~$ date --date='31-Dec-2016' +%s
1483102800
qyang@ubuntu:~$ date --date='6-Mar-2017' +%s
1488718800
qyang@ubuntu:~$ ipython
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
Type "copyright", "credits" or "license" for more information.
In [1]: (1488718800 - 1483102800)/(24*60*60.)
Out[1]: 65.0
It's 65 days from 31-Dec-2016 to 6-Mar-2017.

Friday, November 7, 2014

Expand Ubuntu Drive Size Running in VM Player

Ref
[1] http://superuser.com/questions/795699/how-to-extend-the-primary-partition-for-ubuntu-server-running-in-vmware-player
[2] http://www.in8sworld.net/blog/archives/3912
[3] http://blog.pluralsight.com/resize-vmware-linux-drives
[4] http://askubuntu.com/questions/429576/increase-ubuntu-partition-size-under-virtual-machine
[5] http://askubuntu.com/questions/294889/how-to-expand-the-ext4-primary-partition-size-in-a-vmware-player-virtual-disk
[6] http://xmodulo.com/how-to-change-the-boot-order-of-guest-vm-on-vmware-player.html  F2 into VM guest BIOS
[7] http://unix.stackexchange.com/questions/108199/centos-cant-use-new-extented-space-on-system-disc
[8] http://gparted-forum.surf4.info/viewtopic.php?id=16987

Adding following line into *.vmx file if too short to hit F2 key
--------------------
bios.bootDelay = "<number_of_milliseconds>"
bios.forceSetupOnce = "TRUE"

Command line option (run after boot VMWare from GParted disc or iso)
----------------------
--Start fdisk and display current partition---
# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).
Command (m for help): p
Device Boot         Start         End      Blocks   Id  System
/dev/sda1            2048    39845887    19921920   83  Linux
/dev/sda2       207607995   209712509     1052257+   5  Extended
/dev/sda5       207611904   209712509     1050303   82  Linux swap / Solaris

--Delete /dev/sda1-----
Command (m for help): d
Partition number (1,2,5, default 5): 1
Partition 1 is deleted

--Create new primary partition----
Command (m for help): n
Partition type:
   p   primary (0 primary, 1 extended, 3 free)
   l   logical (numbered from 5)
Select (default p): p
Partition number (1,3,4, default 1): 1
First sector (2048-209715199, default 2048):    <==== This MUST be the same as in the original partition table!
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-207607994, default 207607994):  <== Use the default, will be maximum it can do
Using default value 207607994
Partition 1 of type Linux and of size 99 GiB is set

--Write new partition-----
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

--Check file system consistence----
# e2fsck -f /dev/sda1
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/sda1: 11/1245184 files (0.0% non-contiguous), 122210/4980480 blocks

--Resize partition----
# resize2fs /dev/sda1
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/sda1 to 25950743 (4k) blocks.


In my own practice, /dev/sda2 sectors straight after /dev/sda1/, so either change /dev/sda2/  and /dev/sda5/ start sectors, or just delete /dev/sda2 and /dev/sda5, then all unassigned sectors can be added to new /dev/sda1






Above is resizing 'primary partition'. Below is for resize partition on logical volume [7]
---------------------------------------------------
Baisc relationship among PhysicalVolume(PV), VolumeGroup(VG) and LogicalVolume(LV):
PV (/dev/sda2) -> VG (turnkey) -> LV (root)
Resize PV, then extend LV, then resize2fs /dev/VG/LV .....

---expand guest OS disk space from 20G to 200G
Using VMWare disk -> utilities -> Expand

---resize LVM in GParted GUI mode from 20G to 200G
Remember to partition->deactivate LVM2 PV before resizing. [8]

---run following commands after starting debian
root@trac ~# pvs
  PV         VG      Fmt  Attr PSize   PFree
  /dev/sda2  turnkey lvm2 a--  199.52g 182.02g
root@trac ~# lvs
  LV     VG      Attr     LSize   Pool Origin Data%  Move Log Copy%  Convert
  root   turnkey -wi-ao--  17.00g
  swap_1 turnkey -wi-ao-- 512.00m
root@trac ~# vgs
  VG      #PV #LV #SN Attr   VSize   VFree
  turnkey   1   2   0 wz--n- 199.52g 182.02g

---before adding newly allocated space into LVM
root@trac ~# df -h
Filesystem                Size  Used Avail Use% Mounted on
rootfs                     17G  893M   16G   6% /
udev                       10M     0   10M   0% /dev
tmpfs                     101M  172K  101M   1% /run
/dev/mapper/turnkey-root   17G  893M   16G   6% /
tmpfs                     5.0M     0  5.0M   0% /run/lock
tmpfs                     201M     0  201M   0% /run/shm
/dev/sda1                 415M   19M  375M   5% /boot

---Run following commands
root@trac ~# pvresize /dev/sda2
root@trac ~# lvextend /dev/mapper/turnkey-root /dev/sda2
root@trac ~# resize2fs /dev/turnkey/root

---Afterwards, checking again. It's done.
root@trac ~# df -h
Filesystem                Size  Used Avail Use% Mounted on
rootfs                    196G  909M  186G   1% /
udev                       10M     0   10M   0% /dev
tmpfs                     101M  172K  101M   1% /run
/dev/mapper/turnkey-root  196G  909M  186G   1% /
tmpfs                     5.0M     0  5.0M   0% /run/lock
tmpfs                     201M     0  201M   0% /run/shm
/dev/sda1                 415M   19M  375M   5% /boot





root@trac ~# pvs
  PV         VG      Fmt  Attr PSize   PFree
  /dev/sda2  turnkey lvm2 a--  199.52g 182.02g
root@trac ~# lvs
  LV     VG      Attr     LSize   Pool Origin Data%  Move Log Copy%  Convert
  root   turnkey -wi-ao--  17.00g
  swap_1 turnkey -wi-ao-- 512.00m
root@trac ~# vgs
  VG      #PV #LV #SN Attr   VSize   VFree
  turnkey   1   2   0 wz--n- 199.52g 182.02g
root@trac ~# df -h
Filesystem                Size  Used Avail Use% Mounted on
rootfs                     17G  893M   16G   6% /
udev                       10M     0   10M   0% /dev
tmpfs                     101M  172K  101M   1% /run
/dev/mapper/turnkey-root   17G  893M   16G   6% /
tmpfs                     5.0M     0  5.0M   0% /run/lock
tmpfs                     201M     0  201M   0% /run/shm
/dev/sda1                 415M   19M  375M   5% /boot
root@trac ~# pvresize /dev/sda2
  Physical volume "/dev/sda2" changed
  1 physical volume(s) resized / 0 physical volume(s) not resized
root@trac ~# lvs
  LV     VG      Attr     LSize   Pool Origin Data%  Move Log Copy%  Convert
  root   turnkey -wi-ao--  17.00g
  swap_1 turnkey -wi-ao-- 512.00m
root@trac ~# lvextend /dev/mapper/turnkey-root /dev/sda2
  Extending logical volume root to 199.02 GiB
  Logical volume root successfully resized
root@trac ~# lvs
  LV     VG      Attr     LSize   Pool Origin Data%  Move Log Copy%  Convert
  root   turnkey -wi-ao-- 199.02g
  swap_1 turnkey -wi-ao-- 512.00m
root@trac ~# resize2fs /dev/turnkey/root
resize2fs 1.42.5 (29-Jul-2012)
Filesystem at /dev/turnkey/root is mounted on /; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 13
Performing an on-line resize of /dev/turnkey/root to 52171776 (4k) blocks.
The filesystem on /dev/turnkey/root is now 52171776 blocks long.

root@trac ~# df -h
Filesystem                Size  Used Avail Use% Mounted on
rootfs                    196G  909M  186G   1% /
udev                       10M     0   10M   0% /dev
tmpfs                     101M  172K  101M   1% /run
/dev/mapper/turnkey-root  196G  909M  186G   1% /
tmpfs                     5.0M     0  5.0M   0% /run/lock
tmpfs                     201M     0  201M   0% /run/shm
/dev/sda1                 415M   19M  375M   5% /boot

#man lvextend
.....
Examples
       "lvextend -L +54 /dev/vg01/lvol10 /dev/sdk3" tries to extend the size of that logical volume by 54MB on physical volume /dev/sdk3.  This is only possible if
       /dev/sdk3 is a member of volume group vg01 and there are enough free physical extents in it.

       "lvextend /dev/vg01/lvol01 /dev/sdk3" tries to extend the size of that logical volume by the amount of free space on physical  volume  /dev/sdk3.   This  is
       equivalent to specifying "-l +100%PVS" on the command line.

       "lvextend -L+16M vg01/lvol01 /dev/sda:8-9 /dev/sdb:8-9"
       tries to extend a logical volume "vg01/lvol01" by 16MB using physical extents /dev/sda:8-9 and /dev/sdb:8-9 for allocation of extents.


Surprisingly fast when do it for fedora20 (Only a couple of seconds)
---------------------------------------------------------------------
1. Expand in VMWare on fedora20 disk space from 20G to 250G
2. GParted iso start up and resize LVM2 PV from 20G to 250G to include new unallocated new space from VMware expansion.
3. Restarted into Fedora20. run lvextend, and resize2fs. A few seconds for this on-line resizing. Done

[root@fedora20 q.yang]# lvextend /dev/mapper/fedora_192-root /dev/sda2
Extending logical volume root to 247.51 GiB Logical volume root successfully resized [root@fedora20 q.yang]# resize2fs /dev/fedora_192/root resize2fs 1.42.12 (29-Aug-2014) Filesystem at /dev/fedora_192/root is mounted on /; on-line resizing required old_desc_blocks = 2, new_desc_blocks = 16 The filesystem on /dev/fedora_192/root is now 64882688 (4k) blocks long. [root@fedora20 q.yang]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 988M 0 988M 0% /dev tmpfs 997M 152K 997M 1% /dev/shm tmpfs 997M 884K 996M 1% /run tmpfs 997M 0 997M 0% /sys/fs/cgroup /dev/mapper/fedora_192-root 244G 16G 219G 7% / tmpfs 997M 32K 997M 1% /tmp /dev/sda1 477M 146M 302M 33% /boot /dev/sr0 229M 229M 0 100% /run/media/q.yang/GParted-live
   

Thursday, June 5, 2014

Trace route command line under both windows and Linux

>tracert hostnameOrIP

$traceroute hostnameOrIp


C:\Users\QuentinYang>tracert 10.10.10.56

Tracing route to ENG-QUENTIN [10.10.10.56]
over a maximum of 30 hops:

  1    35 ms    33 ms    33 ms  JUPITER [10.10.10.66]
  2    34 ms    36 ms    39 ms  ENG-QUENTIN [10.10.10.56]

Trace complete.


[q.yang@fedora20 ~]$ traceroute 10.10.10.56
traceroute to 10.10.10.56 (10.10.10.56), 30 hops max, 60 byte packets
 1  10.10.10.66 (10.10.10.66)  47.483 ms  49.967 ms  49.689 ms
 2  10.10.10.56 (10.10.10.56)  52.431 ms  52.185 ms  54.700 ms


quentin@ubuntu:~$ traceroute 10.10.10.56
traceroute to 10.10.10.56 (10.10.10.56), 30 hops max, 60 byte packets
 1  ubuntu (10.1.1.11)  3000.618 ms !H  3000.615 ms !H  3000.547 ms !H

Tuesday, January 15, 2013

upgrade vlc in Ubuntu 12.04

[1] http://origin.omgubuntu.co.uk

  • sudo add-apt-repository ppa:videolan/stable-daily
  • sudo apt-get update && sudo apt-get install vlc

Monday, January 14, 2013

Install chrome in Ubuntu 12.04

[1] http://askubuntu.com


Add PPA to

wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -

sudo sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'

Install Google chrome

sudo apt-get update
sudo apt-get install google-chrome-stable

Sunday, January 8, 2012

Changing MAC address under Linux Command Line

[1] Ref


$ ifconfig -a | grep HWaddr
eth0  Link encap:Ethernet HWaddr 00:80:48:BA:d1:20
 

# ifconfig eth0 down
# ifconfig eth0 hw ether 00:80:48:BA:d1:30
# ifconfig eth0 up
# ifconfig eth0 |grep HWaddr
 
 
In Linux, Windows, Mac OS X, or a different operating system, 
changing MAC address is only temporary. 
 
Once you reboot your machine, the operating system reflects the 
physical MAC address burnt in your network card and not the MAC address you set.
 

Thursday, January 5, 2012

Set Time and Date under Linux

[1] Linuxsa.org

Setting the system clock

To set the system clock under Linux, use the date command. As an example, to set the current time and date to July 31, 11:16pm, type ``date 07312316'' (note that the time is given in 24 hour notation). If you wanted to change the year as well, you could type ``date 073123161998''. To set the seconds as well, type ``date 07312316.30'' or ``date 073123161998.30''. To see what Linux thinks the current local time is, run date with no arguments.

Setting the hardware clock

To set the hardware clock, my favourite way is to set the system clock first, and then set the hardware clock to the current system clock by typing ``/sbin/hwclock --systohc'' (or ``/sbin/hwclock --systohc --utc'' if you are keeping the hardware clock in UTC). To see what the hardware clock is currently set to, run hwclock with no arguments. If the hardware clock is in UTC and you want to see the local equivalent, type ``/sbin/hwclock --utc''

Wednesday, December 28, 2011

FW: File size limit exceeded error under Linux and solution

[1] From Cyberciti.biz

File size limit exceeded error under Linux and solution

$ulimit -a

core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
file size (blocks, -f) unlimited
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 227
virtual memory (kbytes, -v) unlimited

Sunday, August 7, 2011

Install VLC Player for ubuntu 10.10

[1] Web source Link

Command line way

You need to check that a universe mirror is listed in your /etc/apt/sources.list file.

% sudo apt-get update
% sudo apt-get install vlc vlc-plugin-pulse mozilla-plugin-vlc