Skip to main content

Posts about Linux

xrandr tips

adding resolution 1)generate mode cvt 2560 1440 60 ➜ blog git:(website) ✗ cvt 2560 1440 60 # 2560x1440 59.96 Hz (CVT 3.69M9) hsync: 89.52 kHz; pclk: 312.25 MHz Modeline "2560x1440_60.00" 312.25 2560 2752 3024 3488 1440 1443 1448 1493 -hsync +vsync

2)add it to xrandr sudo xrandr --newmode "2560x1440_60.00" 312.25 2560 2752 3024 3488 1440 1443 1448 1493 -hsync +vsync setting resolution

3)sudo xrandr --addmode VGA-0 "1680x1050_60.00"

xrandr -q xrandr --verbose

xrandr --output HDMI-0 --mode 2560x1440

irst generate a "modeline" by using cvt Syntax is: cvt width height refreshrate

cvt 1680 1050 60 this gives you:

# 1680x1050 59.95 Hz (CVT 1.76MA) hsync: 65.29 kHz; pclk: 146.25 MHz Modeline "1680x1050_60.00" 146.25 1680 1784 1960 2240 1050 1053 1059 1089 -hsync +vsync Now tell this to xrandr:

sudo xrandr --newmode "1680x1050_60.00" 146.25 1680 1784 1960 2240 1050 1053 1059 1089 -

First clone the two screens, (the smaller screen will display the top left portion of the virtual screen)

xrandr --output VGA --auto --right-of LVDS

xrandr --output LVDS --mode 1280x800

xrandr --output LVDS --mode 1280x800 --rate 75

xrandr --output LVDS --auto

xrandr --output LVDS --off --output HDMI-0 --auto

xrandr --output VGA1 --mode 1024x768 --rate 60

#Laptop right extra Monitor Left

xrandr --output VGA1 --left-of LVDS1

#Laptop left extra Monitor right

xrandr --output LVDS1 --left-of VGA1

#This is to set your primary monitor.

#This sets your laptop monitor as your primary monitor.

xrandr --output LVDS1 --primary

#This sets your VGA monitor as your primary monitor.

xrandr --output VGA1 --primary

xrandr --output VGA1 --mode 1024x768 --rate 60

xrandr --pos <x>x<y>

$ xrandr --left-of <output>

$ xrandr --right-of <output>

$ xrandr --above <output>

$ xrandr --below <output>

Option '-pos' is more flexible which can place output to anywhere, for example:

$ xrandr --output VGA1 --pos 200x200 $ xrandr --output LVDS1 --pos 400x500

xrandr -o right

ssh reverse tunneling

When you want someone to connect to your NAT-ed or Firewalled server and

you run out of ideas ond options or you even dont have

you dont have access to Firewall or VPN server to configure

anything - you can always try to use reverse ssh tunnel.

The only one condition is that you must be able to ssh from your server to public host( the one other guy wants to connect)

This is how it works:

[Server] <----> [ FIREWALL/NAT SERVER ] <----> [ BOB HOST with public ip 80.80.80.80]

Linux suspended jobs

If you suspended job by accident with ctrl+z you can always resume by fg here more examples:

crtlz suspend
jobs - list the current jobs
fg - resume the job that's next in the queue
fg %[number] - resume job [number]
bg - Push the next job in the queue into the background
bg %[number] - Push the job [number] into the background
kill %[number] - Kill the job numbered [number]
kill -[signal] %[number] - Send the signal [signal] to job number [number]
disown %[number] - you won't be owner of process anymore so it will be alive after leaving terminal
%vim

running-scripts-in-background-linux

I used to execute a lot of commands with & at the end. But once I used plowshare and it didnt work because & works until you wont log out .So my solution (I know I could use nohup :) ) was screen. Screen is the best tool admin can use when working remotely. It can be usefull when you're in place with big packet loss and you often lost connection so when you're restoring database you should be in screen session because when something will disconnect you you can alwas log in and connect to screen session in which restoring is taking place.

So executing

$./my_script.sh &

will be only running when your session is still active so when you'll logout it will be killed.

To run it independent from your presence on server do it with nohup:

$ nohup ./my_script.sh &

To launch screen :

$ screen

Best practice is to launch screen with its name :

$ screen -S my_own_screen_name
Then if you want detach screen to get back later Ctrlad If you want terminate screen just Ctrld or exit

then you can resume it with:

$ screen -r my_own_screen_name

To list all available screens :

$ screen -ls

To attach to already attached screen:

$ screen -x my_own_screen_name

To attach to attached screen and detach others:

$ screen -r -d my_own_screen_name

To rename existing screen:

(being attached): Ctrla:sessionname my_screen_nameEnter

Easy admin joke

When I first got admin access ages ago on shared server I wanted to do something funny to my coleague so I thought to display something on his screen.

Remembering everything in Linux filesystem is a file or a directory I read about pseudoterminals "pts" they are inside /dev directory

Yea yea I know 3 rules of admin : Respect the privacy of others. Think before you type. With great power comes great responsibility bla bla bla ...

To do this joke just check who is logged in and on which pts is he :

$ who
greg     pts/3        2012-03-10 1:26 (:0)
mark     pts/5        2012-03-10 10:29 (:0)
jenny    pts/7        2012-03-10 13:06 (:0)

So now, we know that Mark is working on pts/5 so lets send him message :)

$ echo "In 5 minutes in toilet /Jenny" > /dev/pts/5

To "clean evidences" :D ( remember that guy working on this terminal will lost his current works he's working on this specific terminal)

$ cat /dev/urandom > /dev/pts/5