- Welcome to Geeksww.com
Removing lines with strings from text files on Linux/Mac OS X
I used this technique to remove strings from bash history file containing passwords and other sensitive data on a Mac OS X shell (command line). In my case, this was a precautionary measure to make sure I erase any sensitive data from history files. For example, this is important for folks who enter mysql username and password on command line (with the 'mysql -p' command).
Lets say you want to remove lines containing the string 'password' (without quotes) from bash history file, then you'd use the awk command below. Please make a secure/encrypted backup copy of the original file in case you need it in future or have to restore for any reason:
awk '!/password/' ~/.bash_history > temp && mv temp ~/.bash_history
Please note that the command above erases lines and prints remaining content into a temporary file (named temp in example above). Then, moves (using mv in example above) the temporary file to original bash_history file.
Another technique is to use sed in a similar fashion.
sed '/password/d' ~/.bash_history > temp && mv temp ~/.bash_history
Bash history is stored in ~/.bash_hisotry file for the current user.
Did this tutorial help a little? How about buy me a cup of coffee?
Please feel free to use the comments form below if you have any questions or need more explanation on anything. I do not guarantee a response.
IMPORTANT: You must thoroughy test any instructions on a production-like test environment first before trying anything on production systems. And, make sure it is tested for security, privacy, and safety. See our terms here.
tags cloud
popular searches
free download for mysql database server 5.1.5, bison, gearman, source code, php, install cairo, laptop, mysql, java, linux, install mysql, mysql initialization, mysql mysql, tools, ubuntu
Similar Tutorials:
- Install MySQL Server 5.0 and 5.1 from source code
- How to download, compile, and install CMake on Linux
- Download, configure, compile, and install MySQL 5.6
- Installing Libpng on Ubuntu Linux
- How to setup Spamassasin to run as a deamon?
Tutorials in 'Operating Systems > MacOS X' (more):
- How to SSH into EC2 instances without identity file and password?
- Configuring MacOS X to compile and install open source software using XCode Tools
- Installing Atmail Webmail Client on Mac OS X (PERL)
- How to print screen in a file (Mac OS X)
Comments (write a comment):
0 comments so far. Be the first one to leave a comment on this article.
leave a comment