Using ls -lR ignore given REGEX - bash

I’m using ls -lR | ... to get my desired output, but now I need something that would force ls to ignore given regex expression. Is it possible to achieve this? I found ls -I and ls --ignore but for some reason I get: illegal option error [macOS Catalina 10.15.3]. I need this to be working on most frequently used shells(bash, ksh, zsh etc..)
Output
ls -lR | ...
./NOEMPTY:
total 72
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 10.c
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 15.c
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 20.c
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 25.c
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 30.c
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 35.c
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 40.c
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 5.c
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b.c
./NOT_THIS:
total 32
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 30 2.c
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 30.c
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 35 2.c
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 35.c
./THIS_YES:
total 32
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 30 2.c
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 30.c
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 35 2.c
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 35.c
Desired Output:
ls -lR IGNORE NOT_THIS | ... something more
./NOEMPTY:
total 72
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 10.c
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 15.c
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 20.c
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 25.c
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 30.c
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 35.c
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 40.c
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 5.c
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b.c
./THIS_YES:
total 32
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 30 2.c
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 30.c
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 35 2.c
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 35.c
I’ve tried to use sed utility but failed to achieve this, since I wasn’t able to select empty line between folders such as this:
ls -lR | sed -n '/.\/NOT_THIS/,/[[:space:]]/p'

Try this : ls -lR -I '*NOT_THIS*'
Demo :
:=>ls -1
1.txt
2.txt
a.csv
b.csv
:=>ls -1 -I '*txt'
a.csv
b.csv
:=>
Using SED
sed '/\.\/NOT_THIS/, /^$/'d
explanation : sed '/start/,/end/d' <-- this will delete all data between first /<patern>/ and second pattern.
^$ <-- Blank line. ^ -- Start of record. $ -- end of record
Demo:
:=>sed '/\.\/NOT_THIS/, /^$/'d file.txt
ls -lR | ...
./NOEMPTY:
total 72
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 10.c
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 15.c
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 20.c
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 25.c
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 30.c
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 35.c
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 40.c
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 5.c
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b.c
./THIS_YES:
total 32
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 30 2.c
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 30.c
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 35 2.c
-rw-r--r--# 1 makaveli_10 staff 34 Mar 15 09:26 1b copy 35.c
:=>

Related

Selected png images to gif using ffmpeg or imagemagick

I want to convert png to gif and i want to mention which are the frames i want to combine
eg: frame1.png and frame2.png.
I've tried using ffmpeg -i frames/%03d.png -vf fps=20 logo.gif but it is considering all the images in that directory, but i want only two images in that directory to be included in the gif i want to create. Thank you in advance.
Just use the ones you want:
magick -delay 80 nice1.png nice37.png animated.gif
By way of explanation and further example, I can make a red and a blue frame and morph between the two in 14 steps like this - making a total of 16 frames:
magick -size 20x100 xc:red xc:blue -morph 14 frame-%02d.png
If I append those frames side-by-side, you can see them all:
magick frame* +append side-by-side.png
And I can list them in the shell:
-rw-r--r-- 1 mark staff 278 28 Apr 13:45 frame-00.png
-rw-r--r-- 1 mark staff 278 28 Apr 13:45 frame-01.png
-rw-r--r-- 1 mark staff 278 28 Apr 13:45 frame-02.png
-rw-r--r-- 1 mark staff 278 28 Apr 13:45 frame-03.png
-rw-r--r-- 1 mark staff 278 28 Apr 13:45 frame-04.png
-rw-r--r-- 1 mark staff 278 28 Apr 13:45 frame-05.png
-rw-r--r-- 1 mark staff 278 28 Apr 13:45 frame-06.png
-rw-r--r-- 1 mark staff 278 28 Apr 13:45 frame-07.png
-rw-r--r-- 1 mark staff 278 28 Apr 13:45 frame-08.png
-rw-r--r-- 1 mark staff 278 28 Apr 13:45 frame-09.png
-rw-r--r-- 1 mark staff 278 28 Apr 13:45 frame-10.png
-rw-r--r-- 1 mark staff 278 28 Apr 13:45 frame-11.png
-rw-r--r-- 1 mark staff 278 28 Apr 13:45 frame-12.png
-rw-r--r-- 1 mark staff 278 28 Apr 13:45 frame-13.png
-rw-r--r-- 1 mark staff 278 28 Apr 13:45 frame-14.png
-rw-r--r-- 1 mark staff 278 28 Apr 13:45 frame-15.png
If I now want to select some to make an animated GIF, I can use the shell's "brace expansion" to select certain ones:
ls frame-0{2,3,9}.png
frame-02.png frame-03.png frame-09.png
Or the shell's "range expansion" to select a contiguous range:
ls frame-1[2-4].png
frame-12.png frame-13.png frame-14.png
Or the shell's "wildcard expansion":
ls frame-1?.png
frame-10.png frame-11.png frame-12.png frame-13.png frame-14.png frame-15.png
And that works with magick just the same as ls, so I can select a few frames for an animated GIF like this:
magick -delay 80 frame-0{2,4}.png frame-1*.png animated.gif

