What does the `-- mean in a folder structure? - linux

I encountered a folder structure at raymii.org/s/tutorials and I'm not really sure what the symbols `-- mean. Couln't also find any syntax or documentation on how to write such structures.
$ tree -L 2 ExampleProject/
ExampleProject/
|-- build/
|-- CMakeLists.txt
|-- lib/
| `-- googletest
|-- src/
| |-- CMakeLists.txt
| |-- Formula.cpp
| |-- Formula.h
| `-- main.cpp
`-- tst/
|-- CMakeLists.txt
|-- Formula-test.cpp
`-- main.cpp

The symbols represent a polygonal chain leading from the parent directory to the file. '-' represents a horizontal segment of the chain, '`' represents a diagonal segment and '|' represents a vertical segment.
The chain conveys the parent-child relationship of a directory entry and the directory that contains it.
This particular tree shows the root directory ExampleProject which contains a sub directory src which contains a file CMakeLists.txt. And a bunch of other directories and files.

Related

I need to make the following directory using two command lines and have to copy the directory using absolute path

Write two command lines needed to create the following directory tree.
~
|-- bigboy/
| `-- opss/
| |-- user
| `-- teacher
|
`-- arch/
|-- b/
| `-- pr.txt
|
`-- 2022F
Using absolute paths, write one command line to copy directory opss with its files to
directory 2022F. How do you prove this has been done? Use a second command line and its output to show this has been done as expected.

Rsync: Exclude directory contents, but include directory

I know that a directory can be excluded with --exclude like this:
rsync -avz --exclude=dir/to/skip /my/source/path /my/backup/path
This will omit the directory dir/to/skip
However I want to copy the directory itself but not the contents | Is there a one-liner with rsync to accomplish this?
Essentially, include dir/to/skip but exclude dir/to/skip/*
NOTE: I did search for this question. I found a lot of similar posts but not exactly this. Apologies if there is a dupe already.
The --exclude option takes a PATTERN, which means you just should just be able to do this:
rsync -avz --exclude='dir/to/skip/*' /my/source/path /my/backup/path
Note that the PATTERN is quoted to prevent the shell from doing glob expansion on it.
Since dir/to/skip doesn't match the pattern dir/to/skip/*, it will be included.
Here's an example to show that it works:
> mkdir -p a/{1,2,3}
> find a -type d -exec touch {}/file \;
> tree --charset ascii a
a
|-- 1
| `-- file
|-- 2
| `-- file
|-- 3
| `-- file
`-- file
3 directories, 4 files
> rsync -r --exclude='/2/*' a/ b/
> tree --charset ascii b
b
|-- 1
| `-- file
|-- 2
|-- 3
| `-- file
`-- file
3 directories, 3 files
It is important to note that the leading / in the above PATTERN represents the root of the source directory, not the filesystem root. This is explained in the rsync man page. If you omit the leading slash, rsync will attempt to match the PATTERN from the end of each path. This could lead to excluding files unexpectedly. For example, suppose I have a directory a/3/2/ which contains a bunch of files that I do want to transfer. If I omit the leading / and do:
rsync -r --exclude='2/*' a/ b/
then the PATTERN will match both a/2/* and a/3/2/*, which is not what I wanted.
Try:
rsync -avz --include=src/dir/to/skip --exclude=src/dir/to/skip/* src_dir dest_dir
--include=src/dir/to/skip includes the directory. --exclude=src/dir/to/skip/* excludes everything under the directory.

.htaccess RewriteEngine rules for Slim API + AngularJS client

I am, mostly for learning purposes, building a very simple RESTful API for serving a random image or a specific image given an ID. This API will be accessed via a AngularJS client (probably) and will be deployed, together with the API, to my web server. The API and the web client will reside in the same project, that is the same root folder which will actually be a subdirectory on my server accessible via http://foo.com/bar and in the same git repository. Maybe I'll create an Android client later on accessing the same API.
However, I have trouble getting the .htaccess routing/rewriting right. Below follows my proposed directory structure.
root/
|-- bar/
| |-- api/
| | |-- v1/
| | | |-- lib/
| | | | `-- ImageFactory.php
| | | |-- vendor/
| | | | `-- slim/
| | | |-- .htaccess (#1)
| | | |-- composer.json
| | | `-- index.php
| |-- public_html/
| | |-- css/
| | |-- img/
| | | `-- bar/
| | |-- js/
| | | |-- controllers/
| | | |-- directives/
| | | |-- filters/
| | | |-- lib/
| | | |-- services/
| | | |-- vendor/
| | | `-- app.js
| | |-- views/
| | |-- api.php
| | `-- index.html
| `-- .htaccess (#2)
I am thinking that each major rework of the API needs a new version which depends on its own version of Slim, should I change the version over the years.
But what about the .htaccess files? I think that calls to http://foo.com/bar should redirect to public_html/index.html, in other words the JS client app. However, calls to http://foo.com/bar/api/v1 should redirect to public_html/api.php and give the version v1 as a parameter so that api.php can load the correct API app.
How should I write my RewriteEngine rules for .htaccess #1 and #2? Is there something off with my proposed structure? Have I missed something? Please help a developer in need!
To achieve what you want, you only need to add some rules in your /root/bar/.htaccess file.
If by redirect you mean internal rewrite (forward to page without changing url in browser) then you can put this code into your htaccess
RewriteEngine On
RewriteBase /bar/
RewriteRule ^$ public_html/index.html [L]
RewriteRule ^api/v([1-9][0-9]*)$ public_html/api.php?version=$1 [L]

How does Linux TAR Exclusion works?

Let's say I have a directory structure like this:
# tree original_directory/
|-- sub-1
|-- sub-2
|-- ignore_this_dir
|-- sub-3
Then the tar command to exclude the directory called ignore_this_dir is actually:
# tar -cf new_archived.tar original_directory/ --exclude=ignore_this_dir
OR
# tar -cf new_archived.tar original_directory/ --exclude=original_directory/ignore_this_dir
The man page states:
--exclude=PATTERN
exclude files, given as a PATTERN
Meaning
tar -cf new_archived.tar origin_directory/ --exclude=ignore_this_dir
will be ok in your situation as the pattern ignore_this_dir will match original_directory/ignore_this_dir.

How to recursively copy files under a folder and its subfolders as symbolic links

In linux or freebsd, Is there a way to copy all files under a folder and its subfolders as symbolic link ? I need to copy thousands of files into different locations as symbolic links and only have 2-3 configuration files as the actual file. The reason I'm doing this is, I have dozen of websites with with exactly the same engine code, but different configuration and look. I want to copy the engine as symbolic link so every change I make to original files will be applied to other websites as well.
I can't make symbolic link to the engine folder itself, because the configuration file is under that folder, and I can't copy files one by one ! cause obviously it's not practical.
Any suggestion ?
The command you are looking for is cp -rs /path/to/source dest.
Note that you need to provide full path to the source directory so that it can make absolute symlinks.
i don't know if this is what you want: (see example below)
dir one is your central "engine"
dir two is one of your website.
kent#ArchT60:/tmp$ tree one two
one
|-- 1.txt
|-- 2.txt
|-- 3.txt
|-- 4.txt
|-- 5.txt
|-- dirA
| |-- a
| |-- b
| `-- c
|-- dirB
`-- dirC
two
|-- myConf_a.conf
|-- myConf_b.conf
|-- myConf_c.conf
|-- myConf_d.conf
`-- myConf_e.conf
kent#ArchT60:/tmp$ ln -s /tmp/one/* /tmp/two/.
kent$ tree -l /tmp/two
/tmp/two
|-- 1.txt -> /tmp/one/1.txt
|-- 2.txt -> /tmp/one/2.txt
|-- 3.txt -> /tmp/one/3.txt
|-- 4.txt -> /tmp/one/4.txt
|-- 5.txt -> /tmp/one/5.txt
|-- dirA -> /tmp/one/dirA
| |-- a
| |-- b
| `-- c
|-- dirB -> /tmp/one/dirB
|-- dirC -> /tmp/one/dirC
|-- myConf_a.conf
|-- myConf_b.conf
|-- myConf_c.conf
|-- myConf_d.conf
`-- myConf_e.conf

Resources