How to count the number of duplicated lines in a file
Answer:
Assume you have a file "test.txt"
a
b
b
c
c
c
You want to count the number of distinct rows, here is the command
# sort test.txt | uniq -c
1 a
2 b
3 c
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 count the number of duplicated lines in a file
Answer:
Assume you have a file "test.txt"
a
b
b
c
c
c
You want to count the number of distinct rows, here is the command
# sort test.txt | uniq -c
1 a
2 b
3 c
How to remove duplicated lines in a file
Answer:
Use the following command
sort test.txt | uniq
Display who are currently logged in
Answer:
Type "who" in the command shell
# who
It will display all the users currently logged in.
E.g.
john pts/0 Jan 3 00:36 (232.127.126.23)
How to check if my system was just rebooted
Answer:
Use the following command
sudo last reboot
And it will show all the reboot information, e.g.
reboot system boot 2.6.27-7-server Sat Jan 2 19:03 - 20:39 (01:35)
...
How to generate random password?
Answer:
Install the "makepasswd" package, for example, in Ubuntu, type
sudo apt-get install makepasswd
Then execute command
# makepasswd
ShdDHNt7z
Or you can use another tool called pwgen
sudo apt-get install pwgen
and execute
# pwgen 8 10
It will generate 10 passwords with length equal to 8