i have hundreds of directories that have to be renamed. the directory structure is fairly uniform which makes the scripting a little simpler.
suppose i have many directories like this */*/*/*abc* (in other words i have similar directory names 3 dirs deep that all contain the pattern abc in... (8 Replies)
Hi,
This is what I would like to do.
1. Find all directories named "ByHost" in a specified directory
2. Rename all .plist files inside "ByHost" directories
This is the way I have been able to do it so far.
#!/bin/sh
#
# Rename ByHost files
#
# Thomas Berglund, 13.07.08
# Get the... (2 Replies)
Hello all,
Here's the deal...I have one directory with many subdirs and files.
What I want to find out is who is keeping old files and directories...say files and dirs that they didn't use since a number of n days, only one level under the initial dir. Output to a file.
A script for... (5 Replies)
Hello
I have a directory structure with year in format 4 digits, e.g 2009, below which is month format 1 or 2 digits, e.g 1 or 12, blow which is day format 1 or 2 digits, e.g 1 or 31.
I want to change the names of lots of directories to the be
Year - 4 digits , e.g 2009 - No change here... (4 Replies)
Hello guys,
I was looking for a shell script that removes all the special characters from the files and the subdirectories recursively. I could not locate it any more. Dose any body have a similar script that dose that?
Thanks for the help.
AV (0 Replies)
I have this directory tree under /apps/myapp/data:
imageshack.us/photo/my-images/703/foldersc.png
How to recursively rename ONLY directories with 5 digits (00000, 00100, 00200,..., 00007, 00107,...)?
I want to add to their name two more zeros:
Before: 00107
After: 0000107
Thanks in... (2 Replies)
I can rename a file with sequential numbers from 1 to N with this script:
num=1
for file in *.dat;do
mv "$file" "$(printf "%u" $num).txt"
let num=num+1
done
The script begins with renaming a some.dat file to 1.dat.txt and goes on sequentially renaming other DAT files to... (1 Reply)
Hello
Im trying to make a script in bash shell programming to find subdirectories with the same name into the same directory and rename one of them!!
Could you please help me?
Thanks in advance (1 Reply)
Hi all,
I have more than 12000 files in 46 different directories and each directory has 2 sub-directories named “dat” or “gridded”. Dat sub-directories have files with extension “jpg.dat” and gridded sub-directories have files with extension “.jpg”.
I need to... (1 Reply)
Hi,
Friends, i have a requirement where i need to rename my files residing in multiple sub directories and move them to one different directory along with some kind of directory indicator.
For eg:
test--is my parent directory and it has many files such as
a1.txt
a2.txt
a3.txt
... (5 Replies)
Discussion started by: gnnsprapa
5 Replies
LEARN ABOUT CENTOS
dirname
BASENAME(3) Linux Programmer's Manual BASENAME(3)NAME
basename, dirname - parse pathname components
SYNOPSIS
#include <libgen.h>
char *dirname(char *path);
char *basename(char *path);
DESCRIPTION
Warning: there are two different functions basename() - see below.
The functions dirname() and basename() break a null-terminated pathname string into directory and filename components. In the usual case,
dirname() returns the string up to, but not including, the final '/', and basename() returns the component following the final '/'. Trail-
ing '/' characters are not counted as part of the pathname.
If path does not contain a slash, dirname() returns the string "." while basename() returns a copy of path. If path is the string "/",
then both dirname() and basename() return the string "/". If path is a NULL pointer or points to an empty string, then both dirname() and
basename() return the string ".".
Concatenating the string returned by dirname(), a "/", and the string returned by basename() yields a complete pathname.
Both dirname() and basename() may modify the contents of path, so it may be desirable to pass a copy when calling one of these functions.
These functions may return pointers to statically allocated memory which may be overwritten by subsequent calls. Alternatively, they may
return a pointer to some part of path, so that the string referred to by path should not be modified or freed until the pointer returned by
the function is no longer required.
The following list of examples (taken from SUSv2) shows the strings returned by dirname() and basename() for different paths:
path dirname basename
/usr/lib /usr lib
/usr/ / usr
usr . usr
/ / /
. . .
.. . ..
RETURN VALUE
Both dirname() and basename() return pointers to null-terminated strings. (Do not pass these pointers to free(3).)
CONFORMING TO
POSIX.1-2001.
NOTES
There are two different versions of basename() - the POSIX version described above, and the GNU version, which one gets after
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <string.h>
The GNU version never modifies its argument, and returns the empty string when path has a trailing slash, and in particular also when it is
"/". There is no GNU version of dirname().
With glibc, one gets the POSIX version of basename() when <libgen.h> is included, and the GNU version otherwise.
BUGS
In the glibc implementation of the POSIX versions of these functions they modify their argument, and segfault when called with a static
string like "/usr/". Before glibc 2.2.1, the glibc version of dirname() did not correctly handle pathnames with trailing '/' characters,
and generated a segfault if given a NULL argument.
EXAMPLE
char *dirc, *basec, *bname, *dname;
char *path = "/etc/passwd";
dirc = strdup(path);
basec = strdup(path);
dname = dirname(dirc);
bname = basename(basec);
printf("dirname=%s, basename=%s
", dname, bname);
SEE ALSO basename(1), dirname(1)COLOPHON
This page is part of release 3.53 of the Linux man-pages project. A description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
GNU 2009-03-30 BASENAME(3)