Archive

Articles taggués ‘commands’

Linux Command: Show Linux Version

21/06/2020 Comments off

Source: nixCraft

What command I need to type to display Linux kernel version and other information such as Linux distribution name? How do I check Linux kernel version number?

You need to use the following two commands:

[a] uname - Print kernel and system information.
[b] lsb_release - Print distribution-specific information.
[c] /proc/version file - Print running kernel information.

How to check linux kernel version number?

Open a shell prompt (or a terminal) and type the following command to see your current Linux kernel version:

$ uname -r

Sample outputs:

2.6.32-23-generic-pae

Or type the following command:

$ uname -mrs

Sample outputs:

Linux 2.6.32-23-generic-pae i686

To print all information, enter:

$ uname -a

Sample outputs:

Linux vivek-laptop 2.6.32-23-generic-pae #37-Ubuntu SMP Fri Jun 11 09:26:55 UTC 2010 i686 GNU/Linux

Where,

  • 2.6.32-23 – Linux kernel version number
  • pae – pae kernel type indicate that I’m accssing more than 4GB ram using 32 bit kernel.
  • SMP – Kernel that supports multi core and multiple cpus.

Lire la suite…

Categories: Système Tags: , , ,

How to find out Router MAC address

19/06/2020 Comments off

Source: nixCraft

MAC is acronym for for Media Access Control address. It is a unique identifier attached to almost most all networking equipment such as Routers, Ethernet cards and other devices.

If you do not have access to router admin interface (via telnet or webbased), use following method to find out router MAC address.

You need to use arp command (available on both Windows, Linux/Unixish systems).

arp manipulates the kernel’s ARP cache in various ways. The primary options are clearing an address mapping entry and manually setting up one. For debugging purposes, the arp program also allows a complete dump of the ARP cache.

arp shows the entries of the specified hosts. If the hostname parameter is not used, all entries will be displayed.

Task: Find out router Mac Address

To find out your router MAC address, use arp command as follows:

$ /usr/sbin/arp -a
OR
$ arp -a
Output:

router (192.168.1.254) at 00:08:5C:00:00:01 [ether] on eth0
fbsd6 (192.168.1.16) at 00:0F:EA:91:04:07 [ether] on eth0

In above example 00:08:5C:00:00:01 is MAC address of my router. If you cannot find MAC address then just ping to your router once (my router had 192.168.1.254 IP)
$ ping 192.168.1.254
And then run (type arp -a) above arp command again. If you have telnet access to router then you can just telnet into router and find out MAC address:
$ telnet 192.168.1.254

Output:

Welcome to nixCraft Router!
Login: admin
Password:

Once logged in type ifconfig command:

$ ifconfig br0

Output:

br0             Link encap:Ethernet  HWaddr 00:08:5C:00:00:01
        inet addr:192.168.1.254  Bcast:192.168.1.255  Mask:255.255.255.0
        UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
        RX packets:48574 errors:0 dropped:0 overruns:0 frame:0
        TX packets:61329 errors:0 dropped:0 overruns:0 carrier:0
        collisions:0 txqueuelen:0
        RX bytes:9146189 (8.7 MiB)  TX bytes:74456679 (71.0 MiB)

Please note that your interface name (br0) could be different. You can also use ifconfig -a command.

Windows XP/NT/2003 find out Router Mac address

If you are using Microsoft Windows XP then you need to open MS-DOS shell prompt first. Click on Start > Run > Type cmd command followed by ENTER key. Then at C:\> prompt, type arp command as follows:

C:\> arp -a

Categories: Réseau Tags: ,

Afficher une image dans un terminal

17/06/2020 Comments off

Source: korben.info

Si vous cherchez un utilitaire et une bibliothèque pour vos projets qui permette d’afficher dans un terminal une image en utilisant du code ANSI, j’ai ce qu’il vous faut. Ça s’appelle Picture- et pour l’ c’est très simple. Il vous faudra npm, donc sous pour un petit npm, il faut taper :

sudo apt-get install npm

Ensuite pour installer la bibliothèque Picture-tube, il faut faire :

sudo npm install picture-tube

Si seul l’outil en vous intéresse, ajoutez le paramètre -g

sudo npm install -g picture-tube

Ensuite, pour convertir une image, un petit

picture-tube monimage.jpg

dans le terminal et taaadaaa

 

zelda

Après, pour utiliser la bibliothèque, voici un exemple de code :

var pictureTube = require('picture-tube')
var tube = pictureTube();
tube.pipe(process.stdout);
var fs = require('fs');
fs.createReadStream('robot.png').pipe(tube);

Pour tout le reste, c’est par ici.

Categories: Logiciel Tags: , ,

Useful Mac bash terminal shortcuts

10/06/2020 Comments off

Open directory in finder

open .

Pbcopy and pbpaste

grep 'searching for' hugeFile.txt | pbcopy
pbpaste | sed 's/ / /g'

mdfind command is the spotlight search from command line

say "Hello there"

The say command invokes the system text-to-speech capabilities.

cd -

Will restore the previous directory you were in. Very handy if you accidentally type cd and flip to home.

And some usefull aliases

alias ..="cd .." alias ...="cd .. ; cd .."
alias ls="ls -G" # list alias la="ls -Ga" # list all, includes dot files alias ll="ls -Gl" # long list, excludes dot files alias lla="ls -Gla" # long list all, includes dot files
alias stfu="osascript -e 'set volume output muted true'" alias pumpit="osascript -e 'set volume 10'"
alias ips="ifconfig -a | perl -nle'/(d .d .d .d )/ && print $1'" alias myip="dig  short myip.opendns.com @resolver1.opendns.com"

