Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Something like .htaccess in Linux

Tags:

linux

I have a directory with lot of files (above 4.000.000 files). All filenames has this same pattern:

PREFIX-XXXXXX-YY.ext

where

  • XXXXXX contains letters and digits
  • YY contains digits
  • ext is a extension of file (.txt, .jpg)

File structure have 12MB, so listing/searching of this directory takes long time. I divided all content of this directory to subdirectories, depends of filename, precisiously first letter of XXXXXX from pattern above.

ie.

  • main_directory/A/PREFIX-AXXXXX-YY.ext
  • main_directory/B/PREFIX-BXXXXX-YY.ext
  • main_directory/1/PREFIX-1XXXXX-YY.ext

Is in Linux easy way to make a rule, when I type in linux command for example

test:/home/usr/admin # ls main_directory/PREFIX-AXXXXX-*

I will get a list of filenames from main_directory/A/ directory? This rule MUST work only for main_directory.

like image 346
Skamielina Avatar asked Jun 01 '26 08:06

Skamielina


1 Answers

You can't have this at file-system layer, not without creating links and circling back to your original problem. I can think of two easy ways out.

Take 1: scripting

You could write a short script to rewrite the names for you.

Suppose you had a rewrite script that took PREFIX-AXXXX-* and outputted main_directory/A/PREFIX-AXXXX-*. You could then change your ls line to:

$ ls `rewrite PREFIX-AXXXXX-*`

This can be easily accomplished with sed, awk or any other on-the-fly text transformation tool.

Shell programs are composable for a reason! :)

Take 2: embed a faster file-system

You could do away with the restructuring and rewriting names by using a faster file-system, mounted in your main directory. XFS sounds good for this. It should remove your performance concerns without further ado.

This requires a deeper understanding of what's going on to be effective for day-to-day usage, however.

Edit: Here's an article on how to create virtual user-space file-systems.

Edit 2: actually no, I don't think XFS would cut it. Maybe another file-system, though.

like image 53
slezica Avatar answered Jun 04 '26 00:06

slezica