sed: replace in place
Answer:
Newer version of sed allow you replace a file in place, no more redirection is needed.
# sed -i 's/abc/def/g' test.txt
The above command will replace all "abc" to "def" in the file test.txt
Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.
sed: replace in place
Answer:
Newer version of sed allow you replace a file in place, no more redirection is needed.
# sed -i 's/abc/def/g' test.txt
The above command will replace all "abc" to "def" in the file test.txt
How to get the file creation time?
Answer:
Linux never stores file creation time.
You can only get access, modify & change (change of status, e.g. permission) time of a file with stats command
# stats test.txt
stat test.txt
File: `test.txt'
Size: 25557 Blocks: 56 IO Block: 4096 regular file
Device: ca01h/51713d Inode: 32714 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1001/ user) Gid: ( 1000/ user)
Access: 2010-01-02 18:53:46.000000000 +0800
Modify: 1970-01-01 17:13:08.000000000 +0800
Change: 2010-01-02 18:53:46.000000000 +0800
Turn off PC speaker in Ubuntu Linux
Answer:
To turn of PC speaker so no more beep sound in Ubuntu
1. edit /etc/modprobe.d/blacklist
# sudo vi /etc/modprobe.d/blacklist
2. append the following line, save the file.
blacklist pcspkr
Restart your system to take effect.
How to perform checksum on a folder?
Answer:
Previous article told you how perform checksum on a file. How about to perform checksum on a folder?
A simple solution is to install md5deep
# sudo apt-get install md5deep
To perform checksum on a particular folder (input),
# md5deep -l -r input
26ab0db90d72e28ad0ba1e22ee510510 input/2.txt
6d7fce9fee471194aa8b5b6e47267f03 input/3.txt
b026324c6904b2a9cb4b88d6d61c81d1 input/1.txt
That's so easy.
Reference: http://md5deep.sourceforge.net/
Reset MySQL root password
Answer:
If you have forgotten the MySQL root password, follow the steps below to reset the root password (for Ubuntu/Debian).
1. Shutdown MySQL
# /etc/init.d/mysql stop
2. Startup MySQL using command without grant tables, take the process to run in background
# /usr/bin/mysqld_safe --skip-grant-tables &
3. Login into the MySQL database
# mysql --user=root mysql
4. Reset password
mysql>update user set Password=PASSWORD('newpassword') WHERE User='root';
Query OK, 2 rows affected (0.03 sec)
Rows matched: 2 Changed: 2 Warnings: 0
mysql>flush privileges;
Query OK, 0 rows affected (0.02 sec)
5. Shutdown MySQL
Bring the MySQL server process to foreground now and kill it by Ctrl-C
# fg
[Ctrl-C]
6. Start MySQL using normal way
# /etc/init.d/mysql start
That's all.