directory

20+ Unix/Linux find command examples

Linux/Unix FAQ: Can you share some find command examples?

Sure. The Unix/Linux find command is very powerful. It can search the entire filesystem to find files and directories according to the search criteria you specify. Besides using the find command to locate files, you can also execute other Linux commands (grep, mv, rm, etc.) on the files and directories you find, which makes find extremely powerful. 

A Scala function to list subdirectories in a directory

If you ever need to generate a list of subdirectories in a directory in Scala, here's one way to do it:

def getListOfSubDirectories(directoryName: String): Array[String] = {
  return (new File(directoryName)).listFiles.filter(_.isDirectory).map(_.getName)
}

I intentionally wrote that function in a short, "Scala like" style, but you can expand it to multiple lines, if you prefer.

To demonstrate the use of this directory-listing function, you can print all your subdirectories like this:

How to search multiple jar files for a string or pattern

Here's a shell script that I use that search Java jar files for any type of pattern. You can use it to search for the name of a class, the name of a package, or any other string/pattern that will show up if you manually ran jar tvf on each jar file. The advantage of this script -- if you're a Unix, Linux, or Cygwin user -- is that this script will search through all jar files in the current directory.

Handling spaces in Linux shell script input (and for loops)

Linux shell script FAQ: How can I deal with spaces (blank spaces) in my input data when I'm writing a shell script for loop or while loop?

I was just working on a Linux shell script, and ran into the ages-old problem of handling data that has spaces (space characters) in it. I run into this any time I try to read a data file with blank spaces in it, or when I run into files and directories with spaces in their names. Whenever I try to work this data like this in a shell script for loop, the spaces always ruin what I'm trying to accomplish.

Mac backups - handling spaces in filenames with find, tar, and xargs

This morning I decided to take a few minutes to backup all the songs I've purchased over the last half-year. These are all on my Mac OS X system, under the Music folder in my home directory.

The problem with trying to do this with standard Unix tools is that all these subdirectories and filenames have spaces in their names. Just looking at the Music folder, it contains many directory names like this:

PHP warning - Unable to load dynamic library ./apc.so (Solution)

While installing the PHP APC opcode cache, I just ran into the following error:

PHP Warning:  PHP Startup: Unable to load dynamic library './apc.so' - ./apc.so: 
cannot open shared object file: No such file or directory in Unknown on line 0

I found this error message in my PHP error log, but depending on your configuration I think it may also be in your Apache error log file.

An Apache 301 redirect for a deleted directory

I recently reorganized the devdaily.com website, and as part of that, I deleted an entire directory at the root level that was named "/Dir". This was the "directory", where I had a Yahoo-like directory of links to applets, tutorials, CGI scripts, and so on, so I had thousands of web pages with URLs like these:

How to create directories in Java

Java directory FAQ: How do I create a directory (or directories) in Java? (Also written as, "How do I make a directory in Java?)

To create a directory in Java, just use the "mkdir" or "mkdirs" methods of the Java File class. Here are a few examples to demonstrate this.

The Linux chmod command

Linux chmod FAQ: Can you share some examples of the Unix/Linux chmod command? (Also written as, "How do I change permissions on Unix files and directories?")

The chmod command name stands for "change mode", and as that name implies, the chmod command is used to change the mode of Unix/Linux files.

I'll start with some simple Unix chmod command examples, then add some more details as we go along.

chmod - Make a script executable

The chmod command is commonly used to make a file "executable", like this:

The old directory has been removed

Sorry for the inconvenience, but the old devdaily.com "directory", formerly available as URLs like these:

/Dir/...

has been removed. With terrific search engines like Google, there wasn't much need for the directory any more.

I'm sorry for the inconvenience. If I can help you find what you're looking for, just send me an email.

Thanks,
Alvin Alexander
devdaily.com

 

 

 

Syndicate content