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.
Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.
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.
Spying on the physical console
Answer:
When you connect to your remote Linux server using SSH, sometimes you would like to see the message that appear in the console, you can view using the following method:
# tail -f /dev/vcs1
Where vcs1 means the virtual terminal 1, possible options are 1, 2, 3, 4 etc.
The method will save you many time from always need to visit the physical server.
Wrap each line to fit in specified width
Answer:
If you want to format a text file into a specific width, you can use the fold command
E.g.
# fold -w 40 test.txt
The above command will wrap the text file and print to standard out, with width = 40 characters.
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 :
How to bulk rename files in Linux
Answer:
Use the rename tool
E.g.
# rename .htm .html *.htm
The above command will rename all *.htm files to *.html files.