Yes, the test utility operator -nt stands for newer than. If you check the man page for the test utility on your system or look for the term "conditional expression" on the man page for your shell, you'll find lots of useful tests that can be performed in your shell scripts. (Note that "conditional expression" might be all lowercase, all uppercase, or have the first letter of each word capitalized depending on which shell's man page you're reading.)
Most of the operators that are available with the [[ command (if your shell has a [[ command) are also available with the test utility invoked with:
or with:
The test and [ utilities are available with all Bourne shell derived shells.
Hi,
I have the following question :
As far as I know unix doesn't store file creation dates.
Would that imply the following?
tar -cvzf backup.tar --newer
is equal to:
tar -cvzf backup.tar --newer-mtime ? (1 Reply)
Howdy folks.
I have a problem - I'm sure the answer is very simple, but I can't work it out.
I want to create a UNIX shell script that does what I've been doing in DOS batch files for years - that is, backing up files. By which I mean copying files from a source directory to a target... (4 Replies)
Dear All,
I'm new to unix scripting. I'm trying to write an utility script which has to check if one file is newer than another one. The condition is I dont know the full name of the first file. I searched google and this forum for any such examples, but couldn't find any or may be I would have... (9 Replies)
Hi,
I have a text file, foo.txt, it looks something like below. In the file there is a line that gives the date in the form of: Mon Jun 15 11:09:31 2008. I need to find which date is the newest and then store certain details of that list data to another file. So, in this sample text file, I... (6 Replies)
This should be a simple script, but can't find one with google search.
I just need to find the file that is in many directories, then overwrite that file with a newer version i.e.
find file.jar then overwrite with /root/file.jar
All I get in searches is substitute text with new test inside... (1 Reply)
Hello,
Can you please help me one this:
I have two servers: Server A and server B.
Every day on 03.00AM in only one on these two servers (randomly)is generated one file, lets say file.txt.
I want to copy this file also to the other server.
I want to create a perl script that does... (2 Replies)
Dear All,
I'm new to unix scripting. I'm trying to write an utility script which has to check if one file is newer than another one. $3 $4 $5 $6 are files .txt. Help me please.
for i in $3 $4 $5 $6
do
if
then
echo "$1 is newer than $i"
else
echo "$i is newer than $1"
fi (9 Replies)
Discussion started by: Manueldo
9 Replies
LEARN ABOUT BSD
test
TEST(1) General Commands Manual TEST(1)NAME
test - condition evaluation utility
SYNOPSIS
test expression
DESCRIPTION
The test utility evaluates the expression and, if it evaluates to true, returns a zero (true) exit status; otherwise it returns 1 (false).
If there is no expression, test also returns 1 (false).
All operators and flags are separate arguments to the test utility.
The following primaries are used to construct expression:
-b file
True if file exists and is a block special file.
-c file
True if file exists and is a character special file.
-d file
True if file exists and is a directory.
-e file
True if file exists (regardless of type).
-f file
True if file exists and is a regular file.
-g file
True if file exists and its set group ID flag is set.
-h file
True if file exists and is a symbolic link.
-n string
True if the length of string is nonzero.
-p file
True if file is a named pipe
-r file
True if file exists and is readable.
-s file
True if file exists and has a size greater than zero.
-t [file_descriptor]
True if the file whose file descriptor number is file_descriptor (default 1) is open and is associated with a terminal.
-u file
True if file exists and its set user ID flag is set.
-w file
True if file exists and is writable. True indicates only that the write flag is on. The file is not writable on a read-only file
system even if this test indicates true.
-x file
True if file exists and is executable. True indicates only that the execute flag is on. If file is a directory, true indicates
that file can be searched.
-z string
True if the length of string is zero.
string
True if string is not the null string.
s1 = s2
True if the strings s1 and s2 are identical.
s1 != s2
True if the strings s1 and s2 are not identical.
n1 -eq n2
True if the integers n1 and n2 are algebraically equal.
n1 -ne n2
True if the integers n1 and n2 are not algebraically equal.
n1 -gt n2
True if the integer n1 is algebraically greater than the integer n2 .
n1 -ge n2
True if the integer n1 is algebraically greater than or equal to the integer n2 .
n1 -lt n2
True if the integer n1 is algebraically less than the integer n2 .
n1 -le n2
True if the integer n1 is algebraically less than or equal to the integer n2 .
These primaries can be combined with the following operators:
! expression
True if expression is false.
expression1 -a expression2
True if both expression1 and expression2 are true.
expression1 -o expression2
True if either expression1 or expression2 are true.
(expression)
True if expression is true.
The
-a operator has higher precedence than the -o operator.
GRAMMAR AMBIGUITY
The test grammar is inherently ambiguous. In order to assure a degree of consistency, the cases described in the IEEE Std 1003.2
("POSIX"), section D11.2/4.62.4, standard are evaluated consistently according to the rules specified in the standards document. All other
cases are subject to the ambiguity in the command semantics.
RETURN VALUES
The test utility exits with one of the following values:
0 expression evaluated to true.
1 expression evaluated to false or expression was missing.
>1 An error occurred.
BUGS
Named pipes are not implemented in 2.11BSD.
STANDARDS
The test function is expected to be IEEE Std 1003.2 ("POSIX") compatible.
7th Edition March 13, 1995 TEST(1)