how to detect space usage in linux

Getting the size of all files and folders inside the current directory can be done by typing:

 ls | xargs du -s -BM

Get filesize in descending order from all files in a recursive folder structure

find . -type f -exec du -a -h --max-depth=100 {} + | sort -hr

Another quite handy tool is ncdu. It provides you the disc usage in a graphical way on the shell. Install it like this:

sudo apt-get install ncdu

List folders bigger 1Mb and list them in descending order

du -sm * | awk '$1 > 1' | sort -n -r

List the ten largest folders inside a recursive folder structure

find . -type d -print0 | xargs -0 du | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}

 

handle multiple shell sessions with tmux

A handy tool for dealing with different bash sessions is tmux. It’s comparable with gnu screen but by far more advanced. You can get it with:

sudo apt-get install tmux

Launch it by typing:

tmux

Dealing with sessions brings great power. You can set up your multi-windows panes on a remote machine, in a seperate session. Now you can detach from this session and log out. When you later ssh back into this machine you can reattach this session and all your views are restored.

tmux ls                             list all sessions currently running
tmux new -s sessionname             create a new session
tmux attach -t sessionname          open a specific session
tmux a                              attach to last session
tmux kill-session -t sessionname    kill a specific session

ctrl+b s                            list all sessions (inside tmux)
ctrl+b d                            detach you from the session

Executing commands tmux specific is usually prefixed with the key combination ctrl+b. See the following list what you can do with tmux.

ctrl+b ?              list all shortcuts

Windows
ctrl+b c              create a new (c=create)
ctrl+b &              kill windowbs
ctrl+b ,              rename the current
ctrl+b p              go to previous (p=previous)
ctrl+b n              go to next (n=next)
ctrl+b w              show list of all windows (w=windows)

Panes
ctrl+b %              split window into vertical panes
ctrl+b "              split window into horizontal panes
ctrl+b o              switch between panes
ctrl+b x              kill current pane
ctrl+b !              close all panes excepting current
ctrl+b space          change pane layout
ctrl+b {              move current pane to the left
ctrl+b }              move current pane to the right