Many Linux users use the ‘find’ utility when searching for files using the command line on their system. They’ll do a simple:
find / -name ‘pattern’
Really though, the power of find isn’t just in finding names of files but rather specific details about those files. For example, if you wanted to find files which are writable by both their owner and their group:
find / -perm -444 -perm /222 ! -perm /111
or perhaps find any file that’s been altered in your Download directory in the past 24 hours:
find /home/user/Downloads/ -mtime 0
As you can see, the find command is very versatile and can be used to find an array of different attributes of files. There are times though where I’m just looking for something and I don’t want to have to wait for the command to scan the entire directory tree in order to track it down. That’s where locate comes in with quick and simple results.
Using the locate command can only be accomplished if you install the mlocate package. Most major distributions have this available. If not, head over to the mlocate homepage and install manually. Once that is accomplished, you’ll need to manually run a command to index your filesystem with it…otherwise, you’ll have to wait for the command to run automatically as it registers with cron to do so on a system level. Open a terminal and change to your root user, then execute the following:
updatedb &
This updates the mlocate database that indexes your files and forks it to the background (the ‘&’ forks it to the background). You can now logout of the terminal as root and the process will quietly work in the background.
After the command completes, using mlocate is as easy as using the locate command:
locate firefox | less
The command above will look for all files with Firefox in the name and pipe the command through less so you can use the space bar or enter key to scroll the file buffer. Of course, the reason we pipe it through less is because any file that resides in the ‘firefox’ directory will be reported in the output. While this tool isn’t as granular as the find command, it is a quick way to track down paths, directories, and files you know should exist. Since the data is indexed using the updatedb command (by cron) the results are very quick and the command does not have to scan through the filesystem to return the results.
There are plenty more advanced options via flags (such as following symbolic links, making search term case-sensitive, and even using regexp). See the man page for details on how each of these options work. Play around with locate and see what you can do! It’s a powerful and quick search command!