How to rename all directories on a terminal

I have a total of 31 directories. Every directory has a random name.
❯ ls -al
total 32
drwxr-xr-x 34 shinokada staff 1088 Dec 28 17:16 .
drwxr-xr-x 32 shinokada staff 1024 Dec 28 17:12 ..
-rw-r--r--# 1 shinokada staff 14340 Dec 28 17:16 .DS_Store
drwxr-xr-x 5 shinokada staff 160 Dec 28 17:10 05618066
drwxr-xr-x 5 shinokada staff 160 Dec 28 17:08 0fef2d20
drwxr-xr-x 5 shinokada staff 160 Dec 28 17:09 11ff096d
drwxr-xr-x 5 shinokada staff 160 Dec 28 17:09 1651ff1f
drwxr-xr-x 5 shinokada staff 160 Dec 28 17:09 2123b256
... and more
Now I'd like to rename them sample1 sample2 sample3 ...sample31.
How can I do it on a terminal(bash/zsh)?
Is there a quick way to do it rather than rename one by one?
This should do:
num=1; for dir in */ ; do mv "${dir}" "sample$num" ; ((num++)); done
I assume you don't want to rename the files, only directories inside your current working directory.

Sorting ls output by file size

I am currently sorting the output of ls -l by byte count using:
ls -l | sort -r -k5,5 -n
What if I wanted to make this work with the -# flag? Currently this will output:
-rwxr-xr-x# 1 name staff 7106 2 May 10:43 c
-rwxr-xr-x 1 name staff 675 22 Apr 17:57 a
-rwxr-xr-x 1 name staff 486 23 Apr 07:56 b
drwxr-xr-x 4 name staff 136 25 Apr 18:38 d
-rwxr-xr-x 1 name staff 120 23 Apr 07:59 e
-rwxr-xr-x 1 name staff 112 22 Apr 18:45 g
-rwxr-xr-x 1 name staff 51 22 Apr 18:45 f
total 56
com.apple.metadata:_kMDItemUserTags 42
Where I want it to take the extended attribute keys line and keep it below the appropriate file like so:
-rwxr-xr-x# 1 name staff 7106 2 May 10:43 c
com.apple.metadata:_kMDItemUserTags 42
-rwxr-xr-x 1 name staff 675 22 Apr 17:57 a
-rwxr-xr-x 1 name staff 486 23 Apr 07:56 b
drwxr-xr-x 4 name staff 136 25 Apr 18:38 d
-rwxr-xr-x 1 name staff 120 23 Apr 07:59 e
-rwxr-xr-x 1 name staff 112 22 Apr 18:45 g
-rwxr-xr-x 1 name staff 51 22 Apr 18:45 f
total 56
No need to use sort, just use the -S option with ls
ls -Sl
(that's an upper case S)

Symfony2 : can't duplicate site because of strange folders architecture

I have to retrieve an existing symfony2 (2.1.13) project from prod server in order to run it locally to make some changes. The problem is the architecture seems to be a little bit strange. Please have a look on it :
$pwd
/var/www/html/sites/www.mysite.com
drwxr-xr-x 2 ... 4.0K Jun 30 09:30 backups/
drwxr-x--- 2 ... 6 Mar 15 2013 cgi-bin/
drwxr-xr-x 4 ... 41 Aug 10 18:09 _copie1/
drwxr-xr-x 2 ... 6 Apr 25 2014 log/
drwxr-xr-x 12 ... 4.0K Aug 11 15:41 releases/
drwxr-xr-x 7 ... 146 May 12 16:46 repo/
drwxr-xr-x 5 ... 85 May 12 16:49 shared/
lrwxrwxrwx 1 ... 58 Jul 6 15:11 current -> /var/www/html/sites/www.mysite.com/releases/201508/
lrwxrwxrwx 1 ... 12 Mar 28 2013 html -> current/web//
-rw-r--r-- 1 ... 1022 Jul 6 15:11 revisions.log
current/
drwxr-xr-x 6 ... 4.0K Jul 6 15:09 app/
drwxr-xr-x 2 ... 124 Jul 6 15:05 bin/
drwxr-xr-x 4 ... 50 Aug 11 14:54 src/
drwxr-xr-x 35 ... 4.0K Aug 11 12:08 vendor/
drwxr-xr-x 5 ... 4.0K Aug 11 18:28 web/
-rw-r--r-- 1 ... 626 Jul 6 15:05 Capfile
-rw-r--r-- 1 ... 4.1K Jul 6 15:05 composer.json
-rw-r--r-- 1 ... 167K Jul 6 15:05 composer.lock
-rw-r--r-- 1 ... 216 Jul 6 15:05 Gemfile
-rw-r--r-- 1 ... 1.2K Jul 6 15:05 Gemfile.lock
-rw-r--r-- 1 ... 1.1K Jul 6 15:05 LICENSE
-rw-r--r-- 1 ... 1.6K Jul 6 15:05 README.md
-rw-r--r-- 1 ... 8 Jul 6 15:06 REVISION
-rw-r--r-- 1 ... 7.7K Jul 6 15:05 UPGRADE.md
-rw-r--r-- 1 ... 7 Jul 6 15:05 VERSION
current/web/
drwxr-xr-x 2 ... 4.0K Aug 11 12:10 bundles/
drwxr-xr-x 4 ... 4.0K Jul 6 15:11 compiled/
drwxr-xr-x 2 ... 47 Jul 6 15:11 js/
-rw-r--r-- 1 ... 46K Jul 6 15:11 apc.php
-rw-r--r-- 1 ... 11K Jul 6 15:05 apple-touch-icon.png
-rw-r--r-- 1 ... 7.0K Jul 6 15:05 apple-touch-icon-precomposed.png
-rw-r--r-- 1 ... 728 Jul 6 15:05 app.php
-rw-r--r-- 1 ... 33K Jul 6 15:05 favicon.ico
-rw-r--r-- 1 ... 20K Jul 6 15:05 favicon.jpg
-rw-r--r-- 1 ... 4.6K Jul 6 15:05 favicon.png
lrwxrwxrwx 1 ... 51 Jul 6 15:06 image -> /var/www/html/sites/www.mysite.com/shared/web/image/
lrwxrwxrwx 1 ... 52 Jul 6 15:06 medias -> /var/www/html/sites/www.mysite.com/shared/web/medias/
-rw-r--r-- 1 ... 66 Aug 10 12:28 robots.txt
-rw-r--r-- 1 ... 2.2M Aug 11 03:00 sitemap.xml
current/web/bundles/
lrwxrwxrwx 1 ... 147 Jul 6 15:09 bazingaexposetranslation -> /var/www/html/sites/www.mysite.com/releases/201508/vendor/willdurand/js-translation-bundle/Bazinga/ExposeTranslationBundle/Resources/public/
lrwxrwxrwx 1 ... 121 Jul 6 15:09 ericharddms -> /var/www/html/sites/www.mysite.com/releases/201508/vendor/erichard/dms-bundle/Erichard/DmsBundle/Resources/public/
lrwxrwxrwx 1 ... 126 Jul 6 15:09 farosadmin -> /var/www/html/sites/www.mysite.com/releases/201508/vendor/faros/admin-bundle-legacy/Faros/AdminBundle/Resources/public/
lrwxrwxrwx 1 ... 125 Jul 6 15:09 faroselfinder -> /var/www/html/sites/www.mysite.com/releases/201508/vendor/faros/elfinder-bundle/Faros/ElFinderBundle/Resources/public/
lrwxrwxrwx 1 ... 113 Jul 6 15:09 farosqb -> /var/www/html/sites/www.mysite.com/releases/201508/vendor/faros/qb-bundle/Faros/QBBundle/Resources/public/
lrwxrwxrwx 1 ... 116 Jul 6 15:09 fosjsrouting -> /var/www/html/sites/www.mysite.com/releases/201508/vendor/friendsofsymfony/jsrouting-bundle/Resources/public/
lrwxrwxrwx 1 ... 133 Jul 6 15:09 framework -> /var/www/html/sites/www.mysite.com/releases/201508/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Resources/public/
lrwxrwxrwx 1 ... 132 Jul 6 15:09 mopabootstrap -> /var/www/html/sites/www.mysite.com/releases/201508/vendor/mopa/bootstrap-bundle/Mopa/Bundle/BootstrapBundle/Resources/public/
lrwxrwxrwx 1 ... 129 Jul 6 15:09 trsteelckeditor -> /var/www/html/sites/www.mysite.com/releases/201508/vendor/trsteel/ckeditor-bundle/Trsteel/CkeditorBundle/Resources/public/
lrwxrwxrwx 1 ... 99 Jul 6 15:09 mysiteadmin -> /var/www/html/sites/www.mysite.com/releases/201508/src/mysite/AdminBundle/Resources/public/
lrwxrwxrwx 1 ... 98 Jul 6 15:09 mysitesite -> /var/www/html/sites/www.mysite.com/releases/201508/src/mysite/SiteBundle/Resources/public/
current/app/
drwxr-xr-x 4 ... 27 Aug 11 18:32 cache/
drwxr-xr-x 3 ... 4.0K Aug 11 12:12 config/
drwxr-xr-x 2 ... 4.0K Jul 6 15:05 DoctrineMigrations/
drwxr-xr-x 8 ... 105 Jul 6 15:06 Resources/
-rw-r--r-- 1 ... 141 Jul 6 15:05 AppCache.php
-rw-r--r-- 1 ... 4.3K Jul 6 15:05 AppKernel.php
-rw-r--r-- 1 ... 474 Jul 6 15:05 autoload.php
-rw-r--r-- 1 ... 48K Jul 6 15:09 bootstrap.php.cache
-rw-r--r-- 1 ... 1.7K Jul 6 15:09 check.php
-rwxr-xr-x 1 ... 794 Jul 6 15:05 console*
lrwxrwxrwx 1 ... 50 Jul 6 15:06 logs -> /var/www/html/sites/www.mysite.com/shared/app/logs/
-rw-r--r-- 1 ... 1.7K Jul 6 15:05 phpunit.xml.dist
-rw-r--r-- 1 ... 26K Jul 6 15:09 SymfonyRequirements.php
lrwxrwxrwx 1 ... 49 Jul 6 15:06 var -> /var/www/html/sites/www.mysite.com/shared/app/var/
As you can see there are so many symlinks :(
I have a new installation of symfony 2.1.13 on my wamp server, so :
1. What should I exactly copy from the server ?
2. And where to copy ?
3. How to configure files like AppKernel.php, config.php, parameters.yml ...
Thanks :)
Looks like you are stepped to the task from apposite side
First of all "strange" folders architecture is comming from the nature of the deployment tool "capifony". You can see folder "releases" that keeps all history of releases deployed and folder(symlink) "current" that points to the latest(current) release. Also you can see some symlinks to the folder "shared" that suppose to keep some content that doesn't suppose change from deploy to deploy (like images, logs).
It is possible to explain long how capifony works, but seems it is better to get some quick overview http://capifony.org/
In short words I can say that you can copy the site to local, but it is not the best way. I suppose you need to clone the project from its repository(most probably git) and setup parameters.yml
You should not change AppKernel.php or config.php
Clone the respository and looks for app/config/parameters.yml.dist that will(should) have initial configuration for the project
PS: you should not copy "current/web/bundles/" but should use "assets install" command to create these assets
PPS: And I believe you should to learn some symfony docs(at least basic) before start to copy the site

How to include a library in the path while compiling?

I'm reading this post about go and was trying to compile the source code found here
I downloaded the source code, compiled the first file with make and I can see the object is generated:
$pwd
/Users/oscarryz/code/go/rsc/rosetta/graph
$ls -ltR
total 136
-rw-r--r-- 1 oscarryz staff 61295 Sep 17 16:20 _go_.6
drwxr-xr-x 3 oscarryz staff 102 Sep 17 16:20 _obj
-rw-r--r-- 1 oscarryz staff 126 Sep 17 16:17 Makefile
-rw-r--r-- 1 oscarryz staff 2791 Sep 17 16:17 graph.go
./_obj:
total 0
drwxr-xr-x 3 oscarryz staff 102 Sep 17 16:20 rsc.googlecode.com
./_obj/rsc.googlecode.com:
total 0
drwxr-xr-x 3 oscarryz staff 102 Sep 17 16:20 hg
./_obj/rsc.googlecode.com/hg:
total 0
drwxr-xr-x 3 oscarryz staff 102 Sep 17 16:20 rosetta
./_obj/rsc.googlecode.com/hg/rosetta:
total 136
-rw-r--r-- 1 oscarryz staff 68486 Sep 17 16:20 graph.a
No my question is, how do I refer to that compiled code from the maze directory:
/Users/oscarryz/code/go/rsc/rosetta/maze/maze.go
Whose import declarations are:
import (
"bytes"
"fmt"
"rand"
"time"
"rsc.googlecode.com/hg/rosetta/graph"
)
And right now is failing to compile with the error message:
6g -o _go_.6 maze.go
maze.go:20: can't find import: rsc.googlecode.com/hg/rosetta/graph
make: *** [_go_.6] Error 1
Ok, I found it, wasn't that hard.
6g flags: -I DIR search for packages in DIR
I have to specify the -I option like this:
6g -I ../graph/_obj/ -o _go_.6 maze.go

Resources