Posts Tagged ‘files’

Using locate to search for files from the terminal

Sunday, April 15th, 2012 | Life, Tech

Need to locate a specific file somewhere on your system? Luckily, there is an appropriated named search tool which you can use to do that. It’s called locate and it’s very similar to file search in Windows file manager.

Not all Linux installs come with locate, so you may need to install it.

yum install locate

Also, the first time you run it, it will need to build the database, so that will take a little longer. But once it is up and running, it is pretty fast. Simply use the command followed by a file name, or even just part of a file name, to get a list of all the files on your system that match.

locate httpd.conf

Following files using tail

Saturday, March 3rd, 2012 | Life, Tech

Tail is a useful command which allows you to see the end of a file. This is probably most commonly used when you want to look at log files as the entries of most interest are usually at the bottom. For example, if you wanted to view the last 50 lines of a log file you could use the following command.

tail -n 50 filename.log

A cool feature of tail is that you can also follow a file – that means continually monitoring it as changes come in. So if you are looking at the Apache error log for example, you could begin tailing the log and then cause an error and you will see it instantly come through on the log.

tail -f error_log

Saving files in memory

Thursday, February 16th, 2012 | Life, Tech

If you need super quick access to a file, for example a log file which isn’t going to be too big but it being used by a script which is time critical, then rather than writing it to disk, you can mount part of your file system in memory and write to it there.

This has the disadvantage that when you restart your system, you will lose the data. But for test scripts, logs or other temporary files that you don’t mind getting lost, it can really speed up performance.

Luckily, most systems come with a an area mounted in memory already – so you don’t even need to configure it!

cd /dev/shm

If said directory exists, you’ll have a memory mounted directory already and can start using it immediately.

List locally modified CVS files

Wednesday, December 28th, 2011 | Programming, Tech

Quick command for listing locally modified CVS files.

cvs -Q status | grep -i locally

Using Server.MapPath in ASP

Wednesday, December 29th, 2004 | Programming, Tech

Server.MapPath is used to create a file path from a virtual path.

Here’s a typical DNS-less database connection:

Connection = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=C:\wwwroot\users\someaddress\db\data.mdb"

This isn’t much good though if you don’t know the full file path and if you are using a web host the chances are that you won’t know it. So you can use Server.MapPath instead.

Lets say that database is on the internet at the following address. Not that it is a good idea to have your database web accessible of course.

http://www.someaddress.com/db/data.mdb

Instead of having to use the file path as the top you could use a virtual path:

Connection = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" + Server.MapPath("/db/data.mdb")

This would get the server to “map” a file path to the database from the virtual path you give it. Notice that after DBQ= the tag (“) is closed as you don’t want the server to think + Sever.Map… is part of the file path.