Difference between revisions of "Linux shell/Commands"
Line 1: | Line 1: | ||
= One liners = | = One liners = | ||
*<span style="font-weight: bold; color: green"><tt>df -h</tt></span> displays filesystem disk space usage for all mounted partitions | *<span style="font-weight: bold; color: green"><tt>df -h</tt></span> displays filesystem disk space usage for all mounted partitions | ||
*<span style="font-weight: bold; color: green"><tt>du - | *<span style="font-weight: bold; color: green"><tt>du -skh * | sort -n</tt></span> displays the disk usage summary for each directory | ||
*<span style="font-weight: bold; color: green"><tt>free -m</tt></span> displays the amount of free and used memory in the system | *<span style="font-weight: bold; color: green"><tt>free -m</tt></span> displays the amount of free and used memory in the system | ||
*<span style="font-weight: bold; color: green"><tt>lsb_release -a</tt></span> prints version information for the Linux release you're running | *<span style="font-weight: bold; color: green"><tt>lsb_release -a</tt></span> prints version information for the Linux release you're running |
Revision as of 20:56, 21 October 2015
One liners
- df -h displays filesystem disk space usage for all mounted partitions
- du -skh * | sort -n displays the disk usage summary for each directory
- 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] [ <=> ]
Tail log files
tail-f-the-output-of-dmesg or install multitail
tail -f /var/log/{messages,kernel,dmesg,syslog}
- old school but not perfectwatch 'dmesg | tail -50'
- approved by man dmesgwatch 'sudo dmesg -c >> /tmp/dmesg.log; tail -n 40 /tmp/dmesg.log'
- tested, but experimental
Replace unix timestamps in logs to human readable date format
user@laptop:/var/log$ tail dmesg | perl -pe 's/(\d+)/localtime($1)/e' [ Thu Jan 1 01:00:29 1970.168088] b43-phy0: Radio hardware status changed to DISABLED [ Thu Jan 1 01:00:29 1970.308597] tg3 0000:09:00.0: irq 44 for MSI/MSI-X [ Thu Jan 1 01:00:29 1970.344378] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready [ Thu Jan 1 01:00:29 1970.344745] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready user@laptop:/var/log$ tail dmesg [ 29.168088] b43-phy0: Radio hardware status changed to DISABLED [ 29.308597] tg3 0000:09:00.0: irq 44 for MSI/MSI-X [ 29.344378] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready [ 29.344745] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
- References
Useful packages
- ARandR Screen Layout Editor - 0.1.7.1
Copy and Paste in terminal
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"
Generate random password
cat /dev/urandom|tr -dc "a-zA-Z0-9"|fold -w 48|head -n1