Category Archives: Linux Tips
Advanced use of – Find -: a handy command line tool for Linux
This post is basically directed towards new users of Linux which are not much familiar with command prompt. This is a small but comprehensive article about ‘GNU find’ .
Find Your Lost Files!
Let’s start from a simple example:
Suppose you want to search for a file named ‘master.txt’ in your home directory.
Open the Terminal and issue the following command:
find . -name “master.txt”
‘find’ will immediately show the results. If ‘find’ does not show any result, this means that the file, in our case, ‘master.txt’, does not exist. It is not always the case that you want to find something in you home directory. The lost/desired file may be anywhere in your computer. Suppose you want to find a file named ‘space-01.jpg’ and you only know that is located somewhere in /usr directory. You can find it by issuing following command in Terminal:
find /usr -name “space-01.jpg”
and ‘find’ will tell you that this is located under /usr/share/backgrounds.
Using Wildcards
Maybe you want to search for a file but you don’t know its exact name? Don’t worry! You can still locate the file using ‘GNU find’ and wildcard will help you in this regard. Wildcards are a way of searching files when you don’t know much about your desired file.
One of the commonly used wildcard is asterisk (*). Lets consider an example to better understand the things.
Suppose you want to search a file named ‘Jumping_Flowers’ but you only remember the ‘Jumping‘ part of the file name. So issue the following command in Terminal:
find . -name “Jumping*”
And it will display all the files starting with the word ‘Jumping’. You can use asterisk (*) anywhere with a file name. For example:
find . -name “*Jumping*”
And it will display all the files which contain the word ‘Jumping’.
Here are some more examples of use of a wildcard:
find . -name “Jumping*Flowers*”
find . -name “*Jumping*Flowers.mp3”
Searching For Different File Types
Sometimes you are not looking for some specific file but you are looking for a group of files. For example, you may be looking for all the .txt files in your home directory. To find all the .txt files, you will give the following command in Terminal:
find . -name *.txt
In case of mp3 files, the above command will be:
find . -name *.mp3
When You Want to Search with Respect to Time
If you want to search for files by the last time they were accessed, you can use -amin flag with ‘find’. In this case you have to put a minus (-) sign before the time. The time here is in minutes. In order to search for .doc files which were accessed in last 10 minutes, you will give the following command:
find . -amin -10 -name “*.doc”
Similarly, to search for .doc files which were modified in last 20 minutes, you will use -mmin option as follows:
find . -mmin -20 -name “*.doc”
Search For Files which are Eating Your Hard Disk
There may be files on your system which are not only huge in size but also located obscure places. You may also may not know when they were last accessed. You have to use -size option with ‘find’ to locate them.
Let’s see how we can do this:
find . -size +100M
It will list all those files which are greater than 100 Megabytes. You can replace ‘M’ with ‘G’ (for Gigabyte) or with ‘k’ (for Kilobyte)
Copy, Move, or Delete Unwanted Files on the Fly
Copy – ‘find’ can also be used to copy or backup your files. You can use ‘find’ to copy certain files from one location to other with one simple command.
Suppose you want copy all of your mp3 songs from your home directory to your Windows Partition. Enter the following command in Terminal:
find . -name “*.mp3” -exec cp {} /path/to/Windows_Drive \;
And all of your mp3 files will be copied to the desired Drive/Folder.
Move – There may be situations that you quickly want to move all of your document files from your Hard Disk to your USB to keep them safe. To move all of your documents from your home directory to your USB, you will issue the following command:
find . -name “*.doc” -exec cp {} /path/to/USB \;
Delete – Suppose there are a lot of .tmp files and you want to get rid of them at once. Again ‘GNU find’ is at your service and does the work for you. Issue the following in Terminal and all of the .tmp files are gone…
find . -name ‘*.tmp’ -exec rm {} \;
Which Files are Owned by You and Which Are Not?
There may be a situation when you want to know that which files in some other directories (or even in your home directory) are owned by some other user of your computer.
Suppose there is another user named ‘blackstar’ with whom you are sharing your PC. Now you want to know that which .doc files in Windows Directory is owned by this user ‘blackstar’. You can do this by issuing the following command:
find /path/to/Windows_Drive -user blackstar -name “*.doc”
Just replace ‘blackstar’ with your username to search on your system.
Direct the Output of ‘find’ to a File
You can save the results of your ‘find’ command to a text file which will allow you to examine the results in detail at some later time (or to create playlist of your songs). For this purpose a greater than (>) sign is used (referred to as “piping the command”).
Suppose you want to save the list of all the mp3 songs in your home directory to a text file (which you can later share with your friend), you can do this by:
find . -name “*.mp3” > mp3.txt
It will save the complete path to all of your mp3 songs in the file named mp3.txt.

