Linux Up Skill – Day 11

L

Halfway through the course now and only one lesson behind. Lesson 11 of the Linux Up Skill Challenge is called “Finding things…” So we’ll be looking at searching for files and the text inside them. Sounds great! It looks like we are going to look at locate, find, grep, and which. A handy lesson indeed!

We are going to start with looking for a file called access.log. So we use locate access.log and return with an error the command is not found. Well then we’re off to sudo apt install mlocate to fix that. Then we try locate access.log again for:

david@linux-up-skill:~$ locate access.log
/var/log/apache2/access.log
/var/log/apache2/other_vhosts_access.log

The lesson points out that locate searches an index that is updated nightly by cron so if you need to manually update the index you can run sudo updatedb to accomplish this.

Now we are looking at find. It starts with the example find /var -name access.log which returns permission denied errors. If I change it to sudo find /var -name access.log I get the expected result. So it just searches the directory listed. The second example is find /home -mtime -3 which returns any file with a last modified date in the last 3 days. Neat! That’d be very handy when it is a recently touched file. find searches the filesystem directly instead of an index, which will be good to remember.

The lesson then touches on using grep -R to recursively search a directory. sudo grep -R -i “PermitRootLogin” /etc/* gives the results:

david@linux-up-skill:~$ sudo grep -R -i "PermitRootLogin" /etc/*
/etc/ssh/sshd_config:#PermitRootLogin prohibit-password
/etc/ssh/sshd_config:# the setting of "PermitRootLogin without-password".

This is pretty cool way to look into files for a specific string. The lesson does point out that this only works on plain text files but it is still very handy if you are sifting through logs.

The lesson then touches on which. This command lets me see where commands are being run from. For example, which nano is run from /usr/bin/nano.

I finish up the lesson by reading through the additional resources provided with the lesson. These are all great at helping getting into the depths of the commands.

About the author

David

I am a geek that is passionate about technology and all of the very cool things it can do.

By David

Recent Posts

Categories