Print sequences of numbers in Linux
Answer:
To generate a sequences of numbers from 1 to 99, you can try the `seq` command, e.g.
# seq 1 99
To reverse from 99 to 1, simply
# seq 99 1
Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.
Print sequences of numbers in Linux
Answer:
To generate a sequences of numbers from 1 to 99, you can try the `seq` command, e.g.
# seq 1 99
To reverse from 99 to 1, simply
# seq 99 1
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.