Can a symlink negatively affect the original file? - shell

I want to upload a markdown file named "original.md" to a repo, but it has to stay named like that. I want the "README.md" which GitHub displays automatically to link to it.
$ ln -s original.md README.md
It creates a link, then the files look like so:
-rw-r--r--. 1 username username 32K Nov 8 11:33 original.md
lrwxrwxrwx. 1 username username 15 Nov 12 02:23 README.md -> original.md
Now if I stage, commit, and push to git everything will look fine, the "original.md" will display through README.md.
However, what if I change my mind one day and decide that I don't need the README.md anymore because I don't want my files in Git anymore? Let's say I delete it:
$ rm README.md
While this removal have any negative effect on the "original.md" file?

No, it is a symlink... you can remove it safely. If you remove original.md instead the symlink will not work anymore.
You can just have a look https://linuxize.com/post/how-to-create-symbolic-links-in-linux-using-the-ln-command/

Related

Searching for a file in a directory of gziped tar files

OK, I have a directory where I backup my dev server every hour. I work a great many projects at the same time and I use GIT and at times uncommitted files are deleted when I go from branch to branch. I am sure I could avoid this with some neat GIT trickery or simply slowing down to read what GIT is about to do, but we are on year 36 of coding and year 12 of using GIT and sometimes my fat, old fingers just want to start over. It doesn't happen often but it happens.
So here is my directory
Backup_09_15_2021-20:00.tar.gz
Backup_09_15_2021-21:00.tar.gz
Backup_09_15_2021-22:00.tar.gz
Backup_09_15_2021-23:00.tar.gz
...
Each of these is about 2G and contains hundreds of thousands of files each. I retain several days of files so there might be 70-120 of these files in the directory
What I need to do is find a file by name, pretty simple
So for example, today I was missing a file called createPackageCommand.php. I need to see all the files that have a file by that name and print out the info so I can see file sizes and dates.
My current bash command looks like this
find . -name "Backup_*.tar.gz" -exec bash -c 'echo {};tar -ztvf {} | grep CreatePackageCommand' \;
It outputs something like this
./Backup_09_20_2021-16:00.tar.gz
./Backup_09_19_2021-15:00.tar.gz
./Backup_09_22_2021-17:00.tar.gz
./Backup_09_17_2021-11:00.tar.gz
./Backup_09_21_2021-10:00.tar.gz
./Backup_09_16_2021-17:00.tar.gz
./Backup_09_23_2021-11:00.tar.gz
./Backup_09_17_2021-08:00.tar.gz
./Backup_09_21_2021-16:00.tar.gz
-rw-r--r-- 0 kbrill staff 2874 Sep 21 11:12 var/www/crm/custom/src/Console/Command/CreatePackageCommand.php
So it prints out each tar files name and if there is a matching file in it then we get the greps output for that.
Its slow, ugly and I can't live without it.
2 questions
Is there a better way to search these files?
Is there a way to make the command search the files in order. Newest to oldest?

mac permission download folder ls folder

I can't ls my /Users/alex/Downloads folder.
Other folders work normal.
touch blub.txt works.
via finder I see everything.
Permission are as followed:
613923 0 drwx---r-x# 4 alex staff 128B 29 Jan 22:21 Downloads
I don't understand the behaviour.

Cannot change com.apple.atrun.plist even with root permissions

I'm using OSX Mojave and I've been wanting to use the at command to run scripts at certain times, but I've discovered that I need to change its plist file in order to use it. Right now, one of the attributes in it is Disabled=true which of course, isn't what I want.
I've gone to the ends of the earth to try to change that. I tried XCode, Pref Setter, chmod, chown, vim, and doing all of that in root. No matter what, it always says, "readonly file" or "You do not have permission."
Are plists supposed to be immutable? I'm pretty sure they aren't. Here is some of the things I've tried.
~root# id
uid=0(root) gid=0(wheel) groups=0(wheel ...
~root# atrun=/System/Library/LaunchDaemons/com.apple.atrun.plist
~root# chmod 777 $atrun
chmod: Unable to change file mode on
/System/Library/LaunchDaemons/com.apple.atrun.plist: Operation not permitted
~root# ls -l $atrun
-rw-r--r-- 1 root wheel 444 Aug 22 23:11 /System/Library/LaunchDaemons/com.apple.atrun.plist
Make a copy of com.apple.atrun.plist from /System/Library/LaunchDaemons
into your home directory or wherever you want to work on it.
Open com.apple.atrun.plist with Xcode and the settings will show up in user readable form.
Change the setting for "Disabled" from 1 to 0 then save and exit Xcode
Copy your changed com.apple.atrun.plist file to /Library/LaunchDaemons
This can be manually launched to enable batch.

Why can't I run the go binary from within the /bin directory?

I downloaded go1.7.5.darwin-amd64.tar.gz for osx 10.12.2.
Unpacked the tar and went to the /bin directory to see if the Go executable would run.
$ cd Downloads/go/bin
$ ls
total 54560
-rwxr-xr-x# 1 bryanwheelock staff 9884220 Feb 10 16:53 go
-rwxr-xr-x# 1 bryanwheelock staff 15065500 Feb 10 16:53 godoc
-rwxr-xr-x# 1 bryanwheelock staff 2976976 Feb 10 16:53 gofmt
bryanwheelock#Bryans-MacBook Fri Feb 10 16:57:45 ~/Downloads/go/bin
$ go version
-bash: go: command not found
When you type a command without giving the full path, your system will try to find it within all the folders provided in $PATH variable.
In typical Unix environment, your $PATH does not include "your current folder". So you need to either:
call go by its full path (i.e. $HOME/Downloads/go/bin/go); or
call go by its relative path (i.e. ./go); or
put $HOME/Downloads/go/bin in your $PATH variable; or
put . (Unix way of saying "your current folder") in your $PATH; or
put your go binary into folders that already in your $PATH. For example
sudo cp $HOME/Downloads/go/bin/* /usr/local/bin/.
sudo chmod +x go
seems like it does not have execute permission, so just change permission and run it then you should alias your go binary path to your environment to access binary every where.

Best practice for saving temporary files in macOS?

Is there a common practice where to save temporary files on macOS?
Currently I'm using /tmp but I often see the folder /var/folders in use for saving temporary files.
Is there a suggested way?
Thanks!
I don't know of any official guide, but I would say:
use /tmp for temporary things that do not need to survive a reboot
use /var/tmp for temporary things that do need to survive reboot
On my system at least, /var/folders is quite restricted in who can access it:
drwxr-xr-x 4 root wheel 136 28 Oct 2015 /var/folders

Resources