Linux diplay size of each subdirectory    Posted:


To display total size of each subdirectory

du -sh *

-h human readable displays MB and GB instead of milions and bilions of bytes :) -s summarize total size of dir

Comments

ssh reverse tunneling    Posted:


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]

Comments

Linux suspended jobs    Posted:


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

Comments

Running scripts in background (linux)    Posted:


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

Comments

shell_productivity    Posted:


ctrlu clear whole line
ctrlk clear everything after curson
ctrlw clear everything before curson
ctrla set cursor at the beginning (home)
ctrle set cursor at the end (end)
ctrly undo last clear or repeat after second hit
ctrll clears screen
ctrlr search in you history commands type twice to select next candidate
ESCt Swap the last two words before the cursor
Altf Move cursor every word forward
Altb Move cursoor every word backward
ctrl_ Undo the last change

Comments