To delete a file recursively:
find . -name ‘*.DS_Store’ -type f -delete
To delete a directory recursively:
find . -type d -name ‘.svn’ -print -exec rm -rf {} \;
To delete a file recursively:
find . -name ‘*.DS_Store’ -type f -delete
To delete a directory recursively:
find . -type d -name ‘.svn’ -print -exec rm -rf {} \;
Grep suits the bill for all my requirement for efficient search of files containing text in Linux and Mac. The following commands detail the use cases of grep.
Search for pattern
grep -rnw 'folder' -e 'text'
-r stands for recursive.
-n is the line number.
-w stands for whole word match.
Example: grep -rnw . -e 'import'
This searches for the the text ‘import’ in the current directory recursively.
Found this tip at stackoverflow.com.
I use Fiddler extensively in Windows for debugging any HTTP traffic in my web applications. However on Mac Fiddler is not available. On some search I have found out the following tools which can do the job:
Chrome
In Chrome just type “chrome://net-internals/#http2” in the address bar and you will be able to see all the HTTP traffic that is going on in your system. Not sure when it got added to Chrome but it is a very simple yet powerful utility.
Charles Proxy
This is Java based commercial utility which can be used for almost Fiddler like functionality. This works in Windows, Linux and Mac so it is good deal I think for any developer.
Update: On using Charles Proxy I found it to be dead simple to use and it fulfilled all the requirements I had on my Mac. There is 30 minute lockout feature for unlicensed version which seems fair. It is completely worth the 50$ price tag.
I found out that my server had run out of space which was very strange given the fact that there is no heavy disk activity happening on the server. I used the following script to find out the offending files which were taking maximum space.
for file in ./*; do du -sh "${file}"; done
or
du -sh ./*
or
du -ash .
I needed to find the different file extensions inside a folder in Debian Linux. I used the following command to do it.
find . -type f | perl -ne 'print $1 if m/\.([^.\/]+)$/' | sort -u
I found this code in this link.
I recently received a blob of data which needed some alteration to properly suit the CSV format. I found that the data file ‘xyz.dat’ contained close to 600,000 rows so writing a VBA script in Excel to format the data was not an option. I opted to do it using some plain commands in Unix. I had to attain the following purpose:
1. Remove all rows with blank lines.
2. Remove all rows that didn’t start with the number ‘1’
3. Trim the file to 1000 rows to sample the data.
I executed the following commands to attain the above objectives.
To remove all blank lines I used this command. I am basically asking grep to treat the text as ASCII text and using a regular expression to identify blank rows:
cat xyz.dat | grep -a -v -e '^[[:space:]]*$' > xyz_no_space.dat
To remove all rows that don’t start with ‘1’ I used this command. This command is similar to above command except for the regular expression to identify rows that start with ‘1’.
cat xyz_no_space.dat | grep -a '^1' > xyz_no_space_start_with_1.dat
At this point we have the data we want but for sampling purpose I need to copy first 1000 rows into another file. This command uses ‘sed’ to do it.
sed -n -e '1,1000p' xyz_no_space_start_with_1.dat > xyz_trimmed_1_1000.dat
This command basically renames the *.dat file into *.csv for convenience.
mv xyz_trimmed_1_1000.dat xyz_trimmed_1_1000.csv
A summary of all commands I executed is listed below:
cat xyz.dat | grep -a -v -e '^[[:space:]]*$' > xyz_no_space.dat
cat xyz_no_space.dat | grep -a '^1' > xyz_no_space_start_with_1.dat
sed -n -e '1,1000p' xyz_no_space_start_with_1.dat > xyz_trimmed_1_1000.dat
mv xyz_trimmed_1_1000.dat xyz_trimmed_1_1000.csv
I wanted to try out Tomcat 8 and Java 8 for one of my production servers. The following link summarizes the various steps required for installing and configuring both Java 8 and Tomcat 8 from scratch.
The Jenkins CI server can be integrated with BitBucket by using the concept of deployment keys. In BitBucket go to Settings > Deployment Keys. Add a new public key. Make sure you are adding an openssh compatible public key otherwise the key won’t be accepted. Once this is done you need to test the read-only cloning capability using this approach.
ssh-agent (ssh-add /home/user1/ssh_keys/my_private_key; git clone git@bitbucket.org:my_user/my_project.git)
This command basically attempts to make a clone from the BitBucket server using the private key you specified as ‘my_private_key’. Since we are using the ssh-agent command to wrap the other two commands the key is loaded, the clone command is executed and then immediately the key is unloaded. If your cloning process failed you know that something is wrong. Remember you need the private key in openssh format as well.
If the above command gave you the cloned repository, go ahead and use this private key inside the Jenkins server.
Please do refer to BitBucket documentation link has more details on the exact steps.
I was trying to setup Jenkins web app inside the Tomcat server and it continuously gave me this error:
SEVERE: Failed to initialize Jenkins
hudson.util.NoHomeDir
This I fixed by creating the folder ‘/usr/share/tomcat7/.jenkins’
mkdir /usr/share/tomcat7/.jenkins
On redeploying Jenkins I again noticed the following error.
WARNING: Failed to record boot attempts
java.io.FileNotFoundException: /usr/share/tomcat7/.jenkins/failed-boot-attempts.txt (Permission denied)
I fixed this issue by giving full access to this folder.
sudo chmod 777 /usr/share/tomcat7/.jenkins
I believe 777 is not a good approach in a production environment, but for development perspective it looks ok.
I recently had to find out if a particular package was properly installed in my Debian Linux OS as something was broken. I used the following command to do that.
dpkg --get-selections | grep -v deinstall | grep oracle
This basically lists out all the packages which contain the text ‘oracle’ in them. Once I find out the exact package name I can actually decide to remove all packages containing them.
sudo apt-get purge oracle*
sudo apt-get autoremove oracle*