Bash Keyboard Shortcuts

Moving the cursor:

  Ctrl   a   Go to the beginning of the line (Home)
  Ctrl   e   Go to the End of the line (End)
  Hold the Option key option and click on the current line = Jump Backwards

  Ctrl   p   Previous command (Up arrow)
  Ctrl   n   Next command (Down arrow)
  Hold the Option key option and click on a previous line = Jump upwards

  Ctrl   f   Forward one character
  Ctrl   b   Backward one character
   Alt   b   Back (left) one word      or use Option Right-Arrow
   Alt   f   Forward (right) one word  or use Option Left-Arrow

  Ctrl   xx  Toggle between the start of line and current cursor position

Editing:

 Ctrl   L   Clear the Screen, similar to the clear command

  Alt   Del Delete the Word before the cursor.
  Alt   d   Delete the Word after the cursor.
 Ctrl   d   Delete character under the cursor
 Ctrl   h   Delete character before the cursor (backspace)

 Ctrl   w   Cut the Word before the cursor to the clipboard.
 Ctrl   k   Cut the Line after the cursor to the clipboard.
 Ctrl   u   Cut/delete the Line before the cursor position.

  Alt   t   Swap current word with previous
 Ctrl   t   Swap the last two characters before the cursor (typo).
 Esc    t   Swap the last two words before the cursor.

 ctrl   y   Paste the last thing to be cut (yank)
  Alt   u   UPPER capitalize every character from the cursor to the end of the current word.
  Alt   l   Lower the case of every character from the cursor to the end of the current word.
  Alt   c   Capitalize the character under the cursor and move to the end of the word.
  Alt   r   Cancel the changes and put back the line as it was in the history (revert).
 ctrl   _   Undo
 
  TAB       Tab completion for file/directory names

For example, to move to a directory ‘sample1’; Type cd sam ; then press TAB and ENTER.
type just enough characters to uniquely identify the directory you wish to open.

Special keys: Tab, Backspace, Enter, Esc

Text Terminals send characters (bytes), not key strokes.
Special keys such as Tab, Backspace, Enter and Esc are encoded as control characters.
Control characters are not printable, they display in the terminal as ^ and are intended to have an effect on applications.

Ctrl I = Tab
Ctrl J = Newline
Ctrl M = Enter
Ctrl [ = Escape

Many terminals will also send control characters for keys in the digit row:

Ctrl 2 → ^@
Ctrl 3 → ^[ Escape
Ctrl 4 → ^
Ctrl 5 → ^]
Ctrl 6 → ^^
Ctrl 7 → ^_ Undo
Ctrl 8 → ^? Backward-delete-char

Ctrl v tells the terminal to not interpret the following character, so Ctrl v Ctrl-I will display a tab character,
similarly Ctrl v ENTER will display the escape sequence for the Enter key: ^M

History:

  Ctrl   r   Recall the last command including the specified character(s)
             searches the command history as you type.
             Equivalent to : vim ~/.bash_history. 
  Ctrl   p   Previous command in history (i.e. walk back through the command history)
  Ctrl   n   Next command in history (i.e. walk forward through the command history)
   Alt   .   Use the last word of the previous command
  Ctrl   s   Go back to the next most recent command.
            (beware to not execute it from a terminal because this will also launch its XOFF).
  Ctrl   o   Execute the command found via Ctrl r or Ctrl s
  Ctrl   g   Escape from history searching mode

Process control:

 Ctrl   C   Interrupt/Kill whatever you are running (SIGINT)
 Ctrl   l   Clear the screen
 Ctrl   s   Stop output to the screen (for long running verbose commands)
 Ctrl   q   Allow output to the screen (if previously stopped using command above)
 Ctrl   D   Send an EOF marker, unless disabled by an option, this will close the current shell (EXIT)
 Ctrl   Z   Send the signal SIGTSTP to the current task, which suspends it.
            To return to it later enter fg 'process name' (foreground).

To use the Alt Key Shortcuts in OS X – Open Terminal Preferences | Settings Tab | Keyboard | Tick “Use option as meta key”

Emacs mode vs Vi Mode

All the above assume that bash is running in the default Emacs setting, if you prefer this can be switched to Vi shortcuts instead.

Set Vi Mode in bash:

$ set -o vi

Set Emacs Mode in bash:

$ set -o emacs

Source: @coderwall and ss64.com

Categories: Système Tags: , , ,

Tree en une ligne de commande (sed)

07/06/2020 Comments off

Source: didier.misson.net

Mais que fait cette commande ?

Il suffit d’essayer en ligne de commande…

Non, ce n’est pas risqué.

ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'

Cette commande liste vos dossiers en arborescence, sous forme d’un arbre.

C’est plutôt pour le fun, et pour utiliser SED, car on ne va pas retaper cette longue commande à chaque fois !

Voyez donc ce billet comme un exercice, un exemple de ce qu’on peut faire en ligne de commande avec SED, et pas comme un « truc et astuce ».

J’ai ensuite voulu comprendre comment cette commande fonctionnait.

On y retrouve des commandes assez classiques en Linux : ls, grep et sed.

Lire la suite…

Categories: Système Tags: ,