Skip to main content
added 112 characters in body
Source Link
Faheem Mitha
  • 36.1k
  • 33
  • 130
  • 191

I've been using something like mktemp -u --tmpdir=. to generate a random string in the past, but it is hardly ideal, so I'm open to other suggestions. Ideally I'd like a name that looks like libc.tmp_xw3st. Ie. tmp_ followed by a 5 digit alphanumeric string.

I've been using something like mktemp -u --tmpdir=. to generate a random string in the past, but it is hardly ideal, so I'm open to other suggestions.

I've been using something like mktemp -u --tmpdir=. to generate a random string in the past, but it is hardly ideal, so I'm open to other suggestions. Ideally I'd like a name that looks like libc.tmp_xw3st. Ie. tmp_ followed by a 5 digit alphanumeric string.

added 567 characters in body
Source Link
Faheem Mitha
  • 36.1k
  • 33
  • 130
  • 191

Here is aA fuller directory listing is at the end of this posting. To summarize, I want to create additional directories like x86-headers/libc.tmpvalue, which only contains the further file x86-headers/libc.tmpvalue/C/populate.sh.

A sketch of a possible approach is to handle this in two steps as follows:

Step 1: Run over the list of top level directories using find, and create a corresponding directory structure eg dirname.tmpvalue/C/ using exec or piping to xargs and using mkdir -p.

Step 2: Run over the list of top level directories again and cp populate.sh into the C subdirectories. This is a bit sloppy, because the list of directories in theory could have altered between the two invocations of find, but this is not an issue in this case.

Here is a fuller directory listing. To summarize, I want to create additional directories like x86-headers/libc.tmpvalue, which only contains the further file x86-headers/libc.tmpvalue/C/populate.sh.

A fuller directory listing is at the end of this posting. To summarize, I want to create additional directories like x86-headers/libc.tmpvalue, which only contains the further file x86-headers/libc.tmpvalue/C/populate.sh.

A sketch of a possible approach is to handle this in two steps as follows:

Step 1: Run over the list of top level directories using find, and create a corresponding directory structure eg dirname.tmpvalue/C/ using exec or piping to xargs and using mkdir -p.

Step 2: Run over the list of top level directories again and cp populate.sh into the C subdirectories. This is a bit sloppy, because the list of directories in theory could have altered between the two invocations of find, but this is not an issue in this case.

Source Link
Faheem Mitha
  • 36.1k
  • 33
  • 130
  • 191

Make directory copies using find

I have a directory with a bunch of subdirectories in it. Thus

/usr/local/src/ccl/ccl-1.8/x86-headers$ ls
elf  gl  gmp  gnome2  gtk2  jni  libc

Each of these directories has a further subdirectory C inside it, which contains a file populate.sh. I want to create a parallel group of subdirectories with the same structure, but with a random value appended to the directory name (the random value should be the same in all cases), and only containing the C subdirectory with the populate.sh file. These directories contain other files besides the populate.sh file.

This is for a makefile, so for simplicity should probably use standard unix utilties. I'm thinking find with the -exec flag, or possibly xargs would work, but I'm having trouble making sense of the documentation, and I have little experience with shell scripting. Perl might work, but I have not used it, and would prefer not to use it here.

I've been using something like mktemp -u --tmpdir=. to generate a random string in the past, but it is hardly ideal, so I'm open to other suggestions.

So far, I've got a way of getting a listing of the top level directories. :-)

find . -maxdepth 1 -type d -print0

../gmp./jni./gl./elf./libc./gtk2./gnome2

Here is a fuller directory listing. To summarize, I want to create additional directories like x86-headers/libc.tmpvalue, which only contains the further file x86-headers/libc.tmpvalue/C/populate.sh.

/usr/local/src/ccl/ccl-1.8/x86-headers$ ls -laR

[...]

./jni:
total 96
drwxr-sr-x 3 faheem staff  4096 Jul 31 00:53 .
drwxr-sr-x 9 faheem staff  4096 Jul 31 00:53 ..
drwxr-sr-x 2 faheem staff  4096 Jul 31 00:53 C
-rw-r--r-- 1 faheem staff 19535 Jul 31 00:53 constants.cdb
[more .cdb files]

./jni/C:
total 12
drwxr-sr-x 2 faheem staff 4096 Jul 31 00:53 .
drwxr-sr-x 3 faheem staff 4096 Jul 31 00:53 ..
-rw-r--r-- 1 faheem staff  148 Jul 31 00:53 populate.sh

./libc:
total 1276
drwxr-sr-x 3 faheem staff   4096 Jul 31 00:53 .
drwxr-sr-x 9 faheem staff   4096 Jul 31 00:53 ..
drwxr-sr-x 2 faheem staff   4096 Jul 31 00:53 C
-rw-r--r-- 1 faheem staff 593125 Jul 31 00:53 constants.cdb
[more .cdb files]

./libc/C:
total 20
drwxr-sr-x 2 faheem staff  4096 Jul 31 00:53 .
drwxr-sr-x 3 faheem staff  4096 Jul 31 00:53 ..
-rwxr-xr-x 1 faheem staff 10544 Jul 31 00:53 populate.sh