How to broadcast text message to all users
Answer:
To broadcast message on the terminals of all currently logged in users, use the wall command
# echo "Hello" | wall
Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.
How to broadcast text message to all users
Answer:
To broadcast message on the terminals of all currently logged in users, use the wall command
# echo "Hello" | wall
Execute command as another user
Answer:
If you want to run command as another user, you can use the following method:
# sudo su mark -c 'whoami'
mark
Assume currently logged in as user other than mark.
Extract column data using awk
Answer:
A simple awk command print the 1st column of top command
# top -bc -n1 | awk '{print $1}'
If you want to specify the field separator, you can do the following
# awk -F':' '{print $1}' /etc/passwd
Which print the 1st column of file /etc/password, as if they are split by :
Print a particular column data using awk
Answer:
Consider you have a file text.txt like below
1 one
2 two
3 three
How would you only print the second column?
It can be easily done using awk
# awk '{print $2}' text.txt
one
two
three
Try the above command with $1, $2, $3 etc.
Using system directory stack with pushd & popd
Answer:
When you need to changes a lot of directory frequently, pushd & popd can be very useful
E.g.
john@localhost:/tmp $ pushd /home/jack/
# change to /home/jack/ and push to the stack
/home/jack /tmp
john@localhost:/home/jack $ pushd /home/mark/
# change to /home/mark/ and push to the stack
/home/mark /home/jack /tmp
john@localhost:/home/mark $ popd
# pop current directory and change to /home/jack
/home/jack /tmp
john@localhost:/home/jack $ popd
# pop current directory and change to /tmp
john@localhost:/tmp/ $