Reputation: 1501
I know the command ls-files
generates a list of files you can use in a for loop to filter and rename all files, but what would be the command for just directories? I'm trying to append the string "-dcmp" to all the directory names in a project.
Upvotes: 1
Views: 107
Reputation: 3585
As part of the basic design of git
, it does not manage directories.
Somewhat simplified, directories are only relevant as the path of files.
But that means there are no empty directories. If you list all files, all directories will be shown.
You can cut off the filename part to get all directories.
Something like
git ls-files ... | sed 's|/[^/]*$||' | sort -u
lists all directories that contain files listed acording to the specific options (...
).
(This does not work with whitespace in file names - you will notice lines with space are quoted, and the quotes at start of lines mess up the -u
(--unique
).)
(If you want to work on all directories (which I noticed later) in your working copy, without any relation to the file subsets listed by various options of git ls-files
, you may not need that at all, and an answer using find
is more clear.)
Upvotes: 0
Reputation: 91857
There's no particular reason to do this with git, rather than with the usual bash tools. Specifically, I would just use find
, myself, since it's the tool I'm used to using for doing similar things to many different files:
$ find . -name .git -prune -or -type d -exec git mv '{}'{,-dcmp} \;
Upvotes: 1