Linux CLI: File Text Search & Replace

Occasionally you need to change the contents of some files easily to save a lot of manual work. In my case it was a server migration, the old IP address of a server was referred to from numerous DNS records. This meant the contents of a couple of hundred Bind zone files would also have to change so that they would reflect the new server address. This is task that would take way too long to do manually, luckily grep and sed can automate the process. In this post I will show you how to recursively search for and change a string in all files that exist below a directory. The format for doing a recursive search / replace looks like: grep -rl ‘search_term’ ./ | xargs sed -i ‘s/search_term/replacement_text/g’ Continue reading “Linux CLI: File Text Search & Replace” »

By |December 19th, 2013|Linux|0 Comments

Command Line Tips: Program Execution

Executing commands is an integral part of using any Linux system. To follow up on my post about navigating file systems from the command line ( Linux Tips: File & Directory Handling ) more effectively, I am I have picked up over the years. Discovering What Shell You Are In Finding exactly out what shell you are currently using in a terminal can be determined using a variety of different techniques. Some of which are: Using the ps command to display the name of the shell process ( $ is a shell variable that reflects the pid of the current shell ). ps -o command $$ You can echo the $0 variable which will display the name of the shell script. echo $0 Or you can also echo the $SHELL environment variable which will display your shell script echo $SHELL Continue reading “Command Line Tips: Program Execution” »

By |July 2nd, 2013|Linux|0 Comments

Linux Tips: File & Directory Handling

My desktop and all of the servers I own are Linux or Unix based. So as a result I tend to find myself in a terminal navigating file systems and working with files more often than not. Command line file management allows you to wield crazy amounts of power but it doesn’t have to be all hard work. Here I am going to run you through some of my favorite simple file and directory related tips for working at the command line. Continue reading “Linux Tips: File & Directory Handling” »

By |June 25th, 2013|Linux|0 Comments

Deleting all mail for a local server account

It happens, cron jobs can and will go wrong occasionally and when they do, they love to send alerts to the job's owner hoping for a little attention. An alias can always be added to the /etc/alias file directing all of the mail for an address to to /dev/null but most of the time thats [...]

By |June 17th, 2013|Linux|0 Comments

Watching the progress of a dd action

dd is one of those indispensable Unix / Linux utilities whether its cloning or wiping a drive or simply creating a bootable flash drive from an image file. The problem is operations like wiping a drive with the output from /dev/zero can take an extremely long time especially on larger hard drives. In situations like this it can be handy or somewhat soothing for the impatient to know how far through the requested action the process is. Luckily its pretty simple to find out, simply open a new tab and execute: pgrep -l ‘^dd$’ Continue reading “Watching the progress of a dd action” »

By |June 22nd, 2012|Linux|0 Comments

Quick Recursive Code Count

Although the “lines of code” in a project is not the worlds most useful metric. Curiosity sometimes gets the better of us and after many days / weeks of typing you think “gee I wonder exactly how many lines of code are in that project?”. Wonder no more! By embracing the power of the command line you can easily count the lines in every file recursively. Simply execute the following line in the directory of your project (changing .php to the file extension of the files you would like to count the line of): find . -name ‘*.php’ | xargs wc -l Continue reading “Quick Recursive Code Count” »

By |May 4th, 2012|Linux, Programming|0 Comments