Search This Blog

Tuesday, July 31, 2018

sudo bang bang 🔫

sudo !! (pronounced sudo bang bang)
!! is used to repeat the last command.

If you forgot to give root privilege to a command instead of using up arrow, going to the beginning of a command and typing sudo you can just do sudo !! 




Tuesday, July 24, 2018

saving linux man page.

A man page (short for manual page) is a form of software documentation usually found on a Unix or Unix-like operating system.
The standard location of the man page is /usr/share/man with man sections as subdirectories (e.g: 1 for user commands, 2 for system calls, 3 for library functions etc.)

File of man pages are in gzip compressed file format!
Gzip reduces the size of the named files using Lempel-Ziv coding (LZ77). Whenever possible, each file is replaced by one with the extension .gz, while keeping the same ownership modes, access and modification times.

We can use zcat to decompress these files!
zcat uncompresses either a list of files on the command line or its standard input and writes the uncompressed data on standard output. zcat will uncompress files that have the correct magic number whether they have a .gz suffix or not.

zcat /usr/share/man/man1/ls.1.gz

man pages are in troff format!
troff features commands to designate fonts, spacing, paragraphs, margins, footnotes and more. Unlike many other text formatters, troff can position characters arbitrarily on a page, even overlapping them, and has a fully programmable input language.

We can convert troff into pdf format by using groff!
Groff (GNU troff) is a typesetting system that reads plain text mixed with formatting commands and produces formatted output. The output may be PostScript or PDF, HTML, or ASCII/UTF8 for display at the terminal.

[Final Command]
zcat /usr/share/man/man1/ls.1.gz | groff -mandoc  > lsmanpage.pdf

Sunday, July 22, 2018

nload

nload is a console application which monitors network traffic and bandwidth usage in real time. It visualizes the in- and outgoing traffic using two graphs and provides additional info like the total amount of transferred data and min/max network usage.

*You can switch between the devices by pressing the left and right arrow keys.

[Example]
~ nload
~ nload wlp6s0

[Output]

Friday, July 20, 2018

Number Lines

nl writes each FILE to standard output, with line numbers added.
With no FILE, or when FILE is -, it read standard input.

[Example]
~ nl population.txt
    1  China
    2  India
    3  United States 

~ nl -s : population.txt
    1:China
    2:India
    3:United States
~ nl -n rz --number-width=4 population.txt
    0001  China
    0002  India
    0003  United States 


[Options]

-s : seprator
-n : number format
ln - left justified, no leading zeros
rn - right justified, no leading zeros
rz - right justified, leading zeros
 


Wget

GNU Wget is a free utility for non-interactive download of files from the Web.
It supports HTTP, HTTPS, and FTP protocols, as well as retrievalthrough HTTP proxies.

Wget has been designed for robustness over slow or unstable connections; if a download fails it will keep retrying until the whole file has  been retrieved. If the server supports regetting, it will instruct the server to continue the download from whereit left off.

[Example]

wget http://foo[.]com/bar[.]mp4
Downlaod bar.mp4 in current directory.

wget -i urls.txt

Iterate through urls in file urls.txt.

wget -nc http://foo[.]com/bar[.]mp4
Download bar.mp4 only if it is not available in current directory.


wget -O tmp[.]mp4 http://foo[.]com/bar[.]mp4

Download bar.mp4 as tmp.mp4 in current directory.



[Options]

-i : Read URLs from a local or external file.
-nc : Do not retrieve file if it already exists in current folder.
-O : Save output as.

Tuesday, July 17, 2018

Paste - Merge Lines Of Files

Paste :
It is used to write lines consisting of the sequentially corresponding lines from each FILE, separated by TABs, to standard output.

[Syntax]
paste [OPTIONS] [FILES]

[Example]

~cat one.txt
foo
bar

~cat two.txt
1337
31337

~paste one.txt two.txt
foo    1337
bar    31337

~paste -d : two.txt one.txt
1337:foo
31337:bar

[Options]
-d : use delimeter characters instead of TABs.

Monday, July 16, 2018

Vim Command to delete all the lines that begins with a digit.

[Command]
:g/^\d.*$/d

[Options]
g - global command
^ - start of line
\d - match digit
. - match any character after \d
* - 0 or more occurence of .
$ - end of line
/d - delete

[Example]
(I used it to delete following subtitle meta data to retain only text)
1337
00:00:00,000 --> 00:00:20,020

Sunday, July 15, 2018

Xargs

Xargs is a command line utility for building an execution pipeline from standard input.
Tools that cannot accept standared input as a parameter (e.g rm , echo , mkdir etc.) Xargs allows them to take standared input as a parameter.

Example :

[Command]
~ echo 'foo bar' | xargs mkdir 
It creates two directories named foo and bar.

[Command]
~ echo 'foo bar' | xargs -t rm -r 
rm -r foo bar 
It removes foo and bar directories.

[Options]
-t : prints command that will be executed to the terminal.

Saturday, July 14, 2018

FFMPEG + ImageMagic to make gif of video.

Step 1 - Convert video to images


Tool Used : FFMPEG 
ffmpeg is a very fast video and audio converter that can also grab from a live audio/video source.
It can also convert between arbitrary sample rates and resize video on the fly with a high quality polyphase filter.

[Command]
ffmpeg -i foo.mp4 -vf fps=25 foo%04.jpg -hide_banner

[Options]
-vf : Video filter to change frame property (fps to 25)
-hide_banner : Suppress printing banner.

Step 2 - Convert sequence of jpgs to gif  :


Tool Used : ImageMagick Convert
The convert program is a member of the ImageMagick suite of tools.
It is used to convert between image formats as well as resize an image, blur, crop, despeckle, dither, draw on, flip, join, re-sample, and much more.

[Syntax] 
convert [ip-options] ip-file [op-options] op-file 

[Command]

convert -resize 30% -delay 15 -loop 0 foo*.jpg output.gif 

[Options]
-resize : resize the image
-delay : pause between images
-loop : number of loops for gif

Friday, July 13, 2018

FTKimager

FTKimager is a forensic imaging software which can scan disks and make copy of it in EnCase , SMART as well as in raw (dd) format.

Syntax :
ftkimager source [destination] [options]
Example :
ftkimager /dev/sda ~/img --e01 --outpass 1337 
Above command will create image of sda encrypted with password 1337 in EnCase format and save it as img.

XDG-OPEN

XDG-Open opens a file or URL in user’s preferred application.
Example :
xdg-open foo.png
xdg-open http://www.example.com