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.

Aug 232011
 

Check if a file exist in Bash Shell

Answer:

The following script demonstrates how to check if a file exist, using shell (Bash) script

#!/bin/bash

if [ -e test.txt ]
then
  echo 'The file exists.'
else
  echo 'The file does not exist.'
fi
Apr 022011
 

How to rename a user in Linux?

Answer:

Firstly, you need to have a account with root privileges (You cannot change the account name if you have this user currently logged in)

To rename a user, do the following steps:

1. Rename user

# sudo usermod -l new_user -d /home/new_user -m old_user

2. Update group (Usually the same as user name)

# sudo groupmod -n new_user old_user

That's all.

Dec 262010
 

Display timestamp information in command history

Answer:

When using the history command, it only shows the command number and the command itself. But sometimes it is useful to know when this command was executed, i.e. the timestamp. To do so, following the instructions below:

# export HISTTIMEFORMAT='%F %T '

Then type history again

# history
..
 260  2010-12-23 19:22:07 ls
 261  2010-12-23 19:22:07 pwd
...

That's all.