Create ‘alias’ (shortcuts to commands) using Linux Sophisticated Commands
Long sophisticated instructions are usually not solely tough to recollect but in addition take a lot of time to be typed. When it’s a must to use them on day by day foundation, you turn into annoyed when typing them repeatedly and again… So, ‘alias’ are extra appropriate for lengthy and complex commands.
Let’s think about an example.
To find the top 10 largest files in your system, you can set the next ‘alias’:
alias top10files=”find . -type f -exec ls -sh {} \; | sort -n -r | head -10”
You can even combine different instructions with ‘alias’. As an illustration, if you happen to often use ‘tail’ and direct its output to file to later view that file, you may set a very simple ‘alias’ to do this cumbersome operation in 1 word:
alias Tail=”tail /var/log/messages > hello.txt;cat hello.txt”
Now just enter ‘Tail’ and voila! All is done at once.
You need to use any file with tail and direct its output and you’ll even use ‘nano’ or ‘vi’ to view/edit its output.
Here’s one other example… ‘alias’ to connect to a remote server:
alias any_name=”ssh -l -p ”
You possibly can even create ‘alias’ on your bash scripts, like:
alias clc=”sh /home/user/myscripts/calc.sh”
Now that you have set a number of totally different ‘alias’ you may want to test that which ‘alias’ are set in your system. To do that, simply difficulty the next command:
alias
and it will list all the set ‘alias’ you have.
To remove an ‘alias’, just issue the ‘unalias’ command, like:
unalias Google
and now typing Google in Terminal will do nothing (as it was set with lynx).
To remove all the ‘alias’, issue the following command and all the ‘alias’ are gone:
unalias -a
We have mentioned the way in which of setting the ‘alias’ for different sorts of commands. However setting ‘alias’ in this approach be temporary. While you reboot you PC, all the ‘alias’ which you will have set will probably be gone. This does not mean that it’s a must to set all of the ‘alias’ each time you boot your PC. You probably have set an ‘alias’ and you favored it a lot that you really want it to completely reside in you PC, simply add this alias in ‘.bashrc’ file in you dwelling directory. For example, if you would like ‘alias’:
Set up <software_name>
to permanently reside in your PC then user your favorite text editor and add the following line in your ‘~/.bashrc’ file:
alias Install=”sudo apt-get install”
Now this ‘alias’ will not vanish into thin air when you reboot your PC. Only those ‘alias’ which are listed in ‘~/.bashrc’ file will be permanent.
This information is just a preview about ‘alias’. It’s just about primary ways of using ‘alias’ to make your life simpler. ‘GNU alias’ is a instrument which can simplify your life immensely. But sadly this device isn’t given the attention it deserves. Briefly, it is such a strong tool that when you give it proper time, it could possibly make you overlook typing.

Ubuntu to Windows XP folder sharing
Computer networks are sometimes comprised of various OS and while operating a network made up fully of Ubuntu desktop and server computer systems would definitely be enjoyable, some community environments can consist of both Ubuntu and Microsoft Windows systems working together.
If you want to make an Ubuntu shared folder be accessible to Windows XP, run the NTFS configuration tool on the drive.
Don’t forget that it is advisable to have admin rights to do that modification.
Select application->Accessories->Terminal
then type the following:
sudo gedit /etc/samba/smb.conf
and in the [global] section add the following line:
usershare proprietor only = false
Using iPhone internet sharing over bluetooth under Linux
To use your iPhone’s internet connection through a Linux notebook over bluetooth, you have to open Tethering option on your iPhone device, under the Settings->General->Network section.
After that you can install Blueman (a simple and intuitive bluetooth manager) for easily configuring bluetooth PAN network:
apt-get install blueman
Start blueman-manager and find your mobile device and connect to it. When connection completed successfully, select Device->Add->Network Access Point in blueman-manager.
And the last step, configure the network interface:
dhclient bnep
Logwatch on Ubuntu Desktop/Server
Logwatch is an Ubuntu modular log analyzer that runs every night and mails you the results. It can also be run from command line. The output is by service and you can limit the output to one particular service. The subscripts which are responsible for the output, mostly convert the raw log lines in structured format.
Logwatch generally ignores the time component in the output, that means, you will know that the reported event was logged in the requested range of time, but you will have to go to the raw log files to get the exact details.
Install logwatch using the following command:
sudo apt-get install logwatch
This will install all the required packages
Configuring Logwatch:
first you need to make sure you server is able to send the mails outside you can do this using postfix with SMTP server configuration.
Now you need to edit logwatch.conf file:
sudo nano /usr/share/logwatch/default.conf/logwatch.conf
Change the following information:
Output = mail
Format = html
MailTo = test@gmail.com
Save and exit the file
If you want to know more available options check logcheck manpage using the following command from your terminal:
man logcheck
Now edit the 00logwatch file
sudo nano /etc/cron.daily/00logwatch
add the following line:
/usr/sbin/logwatch –mailto test@gmail.com
Save and exit the file
Maximize internet speed connection in Ubuntu via sysctl
Do you want to maximize your bandwidth? Here are few important settings you should do to speed up your internet and it works in Ubuntu and all Linux operating system via sysctl.
First open a Terminal via Applications->Accessories->Terminal
Type:
sudo gedit /etc/sysctl.conf
Then Paste the Following at the end of the file:
# increase TCP max buffer size setable using setsockopt()
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
# increase Linux autotuning TCP buffer limits
# min, default, and max number of bytes to use
# set max to at least 4MB, or higher if you use very high BDP paths
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
# don’t cache ssthresh from previous connection
net.ipv4.tcp_no_metrics_save = 1
net.ipv4.tcp_moderate_rcvbuf = 1
# recommended to increase this for 1000 BT or higher
net.core.netdev_max_backlog = 2500
# for 10 GigE, use this, uncomment below
# net.core.netdev_max_backlog = 30000
# Turn off timestamps if you’re on a gigabit or very busy network
# Having it off is one less thing the IP stack needs to work on
#net.ipv4.tcp_timestamps = 0
# disable tcp selective acknowledgements.
net.ipv4.tcp_sack = 0
#enable window scaling
net.ipv4.tcp_window_scaling = 1
Press Ctrl-S to save, then alt-F4 to exit and then type:
sudo sysctl -p
to apply the settings.
Now, check your speed using speed-test site or download files in the net.
You can disable all these settings by removing these lines you added via:
sudo gedit /etc/sysctl.conf
How to manage podcast and RSS reader on Firefox!
This week, in our Linux Page (in Spanish), we posted some lines about editing and changing the feed/podcast reader on Firefox when you have previously chosen a specific program to automatically subscribe to podcasts. If you are using Firefox 3.5 on Linux, you can simply go to Edit -> Preferences and type Feed in the search bar. At this point you have a button menu with all the different options; we suggest to select the Preview in Firefox one. If you have an older version of Firefox that does not allow you to follow the above path (or for some reason, by default, you prefer the most difficult way) you have to open a new Tab and type about:config in it. After a brief warning message you can type Feed in the location bar and find the browser.feeds.handler line. At this point it is necessary to change the value field to Ask and next time you will decide to subscribe a podcast you will free to choose your favourite program. We hope this few lines could be useful and easy to execute for you all!

