The command:
will give you a list of the directories you're interested in in increasing alphabetic order. Since all of the numbers at the end of these directory names contain 3 digits, this will also be in increasing numeric order. Adding the -r option to ls will give you the list in reverse order. Piping the output of ls through the command: head -n 1 will give you just the first line, which will be the directory that you want. You can use save that directory name in a variable using command substitution and variable assignment:
To copy a file named filename.txt from that directory to another directory (in this example, named /target/directory), you can then use:
You can change the name of the file in the target directory using the first form above; the second form will copy the source file to the target directory using the same name as the final component of the source file pathname as the filename of the copy in the target directory.
Hi
I a really need help.
I got simply shell script which store result into the specific file
in this case xxx_001.txt
And after another run script I would like to create the same file but
value 001 is incremented by 1 -> xxx_002.txt a so on.
If I gonna use awk utility then result... (4 Replies)
Hi all,
I have a folder '/samplefolder' in which i have some files like data0.txt, data1.txt and data2.txt.
I have to search the folder for existence of the file data0.txt first and if found have to copy it to some other file; next i have to search the folder for existence of file... (5 Replies)
Hello all, this is my first post while i am trying to understand unix.
I would basically like to know if i can do this:
Lets say i have a folderA and folderB
And i save something in folderA
Can i make a script that checks folderA latest file, then compares it with the date of latest file in... (16 Replies)
Hi everyone.
I'm in need of a solution where i need to rename a folder to a name that's inside an XML file in that folder.
OS is Ubuntu 9.10 with Gnome.
I've tried using grep, sed and xpath, but can't seem to find a solution.
This is the simplified folder structure:
FOLDER-NAME
-... (4 Replies)
I have a file myfile with only one value 1000.I am using it in a shell script.Each time i run the script,the file shud get incremented by 1. I have used the below code for incrementing the value-
curr=`cat myfile`
echo $curr
curr=`expr $curr + 1`
But i am not sure how to save this replaced... (2 Replies)
I have a file named file.txt that looks as follows
//class1.txt
45
234
67
89
90
//class2.txt
456
34
78
89
120
class1 and class2.txt are the names of files in a folder named folder1.
The content of class1.txt file in folder1
67 9
89 5
234 9The content of class2.txt file in... (1 Reply)
Hi
I'm trying to look through a series of directories in A folder, lets just call it A:
for example:
A/1
A/2
A/3
Etc and I wish to move the files in the folder if they are bigger than a certain size into a structure like below:
A/TooBig/1
A/TooSmall/1
A/TooBig/2
A/TooSmall/2... (1 Reply)
Hi Guru's,
I am new to unix scripting. I have a huge file with user details in it(file2) and I have another file with a list of users(file1). Script has to search a user from file1 and get all the associated lines from file2.
Example:
fiel1:
cn=abc
cn=DEF
cn=xyx
File 2:
dn:... (10 Replies)
Hi,
I have a script doing backup to synology server, the script create new folder each day with the date as being folder name i.e. 2018-07-30. Just before creating the new folder I want the script to find the oldest folder from the list and delete it including its content.
for example... (3 Replies)
Discussion started by: humble_learner
3 Replies
LEARN ABOUT HPUX
rename
rename(2) System Calls Manual rename(2)NAME
rename - change the name of a file
SYNOPSIS DESCRIPTION
The system call causes the source file to be renamed to target. If target exists, it is first removed. Both source and target must be of
the same type (that is, either directories or nondirectories), and must reside on the same file system.
If target can be created or if it existed before the call, guarantees that an instance of target will exist, even if the system crashes in
the midst of the operation.
If the final component of source is a symbolic link, the symbolic link is renamed, not the file or directory to which the symbolic link
points.
RETURN VALUE
returns the following values:
Successful completion.
Failure.
Neither file is affected. is set to indicate the error.
ERRORS
If fails, is set to one of the following values.
[EACCES] A component of either path prefix denies search permission.
[EACCES] The requested link requires writing to a directory without write permission.
[EBUSY] target or source is an existing directory that is the mount point for a mounted file system.
[EDQUOT] User's disk quota block or inode limit has been reached for this file system.
[EEXIST] target is a directory and is not empty.
[EFAULT] source or target points outside the allocated address space of the process. Reliable detection of this error is
implementation dependent.
[EINVAL] source is a parent directory of target, or an attempt is made to rename the or directory.
[EISDIR] target is a directory, but source is not.
[ELOOP] Too many symbolic links were encountered in translating either path name.
[ENAMETOOLONG] A component of either path name exceeds bytes while is in effect, or the entire length of either path name exceeds
bytes.
[ENOENT] A component of the source path does not exist, or a path prefix of target does not exist.
[ENOSPC] The destination directory cannot be extended because of a lack of space on the file system containing the directory.
[ENOTDIR] A component of either path prefix is not a directory.
[ENOTDIR] source is a directory, but target is not.
[EPERM] The directory containing source has the sticky bit set, and neither the containing directory nor the source are owned
by the effective user ID.
[EPERM] The target file exists, the directory containing target has the sticky bit set, and neither the containing directory
nor the target are owned by the effective user ID.
[EROFS] The requested link requires writing in a directory on a read-only file system.
[EXDEV] The paths named by source and target are on different logical devices (file systems).
AUTHOR
was developed by the University of California, Berkeley.
SEE ALSO open(2).
STANDARDS CONFORMANCE rename(2)