rename a number of files with git - shell

I have a directory called clients. In this directory there are more directories and some files. All the file names start with double underscore as given below. All the files in clients directory or within the directories within clients have file names starting with double underscore.
client1/
client2/
__a.txt
__b.txt
I need to rename all the files to a single underscore. All the files are in github so we use git.
What would be a good tool I should read up on. sed / awk ?

If your (unix?) system has the rename command:
cd client2
rename 's/^__/_/' *

Related

Rename lowercase folder to uppercase

I want to rename folders from lowercase to uppercase. For example
abc ABC
twoshirts TwoShirts
I've tried
mv -T -f source destination
I've tried a few different combination but I get an error
Error moving files as they are the same file or sub directory of itself.
Is it possible to do it with mv?
The problem is that your file system is case-insensitive; UNIX and its derivatives like Linux have traditionally had case-sensitive filesystems, but Windows doesn't. So you have to first rename the file to some other name, and then from there to the target name.
e.g. mv abc notabc; mv notabc ABC

Rename batch files in bulk using spaces?

You can rename files in batch in bulk using, for example:
rename *.docx *.pdf
However, when my docx files have spaces in them, this renames them to new files which only have the first word in their file name. How do I preserve the entire file name?
EDIT: Apparently this is only the case when the file name as a dot in it (but the file has no extension still), for example:
2017. abcdef

rename multiple files bash in a subdir

I am trying to use rename but I have several subdirs. The expression I am trying to use is this:
rename 's/ZAUQ-F24MS-SC12-F01-5C\/R44.wav/wav\/2012.wav/' *.wav
I want to rename the file ZAUQ-F24MS-SC12-F01-5C/R44.wav to wav/2012.wav and all files are *.wav files.
I am able to do this from inside the directory but I have multiple directories and a mapped to and from list. Can rename do this or should I be using something else?
Apparently you are moving a file from one directory (ZAUQ-F24MS-SC12-F01-5C) to another (wav). Why not mv then:
mv ZAUQ-F24MS-SC12-F01-5C/R44.wav wav/2012.wav

Batch file to copy files from multiple folders to a single folder, overriding if date is newer

I would like to be able to copy all files from various folders and combine them into a single folder using a Windows batch file. That is fairly easy to do for me. But if the file already exists on the destination, I would like it to only override the file if it's newer.
copy c:\pics\ to d:\
Thanks.
You can use xcopy for more options if the source dirs are 2-3-5 (write separate xcopy lines for each). If the dirs are too many, you can use archiver like WinRar (or its command line rar.exe) with #list option where are stored the source dirs. In the batch file call RAR 2 times - first to pack all source files to one archive, then to unrar them in single folder (with E option, not X). Finally, you delete the .rar file. See the extra options to skip older files, omit prompts, etc.

zip all files and folders recursively in bash

I am working on a project, where compilation of the project involves, zipping up various files and folders and subfolders (html/css/js) selectively. Working on the windows platform, and I could continue to just use the CTRL+A and then SHIFT-click to unselect, but it does get a little tedious. I am working with cygwin, so I was wondering if it is possible to issue a command to zip selected files/folders recursively whilst excluding others, in one command? I already have zip command installed, but I seem to be zipping up the current zip file too and the .svn file too.
I would like this to be incorporated into a shell script if possible, so the simpler the better.
After reading the man pages, I think the solution that I was looking for is as follws:
needs to recurse directories (-r),
needs to exclude certail files/directories (-x)
It works in the current directory, but the . can be replaced with the path of any directory
zip -x directories_to_exclude -r codebase_latest.zip .
I have incorporated this into a short shell script that deletes files, tidy up some code, and then zips up all of the files as needed.
You should read man page of zip command:
-R
--recurse-patterns
Travel the directory structure recursively starting at the current directory; for example:
zip -R foo "*.c"
In this case, all the files matching *.c in the tree starting at the current directory are stored into a zip archive named foo.zip. Note that *.c will match
file.c, a/file.c and a/b/.c. More than one pattern can be listed as separate arguments. Note for PKZIP users: the equivalent command is
pkzip -rP foo *.c
Patterns are relative file paths as they appear in the archive, or will after zipping, and can have optional wildcards in them. For example, given the cur‐
rent directory is foo and under it are directories foo1 and foo2 and in foo1 is the file bar.c,
zip -R foo/*
will zip up foo, foo/foo1, foo/foo1/bar.c, and foo/foo2.
zip -R */bar.c
will zip up foo/foo1/bar.c. See the note for -r on escaping wildcards.
You can also have a look HERE

Resources