In the last chapter of ‘The Lord of the Linux’ we learnt the power of the network commands. Now we have to progress in our journey and face the power of the two letters.
For those how are not LOTR geeks: I’m doing a reference to the movie ‘The Two Towers’. In this case instead of towers we have letters. Not all the commands are long and complex words, we can also find a few commands with three or two letters. Now, in honor of the ‘Two Towers’ we are going to list a few use cases where we use two letters commands.
for log rotation
In our logstash instance we have a few custom scripts for log rotation. These scripts list all the files in a directory with the command
for FILE in $(ls $DIR); do
After that we move/copy the files to a new location with:
mv $DIR/$FILE.new $DIR/$FILE
cp --archive $OLD_DIR/$FILE $ARCHIVE_DIR/$FILE.new
We are using cp instead of mv if we want to rotate the logs in a different filesystem.
linking apache site configuration
In order to avoid the duplication of sites configuration on apache for sites-available and sites-enabled we have a link between the files in sites-enabled pointing to the files in sites-available. We can do this with a symbolic link with the command
ln -s /etc/apache2/sites-available/SITE /etc/apache2/sites-enabled/SITE
If you don’t know the difference between symbolic and hard link I found a very useful article: symbolic and hard links.
where is my jvm?
The ps command shows processes running in the system. In this case we are looking for our JVM process so we will use the following command to check the java process:
ps -ef | grep java
We used to have more than one java process running at the same time so I added another grep for the name of the process:
ps -ef | grep java | grep --color cassandra
The ‘–color’ will color all the ‘cassandra’ so it will make it easier to find out where our process is.
One way to test our web servers is ab which is an Apache benchmarking tool. We can use ab to inform us whether our Apache instance will be able to deal with a reasonable number of concurrent requests. Here is an example:
ab -k -n 1000 -c 5 http://HOSTNAME/index.html
testing new configuration
Sometimes we have to edit a configuration file for services or JVMs (for example the apache2.conf for apache2). A way to do this is by editing the configuration file, suspend the editing process with Ctrl+z, send the job to the background with the command:
Restart the service or JVM, check that the configuration is ok and if not you can call the job to the foreground with the command
and edit again the configuration file.
how to find big log files
In exceptional circumstances we have rogue processes generating vast amounts of logs filling our disk space. We use df and du to find the problematic files. In order to check the disk space in the volumes we use the command:
The -h is for ‘human’ readable output. We also use the command:
which shows the disk usage statistics. More specific we use the command:
du -h -x —max-depth=1 | sort -h
in order to show a sorted list of disk usage for all the files with a max depth of one folder.
Are you impressed by the power of two letters yet? If you are or just have more examples of two-letters commands please let us know on Twitter.
If you enjoyed the read, drop us a comment below or share the article, follow us on Twitter or subscribe to our #MetaBeers newsletter. Before you go, grab a PDF of the article, and let us know if it’s time we worked together.