|
Linux Scripts |
||||
|
Short, Easy, Useful Linux Batch File Commands |
||||
|
|
||||
|
MyFind - usage: ./myfind <filename>
When doing setup, configuration, and maintenance on my systems, I wanted a Linux 'Search' command that would find a file on my system, but not get bogged down in the hundreds of Gigs of personal data I have on disks which are mounted in the 'mount' directory. A full system search takes a minute or two. What I wanted searched takes less than 30 seconds. For every instance that matches the parameter, 'myfind' returns the filespec of that match. In other words, for every time 'myfind' finds a match for the file you seek, it displays the full path to that file. If you tell Linux 'find /' it does indeed search your entire system, but again, for me that is about 10 Gigs of relevant, system, Linux files and 2000 Gigs of Data (text, scans, music, images, etc.) which I'm not interested in. These are probably mounted network drives anyway which are not even on the machine I'm working on. There are ways to do this. There are ways to specifically exclude directories from the 'find' search path but I am not THAT conversant with the command line. I know lots of commands and what they do, but it has to be something really special for me to start seriously hacking command line syntax. Find was such a case. My Linux experience got to be such that I was hacking a lot of .config files all the way down the line from the Gnu interface, to the Evolution setup, to the config files for Apache and MySQL. This easily totals dozens of config files in 10 directories. Every time a help file mentioned another config file, I had a 10 minute hassle trying to find it. Often the help files cannot specify the exact directory where the config file is located because often the location depends on the exact build. In other words, if you compile Apache for one Linux distribution on one machine, the file will be in a different directory than when you compile the same program for use on another machine or another distribution of Linux. 'MyFind' helps with that. It is a simple batch/script file. It does need to be run as root and needs to be run on the path, but my pea brain can remember all that. Usage is also simple. On the command line just type: ./myfind <filename> 'myfind' needs to be run on the path because if your command line is not logged onto the directory where 'myfind' resides, your system will not be able to find 'myfind'. Alternatively, if you don't know what the path is or how to manipulate the path, you can just save 'myfind' in your /home/user directory and log into that directory every time you run 'myfind'. Note: as you are running as root, you can't log into ~ as /home/<your username> which as root is /home/root. You have to log into /home/<your username>. Also 'myfind' needs to be run as root (as administrator) otherwise, if run as a user, every time 'myfind' is about to search a directory and you don't have access to that directory, 'myfind' will just say that (no access) rather than telling you if there is a copy of the file you're looking for in that directory. The dot and slash preceding 'myfind' have to do with running script/shell files. I can't remember the details offhand, but you can look up any intro to script/batch/shell files for details. ' myfind' is the name of the batch file and is case sensitive. You can name it what you wish, but you must type it exactly as you have named it. Note that the parameter which follows 'myfind' is just the <filename> not the full filespec. The path part of the filespec is what you are looking for with myfind. You don't know it. You do know the file name and can enter that. You can also use wildcards in the file name. For instance you can type: ./myfind *.conf That will return all the files on your system with the extension .conf. Here is the file you need to save as 'myfile': #!/bin/sh
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
| *
Compressed files are used to make file transfer times faster and more
efficient. If you are using Win98 or lower, you can easily download
a free copy of a compatible unZip utility at www.7-zip.org. If you are using WinXP or higher, zip file compression is automatic. In current releases of Linux, zip file compression is automatic but I also indlude links to .tar.gz files. *.PDF files are Adobe Portable
Document Format. The PDF viewer is available free from www.Adobe.com. |
||||
| Top of Page | ||||
© Western News Company (Chicago) 2008 all rights reserved. |
||||