How to recursively list (ls) a symbolically linked directory on the Mac terminal - terminal

I want to list all directories and subdirectories in a folder on my Mac (OS Catalina) using terminal. One of the directories is a symbolically linked directory (alias).
ls -R
works fine but doesn't list the contents of the alias directory.
So I did a man on ls and saw that I can do
ls -L -R
The -L flag supposedly lists symbolically linked directories and their contents.
However, I get the identical output with both commands.
How can I list the contents of the symbolically linked directory as well?

Related

Unpacking a tar.gz file with symlinks into another directory

I have a directory on a Unix server that contains many subdirectories and many symlinks that point to subdirectories. If I display the contents with ls -la, the following path is displayed, for example.
/customers/41/websites/cms
I have packed the directory cms with all subdirectories and symlinks.
Now I want to discover everything on my Mac. However, into another basic directory, as I cannot create the following directory because of the rights:
/clients/41/websites/cms
I have created a directory on my Mac:
~/development/www/mycompany/clients/41/websites/cms
Everything should be unpacked there with working symlinks.
How can I realise this?
You could try to use tardy to transform the tar ball file.
Or write your C program using #include <tar.h>
See also GNU tar (or compile it then improve it on your MacOSX system)

Is there a command in macOS terminal that can recursively search a string in all files under current directory (including sub-directory)?

I want to know if there is a command in macOS, similar to the grep -r <target-string> in Linux, that can list all lines containing <target-string> in files under current directory (including files in subdirectories).
Thanks!
Screenshot

bin of .app not visible using ls or even ls -a

I noticed something rather interesting yesterday. ls and ls -a don't show the underworking of a .app "directory?", yet you can cd into the bin file of the app if you know the path. Why is this?
I'm not of the Mac world, but in general, when asked for the contents of a given directory, a file system delivers a list of names; and when asked for a particular entry in that directory it is free to return values even when the entry wasn't listed before. The two functions are independent in general, but of course most file systems keep these congruent most of the time. It seems, OSX breaks this congruency deliberately.
Example:
The file system is asked for the contents of directory /foo/bar and it returns the list of the entries xyz, abc, and blah. This means that the entries /foo/bar/xyz, /foo/bar/abc, and /foo/bar/blah exist.
When asked for the stat() of the path /foo/bar/ghi, one could assume that the file system now has to answer with No Such File or a similar error. But in fact, it does not have to. It can return stats which mean that the path is a directory or similar.
While this is unusual in general, the operating system itself and most tools can handle this situation quite well. Tools like ls or find rely on the list of directory entries, so they will process only the entries returned by the file system. But if given an explicit path (which wasn't part of a list of directory entries), they will process that one.
You can make a test: If ls -la /Applications/ doesn't list MATLAB_R2013a_Student.app, you will probably still be able to get information by typing ls -la /Applications/MATLAB_R2013a_Student.app directly.
Some more remarks: Whether you enter that directory (cd) is of no concern. cd can be done on any directory which exists and for which (and for whose parents) you have execute permissions, that's all. The -a flag of ls lists also files starting with a ., but they are not considered "hidden", only "system", i. e. not relevant for normal user interactions. Most of the dot-files are configuration files etc.

Opening symlink to .txt file results in permission denied on MAC OS X

Assume I have two folders and a .txt file in a directory such that
/folder1/file.txt
/folder2
Being currently in folder1 I create a symlink with ln -s file.txt ../folder2/. If a now cdinto folder2 and open the symbolic link in vim with vim file.txt the editor opens with an empty file prompting "test.txt" [Permission Denied]in the status bar. Additionally the file only open in "readonly" mode. Is there a way to create a working symlink. I am on Mac OS X.
Update:
ls -lR on the original file results in -rw-r--r-- and for the symlink I obtain lrwxr-xr-x.
I would suggest trying to enter the complete path to the target. e.g.
ln -s /folder1/file.txt ../folder2/
The path to the link can be relative.

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