Sapiens Search

Showing posts with label unix. Show all posts
Showing posts with label unix. Show all posts

How to rename a branch on git?


1-Go to your repository
cd /<Path to your git repository>
2-Type:
git branch -m <Old branch name> <New branch name>

Example

git branch -m blog garouBlog

How discover your local IP address on Linux?

1-Open terminal
2-Type
ifconfig <interface>
where interface is your name of your network interface
3-Look for
inet end.:

Example

ifconfig eth0
ifconfig eth1
ifconfig wlan0

Output

eth1 Link encap:Ethernet Endereço de HW 78:e4:00:22:f8:86
inet end.: 192.168.10.100 Bcast:192.168.10.255 Masc:255.255.255.0
endereço inet6: fe80::7ae4:ff:fe22:f886/64 Escopo:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Métrica:1
pacotes RX:371047 erros:0 descartados:0 excesso:0 quadro:221100
Pacotes TX:245369 erros:59 descartados:0 excesso:0 portadora:0
colisões:0 txqueuelen:1000
RX bytes:475482323 (475.4 MB) TX bytes:57852121 (57.8 MB)
IRQ:17

Arcam Sapientia

Some other usefull commands are, ifconfig, ifconfig -a to list all networks.

If you don't know the name of your network interface just type ifconfig and search in each result what you are looking for.

How to fit the terminal/console results on the screen?

<Your command> | less


Example

ps ax | less

Arcam Sapientia

Using this tip we can prevent the output results of our command scroll down to the end. Or, we can fit the results to the screen and pressing Enter see rest of the results

How to use ASCII characters on KDE?

1-Go to
System settings->Input devices->Keyboard->Advanced->Position of the compose key
2-Choose a option available, like Right Control
3-Test it typing
Righ_Control =  c
4-You get
€ 

Arcam Sapientia

This is the equivalent to the Alt on Windows systems.

How to change the keyboard layout for the console (Ctrl+Alt+F1)?

1-Go to the console
Press Control+Alt+F1, for example
2-Install the console-common package
sudo apt-get install console-common
3-Follow the instructions and choose your new keyboard layout
4-Test the new layout

 Arcam Sapientia

 To reconfigure your keybout layout run
sudo dpkg-reconfigure console-common
This tip is useful to us keyboard for foreign users.Users that have pipeline (|) missing can emulate it using this tip too.

How to run external programs/commands/functions in Sublime Text 2?

1-Preferences->Key Bindings - User
2- Override [`,`] to:
[
{ "keys": ["<Your shortucut>"], "command": "exec", "args": { "cmd"["<Path to your command>"]} }
]


Where <Your shortcut> could be f1, ctrl+shift+f1, etc. and <Path to your command> echo, /home/garou/scripts/my_script.py, ls, etc.

Example


    [
        { "keys": ["f1"], "command": "exec", "args": { "cmd": ["/media/data/Scripts/myScript"]} },
    ]


Arcam Sapientia

This virtually could run any system command.

How to check GMail by terminal?

1 Type:
curl -u <Your gmail username> --silent "https://mail.google.com/mail/feed/atom" | perl -ne 'print "\t" if //; print "$2\n" if /<(title|name)>(.*)<\/\1>/;'
2 Enter the password
3 See your unread messages

How to create a symbolic link (symlink)?

ln -s <Path to the file> <Path to the target>

Example

ln -s /media/data/script.sh /home/garou/scripts/


Arcam Sapientia

We can use sudo in the beginning of the command if we don't have write privilege in the target.

We can specify a new name to link too, like:
sudo ln -s /media/data/script.sh /usr/bin/macro.sh

How to prompt for a password when running a command or script?

kdesudo "<Full command>"

Example

1 - Open the run command with Alt+F2
2 - To reboot (needs root), for example, type:
kdesudo "shutdown -r now"
3- Type your root password and hit Return
4 - Your system will reboot after this

 Arcam Sapientia

You can use this on scripts to prompt for a pass when it is needed.

#!/bin/sh
clementine
kdesudo "shutdown -r 00:00"

This will open the clementine music player and reboot at 00:00 time.

How to put something on clipboard?

1 Install xclip
sudo apt-get install xclip
2 Type:
echo "<Your text here>" | xclip

Example

echo "Sapiens Garou is a good blog." | xclip

Test on a text editor pressing Control+v to see working

Arcam Sapientia

See the manual to other usefull options:
man xclip
 P.S.: Learn how to put a text on the clipboard by using a command line (terminal) on Linux/Unix.

How to change the brightness (backlight) on Linux by terminal?

xbacklight -set <value>

Example

xbacklight -set 20.0

 Arcam Sapientia

See the man for more options
 man xbacklight

How to change the constrast by terminal on Linux?

xgamma -gamma <value>

Example

xgamma -gamma 0.6

Arcam Sapientia

Gamma values must be between  0.100 and 10.000
See the man too
$man xgamma

How to change the system volume by terminal on Linux?

amixer set Master <volume>

Example

amixer set Master 20

Arcam Sapientia

See the manual to another helpfull parameters
$man amixer

How to use floating numbers in Shell Script?

<variable> =`echo "scale=<precision>;<operations>"`

Example:

Write a code file named float as follow:

#!/bin/sh
floatNumber=`echo "scale=2;1/2" | bc`
echo $floatNumber

When you run it, the result will be:
$./float
.50