How to show SPECIFIC hidden files on mac? - macos

Such as by file extension?
For instance, I don't want to see .DS_STORE files, but I want to see all .htaccess files. Is there a way to do this?

Open a terminal and type
ls -a | grep -G .YOUR_EXTENSION$
See http://www.robelle.com/smugbook/regexpr.html for more information of regex
Also man grep and man ls will be of use

Related

How to remove only extension from origin file with certain extension recursively in folder?

How to remove only extension from origin file with certain extension recursively in folder?
example, If I have
/foo/bar/index.html
/foo/bar/error.html
/foo/bar/static/hi.html
/foo/bar/static/me.jpg
/foo/bar/static/you.jpg
/foo/bar/build/yep.html
And I expect follows after excute some command
/foo/bar/index
/foo/bar/error
/foo/bar/static/hi
/foo/bar/static/me.jpg
/foo/bar/static/you.jpg
/foo/bar/build/yep
Thanks for the help.
Please tell some OS's command If command exist (windows, ubuntu/linux)
As a command :
ls | find *.html | for f in *.html; do mv $f $(echo $f|sed s/.html//);done

How can I grab download links from a website

Is there any way of getting download links from a website and put those like in a text file?
To download hose files later in with wget ?
You need to download the source of the website. You can use wget link-of-the-webiste-you-want-to-grab-links-from for that. Than you can sed the links like this: sed -n 's/.*href="\([^"]*\).*/\1/p' file
The this questions for details.
With this you can download jpg file, instead of jpg you can give any file format which should be present in source_file. Your downloading links list will be in link.txt
grep -Po 'href=\"\/.+\.jpg' source_file | sed -n 's/href="\([^"]*\)/\1/p' >link.txt; wget -i link.txt

tar -h with symlinks pointing to themselves

I have a pretty bad issue where when I tar a series of directories, I want to remove symlinks and tar the file they belong to. I do this using -h option which works perfectly fine up until I have a directory which is symlinked to the directory above.
For Example:
/etc/versions/product
product.php
product2.php
product -> /etc/versions/product
Is there a way to skip these directories or only follow the symlink once? I do have an excludes list however I do not fancy going through the entire system and excluding them individually unless it is the only option
this is the command im using, im sorry I cannot be more specific than that:
tar cvzfh ${BACKUP} --exclude-from ${EXCLUDES_FILE} ${MYSQLFILES} ${LDAP_FILE} ${PATHS}
I have figured it out using find to find any symlinks with loop to themselves.
find **path** -follow > /dev/null 2>/tmp/symlinkFiles && cat /tmp/symlinkFiles | awk '{print $4}'

cp: silence "omitting directory" warning

I'm using the command cp ./* "backup_$timestamp" in a bash script to backup all files in directory into a backup folder in a subdirectory. This works fine, but the script keeps outputting warning messages:
cp: omitting directory `./backup_1364935268'
How do I tell cp to shut up without silencing any other warnings that I might want to know about?
The solution that works for me is the following:
find -maxdepth 1 -type f -exec cp {} backup_1364935268/ \;
It copies all (including these starting with a dot) files from the current directory, does not touch directories and does not complain about it.
Probably you want to use cp -r in that script. That would copy the source recursively including directories. Directories will get copied and the messages will disappear.
If you don't want to copy directories you can do the following:
redirect stderr to stdout using 2>&1
pipe the output to grep -v
script 2>&1 | grep -v 'omitting directory'
quote from grep man page:
-v, --invert-match
Invert the sense of matching, to select non-matching lines.
When copying a directory, make sure you use -R
cp -R source source_duplicate_copy_name
-R, -r, --recursive copy directories recursively
--reflink[=WHEN] control clone/CoW copies. See below
--remove-destination remove each existing destination file before
attempting to open it (contrast with --force)
--sparse=WHEN control creation of sparse files. See below
--strip-trailing-slashes remove any trailing slashes from each SOURCE

How do I view the permissions of a file w/o using ls -l?

I just want to check the permissions of a single file w/o having to look through all of the files in the current directory.
You can use ls with a single file: ls -l filename. Alternatively, you can use the stat command.
there are few ways,
pass the file to ls -l <filename>
use stat eg stat file or use its options for permission format
use a programming language with stat like capability, eg Ruby
$ ruby -e 'puts sprintf( "%o" , File.stat("file").mode )'

Resources