Convert all text in a file from upper-case to lower-case
Answer:
Just one command needed:
# tr '[:upper:]' '[:lower:]' < input.txt
Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.
Convert all text in a file from upper-case to lower-case
Answer:
Just one command needed:
# tr '[:upper:]' '[:lower:]' < input.txt
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
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.
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.
How do I know if I am running a shell inside another shell?
Answer:
We can enter another a shell from a current shell, e.g. enter sh from a bash. To show the current "shell stack", you can use the pstree command.
# pstree -p | grep bash
|-sshd(791)---sshd(29118)---sshd(29171)---bash(29172)---sh(29428)-+-grep(29430)