Difference between revisions of "Linux shell/Commands"

From Ever changing code
Jump to navigation Jump to search
Line 37: Line 37:
*<tt>'''Ctrl+Shift+V'''</tt> or <tt>'''Shift+Insert'''</tt> -to paste
*<tt>'''Ctrl+Shift+V'''</tt> or <tt>'''Shift+Insert'''</tt> -to paste


Option 3 Install parcellite
Option 3 Install Parcellite GTK+ clipboard manager
  sudo apt-get install parcellite
  sudo apt-get install parcellite
then in the settings check "use primary" and "synchronize clipboards"
then in the settings check "use primary" and "synchronize clipboards"

Revision as of 22:57, 27 April 2014

One liners

  • df -h displays filesystem disk space usage for all mounted partitions
  • du -sh displays the disk usage for a directory, -s is for summary
  • free -m displays the amount of free and used memory in the system
  • lsb_release -a prints version information for the Linux release you're running
  • tload -draws system load on text based graph

Copy with progress bar

rsync and cp
  • rsync -aP - copy with progress can be also aliased alias cp='rsync -aP'
  • cp -rv old-directory new-directory - shows progress bar
PV does not preserve permissions and does not handle attributes
  • pv ~/kali.iso | cat - /media/usb/kali.iso equals cp ~/kali.iso /media/usb/kali.iso
  • pv ~/kali.iso > /media/usb/kali.iso equals cp ~/kali.iso /media/usb/kali.iso
  • pv access.log | gzip > access.log.gz shows gzip compressing progress.

PV can be imagined as CAT command piping '|' output to another command with a bar progress and ETA times. -c makes sure one pv output is not use to write over to another, -N creates a named stream. Find more at How to use PV pipe viewer to add progress bar to cp, tar, etc..

$ pv -cN source access.log | gzip | pv -cN gzip > access.log.gz
source:  760MB 0:00:15 [37.4MB/s] [=>     ] 19% ETA 0:01:02
gzip: 34.5MB 0:00:15 [1.74MB/s] [  <=>  ]

Useful packages

  • ARandR Screen Layout Editor - 0.1.7.1

Copy and Paste

In Linux X graphical interface this works different then in Windows you can read more in X Selections, Cut Buffers, and Kill Rings. When you select some text this becomes the Primary selection (not the Clipboard selection) then Primary selection can be pasted using the middle mouse button. Note however that if you close the application offering the selection, in your case the terminal, the selection is essentially "lost".

Option 1 works in X

  • select text to copy then use your mouse middle button or press a wheel

Option 2 works in Gnome Terminal

  • Ctrl+Shift+C -to copy
  • Ctrl+Shift+V or Shift+Insert -to paste

Option 3 Install Parcellite GTK+ clipboard manager

sudo apt-get install parcellite

then in the settings check "use primary" and "synchronize clipboards"

List partitions

lsblk 
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0  55.9G  0 disk 
├─sda1   8:1    0  54.4G  0 part /
├─sda2   8:2    0     1K  0 part 
└─sda5   8:5    0   1.5G  0 part [SWAP]
sudo fdisk -l
Disk /dev/sda: 60.0 GB, 60011642880 bytes
255 heads, 63 sectors/track, 7296 cylinders, total 117210240 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000f12f1

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048   114083839    57040896   83  Linux
/dev/sda2       114085886   117209087     1561601    5  Extended
/dev/sda5       114085888   117209087     1561600   82  Linux swap / Solaris
sudo sfdisk -ls
/dev/sda:  58605120

Disk /dev/sda: 7296 cylinders, 255 heads, 63 sectors/track
Warning: extended partition does not start at a cylinder boundary.
DOS and Linux will interpret the contents differently.
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/sda1   *      0+   7101-   7102-  57040896   83  Linux
/dev/sda2       7101+   7295-    195-   1561601    5  Extended
/dev/sda3          0       -       0          0    0  Empty
/dev/sda4          0       -       0          0    0  Empty
/dev/sda5       7101+   7295-    195-   1561600   82  Linux swap / Solaris
  • -l : List the partitions of a device.
  • -s : List the size of a partition.
  • -u or -uS or -uB or -uC or -uM : Accept or report in units of sectors (blocks, cylinders, megabytes, respecpively). The default is cylinders, at least when the geometry is known

Generate random password

cat /dev/urandom|tr -dc "a-zA-Z0-9"|fold -w 48|head -n1