I have a directory structure as below:
base
├── config.yml
├── build
│ └── output.yml
│ └── <multiple level sub-directories each having many files including *.c and *.h files>
├── <source directories - having many sub-directories with various files including *.c and *.h files>
│ ├── <xyz>
| │ ├── <x1>
| │ .
│ | └── <xy>
│ .
│ .
│ └── <abc>
├── <more directories, each having multiple files including *.c and *.h files>
I need to sync this directory to remote, but I only need *.c and *.h files. Also complete 'build' directory needs to be excluded. I am running below command:
rsync -avm --include '*/' --include='*.c' --include='*.h' --exclude='*' base "$target_loc"
This is syncing all *.c and *.h files which is desired but it also syncs *.c and *.h files from build and its sub directories
I tried
rsync -avm --include '*/' --include='*.c' --include='*.h' --exclude='build' --exclude='*' base "$target_loc". It still syncs files from build and it's sub directories.
How can I fix this?
You need to put --exclude='build' before --include '*/'. Both of these rules could apply to the "build" directory, and whichever is given first takes precedence, so to get the --exclude rule to override the --include rule, you need to list it first.
From the rsync man page, in the FILTER RULES section (with my emphasis):
As the list of files/directories to transfer is built, rsync checks
each name to be transferred against the list of include/exclude
patterns in turn, and the first matching pattern is acted on: if it is
an exclude pattern, then that file is skipped; if it is an include
pattern then that filename is not skipped; if no matching pattern is
found, then the filename is not skipped.
Related
I have files as follows:
assets/
├─ icon_1.png
├─ icon_1#2x.png
├─ icon_1#3x.png
├─ icon_2.png
├─ icon_2#2x.png
├─ icon_2#3x.png
and I want to change it to this format:
assets/
├─ icon_1/
│ ├─ 3.0x/
│ │ ├─ icon_1.png
│ ├─ 2.0x/
│ │ ├─ icon_1.png
│ ├─ icon_1.png
├─ icon_2/
│ ├─ 3.0x/
│ │ ├─ icon_2.png
│ ├─ 2.0x/
│ │ ├─ icon_2.png
I am trying to use zmv commands such as
zmv '(*).png' $1/'$1.png'
or
zmv '(*).png' '$1/$1.png'
to get a feel of how it works. However, it tells me that I do not have the right directories. Is there a way to create directories dynamically from the file names?
I wasn't really able to find a way to parametrize the suffixes and create the directories dynamically, however I did find a solution for my specific case of the problem.
I ran the following commands on zsh:
for file in *#3x.png
do
dirname="${file%#3x.png}" #this truncates the #3x.png from 'icon_1#3x.png' and so on
mkdir "$dirname"
mkdir "$dirname/2.0x"
mkdir "$dirname/3.0x"
done
This creates the folder structures that I want. Now I only have to move the files from ./ to the desired directories as follows:
zmv '(*)#3x.png' '$1/3.0x/$1.png'
zmv '(*)#2x.png' '$1/2.0x/$1.png'
zmv '(*).png' '$1/$1.png'
I move the ones with #3x, #2x suffixes first so they don't get selected by the (*).png selector.
This can be done with zmv, but you may need a somewhat complicated pattern. This will move the files if the destination directories exist:
zmv -n '(icon_<->)(*).png' '${1:r}/${${2##}%x}${2:+.0x}/$1.png'
The -n (no-execute) option is for testing - remove it to actually move the files. The extended glob pattern <-> matches any number; it lets us split the source pattern into two pieces. The destination pattern uses several zsh parameter expansions to build the path, with repeated forward slashes being treated like a single slash for the icon_1 and icon_2 directories.
Out-of-the box, zmv will not create directories, but it will accept a custom command that can call mkdir:
mkdir_mv () {
mkdir -p -- $3:h
mv -- $2 $3
}
zmv -n -p mkdir_mv '(icon_<->)(*).png' '${1:r}/${${2##}%x}${2:+.0x}/$1.png'
The mkdir_mv code is from this answer.
I am trying to implement various project from a programming book. My intention was to have each project exercise in its own folder and then have a makefile that compiles all of them with something like a make all. The folder structure is like this:
.
├── Makefile
├── bin
│ ├── prog1
│ ├── prog2
│ └── prog3
└── src
├── prog1
│ ├── Makefile
│ └── main.c
├── prog2
│ ├── Makefile
│ └── main.c
└── prog3
├── Makefile
└── main.c
I would like to learn how to set up such a structure. In particular the part where the top makefile visit all folders in src calls make there, and then copies and renames the executable into the bin folders.
Your layout schematic shows a makefile for each exercise, plus the top-level makefile that you seem actually to be asking about. It would be best for the top-level makefile to avoid duplicating the behavior of the per-exercise makefiles, as such duplication would create an additional maintenance burden for you. Additionally, it is likely that you will eventually progress to exercises involving multiple source files, and perhaps to some that have multiple artifacts to be built. This is all the more reason for each per-exercise makefile to contain everything necessary to build the exercise with which it is associated (into the exercise-specific directory), and for the top-level makefile to depend on those.
Following that scheme would leave a well-defined role for the top-level makefile: to perform the per-exercise builds (by recursively running make), and to copy the resulting binaries to bin/. This is not the only way to set up a system of cooperating makefiles, but it is fairly easy, and that will allow you to focus on the exercises instead of on the build system.
Let us suppose, then, that each individual exercise can be built by changing to its directory and running make, with the result being an executable in the same directory, with the same name as the directory. That is, from the top-level directory, executing cd src/prog2; make would produce the wanted executable as src/prog2/prog2. In that case, the top-level makefile needs little more than the names of all the exercises, and a couple of rules:
EXERCISES = prog1 prog2 prog3
BINARIES = $(EXERCISES:%=bin/%)
all: $(BINARIES)
$(BINARIES):
make -C src/$$(basename $#)
cp src/$$(basename $#)/$$(basename $#) $#
Note: that uses a feature specific to GNU's implementation of make to compute the names of the wanted binaries from the exercise names. I take that to be acceptable, since you tagged [gnu-make], but in any case, it is a convenience feature, not a necessity.
There are different ways to tackle this, but something like this should work for your example:
PROGS := bin/prog1 bin/prog2 bin/prog3
all: $(PROGS)
$(PROGS):
$(MAKE) -C src/$(#F)
mkdir -p $(#D)
cp src/$(#F)/main $#
.PHONY: clean
clean:
rm -f $(PROGS)
for t in $(PROGS); do make -C src/`basename $$t` clean; done
We define a list of targets (PROGS) we are to build. We say these targets are prerequisites of all and then we go ahead and define how they should be built, that is: we recursively descent into src/ plus filename part of the target to run make there. We create directory of the target to be sure it's there and copy main from the directory we've descended to the path of the target.
For a good measure, there is a clean target as well that removes all the PROGS and runs make clean recursively in src/.
For a directory structure of:
└── bar
├── first
│ └── tmp
└── second
└── tmp
I want to delete all tmp directories.
However,
rm -rf 'bar/*/tmp/'
does not delete the directory
ls bar/*/
still retrurns both tmp directories:
bar/first/:
tmp
bar/second/:
tmp
your problem here is the single quotes
rm -rf 'bar/*/tmp/'
if you remove them you'll be fine.
rm -rf bar/*/tmp
The reason for this is that single quotes in (most, if not all) shell languages indicates that the contained string of characters is to be treated entirely as a string, which ignores the globbing you are trying to do.
ENV:
macOS Sierra 10.12.6
Raw input(example):
.
├── f1.md
├── f2.md
├── f3.md
├── f4.txt
├── f5.csv
└── f6.doc
0 directories, 6 files
In a test folder, there are 6 files.
Expected output:
.
├── all.tar
├── f1.md
├── f2.md
├── f3.md
├── f4.txt
├── f5.csv
└── f6.doc
0 directories, 7 files
Trying and Problem
tar -cvf all.tar f1.md f2.md f3.md f4.txt f5.csv f6.doc
Though I get the result from the above method but I have to inputing all file names and the compressed file name, which is inconvenient. For example , I can select all files and right click, then choose compressed option without inputing all.tar (I don't mind the .tar filenames.)
Hope
command-line method without inputing specific file names.
In case you want all files, including those in the subdirectories (or if you have no subdirectories), you would run:
tar -cvf all.tar *
Then, bash would expand * into the list of all files in the current directory, including subdirectories.
In case you want only those files in the current directory, but NOT in the subdirectories, then you would have to use find, in a more complicated command. Let me know if this is the case for you, and I can take the time to find that combination of commands for you.
Is there someone who can explain in detail the standard used by Symfony* to name folders and files in the directory structure?
MyBundle
├─ Controller/ <-- 1) why singular?
├─ Model/ <-- 2) why singular?
├─ Resources/ <-- 3) why plural?
│ ├─ config/ <-- 4) why the "c" is lowercase?
│ ├─ translations/
│ ├─ views/ <-- 5) why the "v" is lowercase and views is plural?
│ │ └─ Default/ <-- 6) Why uppercase?
│ │ └─ my_view.html.twig <-- 7) Why lowercase and snake case?
│ └─ public/
├─ Service/ <-- 8) why singular?
└─ Tests/
This leads to another question: if I want to create a folder which contains ArchiveSection classes inside the Model folder, how should I name it?
Model/ArchiveSections/
Model/ArchiveSection/
Model/archive_sections/
* I am using Symfony 2.3.
See the docs talking about bundle directory structure.
I would say just keep in mind that the Resources directory structure must follow the standards to get some automatic registration of view paths and translations files in the kernel. The same applies to the Command directory.
For the rest it's how you want it to be, just know that the directory structure should repeat the symfony components structure to keep logic and readability (a Twig directory for creating twig extensions or functions, a Serializer directory to hold custom normalizers...).
This is relevant to have a good directory structure as it defines your classes namespace structure.
There is no strictly rules for structure and architecture directory in symfony framework. But exist best practices and standard convention.
In your case, there is nothing issue and you can do what do you want.
It seems that underscore in name directory is not very standard convention but not mandatory.
For question deal with singular or plurial it seems that is unanswered convention from symfony developers. Example : Me I name my service directory with plurial like this 'services' and all my code run perfectly with this name.