How to solve a bug in Imagewriter (write a.img file on a USB device)
This week in our Linux Page (in Spanish) we posted a brief suggestion about a problem (better a bug) we found when you used Imagewriter. In fact we tried to write an image on a USB key but it stopped different times reporting in “Details”, as last information /dev/sdh successfully unmounted; where sdh was obviously our USB key. First of all, using (System – Administration) Synaptic Package Manager, we tried to reinstall Imagewriter but only after some time on internet we solve the mistery… For some reasons Imagewriter runs better if the .img file is as near as possible to the Home folder. In our case we copied the image file on the User folder after the Home and in the next test we made we successfully wrote the file on sdh (our USB device). We hope this simple tip could be useful for some of you!

How to convert pdf to html on Ubuntu 9.04
This week, in our Linux Page (in Spanish), we tried to find how to freely convert pdf to html files. Unfortunately we have not been able to discover a satisfying solution. In fact, first of all (1) we upload our complex pdf file (text, color drawing and pictures) on Gmail email and we sent it to ourself. When we opened the email we click on “view as html” option and we were able to read the text (unfortunately too tiny) without drawings and pictures. It was not bad but we were really far from what we were looking for. As second experiment (2) we tried to use Kword and we had (as html) text and pictures but there were many incongruences between the texts and the borders and we missed some phrases. In few words, we had a better look but a worse result. Then (3) we installed pdftohtml using Synaptic Package Manager but unfortunately we were not satisfied from the html file we obtained. At this point we concentrated our researches on a free online solution and in order we tried: “Online conversion tools for Adobe PDF documents“, “convertpdftohtml“, “pdftextonline“, and “pdf-search-engine” but the results were not good. Unfortunately, we dismissed and I confess we could not find a solution to solve the task but we think that the “Kword solution”, if improved, is not far from a good solution in converting the file from pdf to html. Please, if you have suggestions about this topic, feel free to add a comment. Thank you.

