03-10-2010
Sorry for the confusion, but I was looking for duplicate commands (or duplicate executable files) but NOT duplicate directories.
For example, while the authentic copy of the executable file "openssl" resides in /usr/bin/, another copy of "openssl" may reside in /sbin/ by accident or by malicious intention. I would like to detect whether multiple copies of an executable file with the same name exist in different directories.
To simplify the problem, assume that I am looking for files whose name is "openssl". The search for "openssl" should be done through the directories listed in PATH (the command search path). I do not want the search to waste time in looking into directories that are not listed in PATH.
I would like the search method to meet the following two conditions. First, the search has to work even if a directory name contains a space. Second, I prefer not to modify the global variable IFS.
I showed two codes in Post #1. The first code met the second condition, but failed in the first condition.
find `printenv PATH | sed "s/:/ /g"` -maxdepth 1 -name openssl
The second code met the first condition, but failed in the second condition.
IFS=":"; find `printenv PATH` -maxdepth 1 -name openssl; IFS=$' \t\n';
I am not sure if there is any elegant method to accomplish this task without modifying IFS. However, if anyone can think of such a method, let me know.
Thanks in advance.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I have a list which contains all the jar files shipped with the product I am involved with. Now, in this list I have some jar files which appear again and again. But these jar files are present in different folders.
My input file looks like this
/path/1/to a.jar
/path/2/to a.jar
/path/1/to... (10 Replies)
Discussion started by: vino
10 Replies
2. UNIX for Dummies Questions & Answers
Hi,
By default FIND command searches for matching files in all the subdirectories within the specified path.
Is there a way to restrict FIND command's search path to only the specified directory and NOT TO scan its subdirectories.
Any help would be more than appreciated.
Thanks and Regards (2 Replies)
Discussion started by: super_duper_guy
2 Replies
3. Shell Programming and Scripting
Hi,
I have a log file having size of 48mb.
For such a large log file. I want to get the message in a particular format which includes only unique error and exception messages.
The following things to be done :
1) To remove all the date and time from the log file
2) To remove all the... (1 Reply)
Discussion started by: Pank10
1 Replies
4. Shell Programming and Scripting
Hi:
I have a requirement as below:
I have some standard Unix commands modified and kept them in a directory say /usr/clsh/bin. For example I have a script named "ls" kept here which is modified version of "ls" (say it always gives long listing i.e. ls -l).
When any user logs on and types... (2 Replies)
Discussion started by: ramesh_samane
2 Replies
5. Solaris
I noticed we have duplicate (or even triple) entries in PATH env variable. Is there any reason to have them all or is it safe to leave only one?
thanks. (2 Replies)
Discussion started by: orange47
2 Replies
6. Shell Programming and Scripting
Hi,
In a file, I have to mark duplicate records as 'D' and the latest record alone as 'C'.
In the below file, I have to identify if duplicate records are there or not based on Man_ID, Man_DT, Ship_ID and I have to mark the record with latest Ship_DT as "C" and other as "D" (I have to create... (7 Replies)
Discussion started by: machomaddy
7 Replies
7. Shell Programming and Scripting
Dear All,
I have file with 4 columns:
1 AA 0 21
2 BB 0 31
3 AA 0 21
4 CC 0 41
I would like to find the duplicate record based on column 2 and replace the 4th column of the duplicate by a new value. So, the output will be:
1 AA 0 21
2 BB 0 31
3 AA 0 -21
4 CC 0 41
Any suggestions... (3 Replies)
Discussion started by: ezhil01
3 Replies
8. Shell Programming and Scripting
Hi,
I've written a script to search for an Oracle ORA- error on a log file, print that line and the .trc file associated with it as well as the dateline of when I assumed the error occured. In most it is the first dateline previous to the error.
Unfortunately, this is not a fool proof script.... (2 Replies)
Discussion started by: newbie_01
2 Replies
9. UNIX for Dummies Questions & Answers
OS Platform : Oracle Linux 6.5
We are creating a shell script to purge old log files . It uses find command with rm in it.
The syntax is
find <Path of Log Directory> -exec rm -fr {} \;
Example:
find /tmp/test3 -exec rm -fr {} \;
For rm command , we use -r option to... (4 Replies)
Discussion started by: kraljic
4 Replies
10. Shell Programming and Scripting
Dear folks
I have a map file of around 54K lines and some of the values in the second column have the same value and I want to find them and delete all of the same values. I looked over duplicate commands but my case is not to keep one of the duplicate values. I want to remove all of the same... (4 Replies)
Discussion started by: sajmar
4 Replies
command(1) General Commands Manual command(1)
NAME
command - Treats command arguments as simple commands
SYNOPSIS
command [-p] command_name [argument...]
command [-v | -V] command_name
The command command causes the shell to treat the arguments to command as simple commands, and suppresses the default shell function
lookup.
STANDARDS
Interfaces documented on this reference page conform to industry standards as follows:
command: XCU5.0
Refer to the standards(5) reference page for more information about industry standards and associated tags.
OPTIONS
Performs the command search using a default value for PATH that is guaranteed to find all of the standard utilities. Writes a string to
standard output that indicates the path name or command to be used by the shell in the current shell execution environment to invoke com-
mand_name. Writes a string to standard output that indicates how the name given in the command_name operand will be interpreted by the
shell in the current shell execution environment.
DESCRIPTION
The command command allows you to run the following commands: User-defined commands whose names correspond to shell built-in commands.
System commands whose names correspond to shell built-in commands.
The command_name argument specifies the name of a utility. The one or more optional arguments to command_name specify strings treated as
arguments to the specified utility. It also provides information concerning how a command name will be interpreted by the shell.
NOTES
[Tru64 UNIX] If command_name is not the name of a function, the effect of command is the same as would be obtained by specifying com-
mand_name without command.
RESTRICTIONS
Since the -v and -V options to command produce output in relation to the current shell execution environment, if command is called in a
subshell or separate utility execution environment, it may not produce correct results. The following are examples of this type of opera-
tion:
(PATH=foo command -v) nohup command -v
EXIT STATUS
When the -v or -V options are specified, command returns one of the following values. Successful completion. The command_name could not
be found, or an error occurred.
If the -v or -V options are not specified, command returns one of the following values on error. The utility specified by command_name was
found but could not be invoked. An error occurred in the command command, or the utility specified by the command_name argument could not
be invoked.
If no error occurs, the exit status of command is that of the command specified by the arguments to command.
EXAMPLES
To ensure execution of the simple command pwd instead of the pwd shell built-in command, enter the following: command -p pwd
The preceding command displays the full path name of the current directory, and does not perpetuate a view of the current directory loca-
tion created by links as the shell built-in command might do.
ENVIRONMENT VARIABLES
The following environment variables affect the execution of command: Provides a default value for the internationalization variables that
are unset or null. If LANG is unset or null, the corresponding value from the default locale is used. If any of the internationalization
variables contains an invalid setting, the utility behaves as if none of the variables had been defined. If set to a non-empty string
value, overrides the values of all the other internationalization variables. Determines the locale for the interpretation of sequences of
bytes of text data as characters (for example, single-byte as opposed to multibyte characters in arguments). Determines the locale that
should be used to affect the format and contents of diagnostic messages written to standard error. Determines the location of message cat-
alogues for the processing of LC_MESSAGES. Determines the search path used during the command search unless the -p option is specified.
SEE ALSO
Commands: env(1), hash(1), type(1)
Standards: standards(5)
command(1)