Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

List the size of sub directories in the current directory

Answer:

To check the disk usage of all sub directories in the current directory, you can try the following method:

#  sudo du -h --max-depth=1

4.0K    ./src
341M    ./lib
68M     ./bin
24K     ./games
195M    ./share
36M     ./local
18M     ./sbin
18M     ./include
673M    .

How to kill and logout a logged in user

Answer:

Assume john is logged in and you want to terminate his session, you can use the skill command.

# sudo skill -KILL -u john

Simple environment variable usage in Linux

Answer:

In Linux, the most basic way to set an environment variable is use the "=" operator.

For example:

# foo=bar
# echo $foo
bar

Count the total number of logged in user

Answer:

To count the total number of logged in user(s), use the following commands:

# who | wc -l
3

It shows currently there are 3 users logged in.

Print current environment variables using printenv

Answer:

Besides using env command, you can also use the printenv command, which has the same effect.

# printenv
TERM=xterm
SHELL=/bin/bash
XDG_SESSION_COOKIE=ff8f5b056d8812b8...