Why do I need Root privilege to do `git branch -a`? - bash

The git repository is under my username nikhil and group nikhil as follows:
$ ls -l
drwxr-xr-x 10 nikhil nikhil 4096 Sep 1 12:33 CS/
I can get git status as git status without root privilege.
But when I try to list branches:
$ git branch -a
nothing happens.
Also, with root priviledge:
$ sudo git branch -a
[sudo] password for nikhil:
* master
remotes/origin/feature
remotes/origin/master
it does lists all my repository.
Why is it so?
Edit: output of ls -lh .git
$ ls -lh .git
total 332K
drwxr-xr-x 2 nikhil nikhil 4.0K May 25 16:32 branches
-rw-r--r-- 1 nikhil nikhil 2 Sep 1 12:25 COMMIT_EDITMSG
-rw-r--r-- 1 nikhil nikhil 5.6K Sep 1 12:33 config
-rw-r--r-- 1 nikhil nikhil 73 May 25 16:32 description
-rw-r--r-- 1 nikhil nikhil 90 Sep 1 12:33 FETCH_HEAD
-rw-rw-r-- 1 nikhil nikhil 23 Sep 1 12:33 HEAD
drwxr-xr-x 2 nikhil nikhil 4.0K Jun 11 15:25 hooks
-rw-r--r-- 1 nikhil nikhil 229K Sep 1 12:34 index
-rw-r--r-- 1 nikhil nikhil 44K Jun 11 08:56 INDEX
drwxr-xr-x 2 nikhil nikhil 4.0K Jun 11 15:25 info
drwxr-xr-x 3 nikhil nikhil 4.0K Jun 11 15:28 logs
drwxr-xr-x 8 nikhil nikhil 4.0K Aug 11 18:01 modules
drwxr-xr-x 260 nikhil nikhil 4.0K Jun 27 15:29 objects
-rw-rw-r-- 1 nikhil nikhil 41 Sep 1 12:33 ORIG_HEAD
drwxr-xr-x 5 nikhil nikhil 4.0K Jun 11 15:25 refs
I identified the problem it was due to Anaconda in my .bashrc:
export PATH="$HOME/anaconda3/bin:$PATH"
if [ -f $HOME/anaconda3/etc/profile.d/conda.sh ]; then
source $HOME/anaconda3/etc/profile.d/conda.sh
fi
conda activate
What should I do? When I comment this out git branch -a works.

conda provides its own pager binary (not more or less, but pager). Using sudo clears your PATH -- so it fixes the problem not by virtue of changing permissions, but by virtue of preventing this faulty binary from being used at all.
To prevent this from having any undesired behaviors, move it out of the way:
mv ~/anaconda3/bin/pager{,.bad}

Related

Why I am getting Screen is terminating error in MacOS

When trying to enter into Docker VM in mac, I am getting screen is terminating error whereby I cannot go into Docker Desktop. In Mac, Docker host is not the mac as it runs as a VM. Any solutions?
Thank you for the help.
Workarounds
I think it's a bug since version 2.3.0.4 of Docker Desktop for Mac, as I have used screen successfully to access the Docker VM in the past on Mac without this issue. (edit: this issue appears to be still present at version 2.4.0.0)
There are some alternative methods to access the Docker VM. Here is one that worked for me:
workaround method 1
run this command to enter shell of the Docker VM:
docker run -it --privileged --pid=host debian nsenter -t 1 -m -u -n -i sh
Then you can do what you need to do at the usual location for Docker volumes:
/ # ls -lah /var/lib/docker/volumes/
total 72
drwx------ 10 root root 4.0K Aug 27 11:34 .
drwx--x--x 15 root root 4.0K Oct 31 00:51 ..
drwxr-xr-x 3 root root 4.0K Aug 26 10:44 14ce94e174839f1947efa6fcbf5ac1fb2ea3b0f0b3f25311fee333ee374576b6
drwxr-xr-x 3 root root 4.0K Aug 25 12:34 34eb2bd80931ff954e1da80c5383beb4def61129d4005432b77080531cd10a5a
drwxr-xr-x 3 root root 4.0K Aug 27 11:34 830de2ce31519c921b50c448964b54517ca4461d337b56a9fd6e5b354ace3247
drwxr-xr-x 3 root root 4.0K Aug 25 12:34 data-layer_mongo_data
drwxr-xr-x 3 root root 4.0K Aug 26 11:01 ebb440184703bfad17184bd5ff74b677b50d74b8f0fbdd116506a1fcacfb00cd
drwxr-xr-x 3 root root 4.0K Aug 27 11:27 hawakening-services_back-end_log
drwxr-xr-x 3 root root 4.0K Aug 27 11:27 hawakening-services_front-end_log
drwxr-xr-x 3 root root 4.0K Aug 27 11:27 hawakening-services_mongo_data
-rw------- 1 root root 64.0K Oct 31 00:51 metadata.db
workaround method 2
Here's another one that also worked for me.
Run this command to enter shell of the Docker VM:
docker run --rm -it --privileged --pid=host walkerlee/nsenter -t 1 -m -u -i -n sh
As before, here is where the Docker volumes' directories are:
/ # ls -lah /var/lib/docker/volumes/
total 72
drwx------ 10 root root 4.0K Aug 27 11:34 .
drwx--x--x 15 root root 4.0K Oct 31 00:51 ..
drwxr-xr-x 3 root root 4.0K Aug 26 10:44 14ce94e174839f1947efa6fcbf5ac1fb2ea3b0f0b3f25311fee333ee374576b6
drwxr-xr-x 3 root root 4.0K Aug 25 12:34 34eb2bd80931ff954e1da80c5383beb4def61129d4005432b77080531cd10a5a
drwxr-xr-x 3 root root 4.0K Aug 27 11:34 830de2ce31519c921b50c448964b54517ca4461d337b56a9fd6e5b354ace3247
drwxr-xr-x 3 root root 4.0K Aug 25 12:34 data-layer_mongo_data
drwxr-xr-x 3 root root 4.0K Aug 26 11:01 ebb440184703bfad17184bd5ff74b677b50d74b8f0fbdd116506a1fcacfb00cd
drwxr-xr-x 3 root root 4.0K Aug 27 11:27 hawakening-services_back-end_log
drwxr-xr-x 3 root root 4.0K Aug 27 11:27 hawakening-services_front-end_log
drwxr-xr-x 3 root root 4.0K Aug 27 11:27 hawakening-services_mongo_data
-rw------- 1 root root 64.0K Oct 31 00:51 metadata.db

Putting files to HDFS

I am running below commands on console:
[root#master ~]# pwd
/root
[root#master ~]# vi test.txt
#editting file
[root#master ~]# su - hdfs -c "hdfs dfs -put /root/test.txt /user/ambari-qa"
put: `/root/test.txt': No such file or directory
the file is there
[root#master ~]# pwd
/root
[root#master ~]# ls -l
total 9636984
-rw-r--r--. 1 root root 1823777034 Jun 12 08:34 ambari-2.6.2.2-centos6.tar.gz
-rw-------. 1 root root 716 Mar 19 2012 anaconda-ks.cfg
drwxr-xr-x. 2 root root 4096 Oct 15 11:30 Desktop
drwxr-xr-x. 2 root root 4096 Oct 15 11:30 Documents
drwxr-xr-x. 2 root root 4096 Oct 15 11:30 Downloads
-rw-r--r-- 1 root root 15 Oct 18 20:16 enabled~
-rw-r--r-- 1 root root 15 Oct 18 20:38 enablez~
-rw-r--r--. 1 root root 511720220 Oct 15 19:33 HDP-2.6.5.0-centos6-rpm.tar.gz
-rw-r--r--. 1 root root 7303095942 May 15 03:50 HDP-2.6.5.0-centos6-rpm.tar.gz.1
-rw-r--r--. 1 root root 43941068 Aug 13 20:28 HDP-UTILS-1.1.0.22-centos6.tar.gz
-rw-r--r--. 1 root root 185646832 Oct 15 17:04 jdk-8u181-linux-x64.tar.gz
drwxr-xr-x. 2 root root 4096 Oct 15 11:30 Music
drwxr-xr-x. 2 root root 4096 Oct 15 11:30 Pictures
-rw-r--r--. 1 root root 12148 Dec 16 2011 post-install
-rw-r--r--. 1 root root 552 Dec 16 2011 post-install.log
drwxr-xr-x. 2 root root 4096 Oct 15 11:30 Public
drwxr-xr-x. 2 root root 4096 Oct 15 11:30 Templates
-rw-r--r-- 1 root root 2 Oct 23 05:39 test
-rwxr-xr-x 1 root root 3 Oct 23 06:37 test.txt
However,I am getting no such file or directory, I am creating the file in the path but I get that error?
Seems the problem was due to privilege at /root directory
dr-xr-x---. 25 root root 4096 Oct 23 06:37 root
using chmod 755 worked then

Restrict hadoop client to not to create hidden checksum files

CopyToLocal command is creating a hidden checksum file. Is there a way to avoid this being created?
Unless you're running a very old version, Apache Hadoop only creates the local checksum file if you opt in to creating it by passing the -crc option as showing in the Apache Hadoop documentation for the copyToLocal command.
> hdfs dfs -copyToLocal /LICENSE.txt
> ls -lrta
drwxr-xr-x+ 131 naurc001 SWNA\Domain Users 4.3K Jan 27 09:18 ../
-rw-r--r-- 1 naurc001 SWNA\Domain Users 140K Jan 27 10:11 LICENSE.txt
drwxr-xr-x 7 naurc001 SWNA\Domain Users 238B Jan 27 10:11 ./
> hdfs dfs -copyToLocal -crc /LICENSE.txt
> ls -lrta
drwxr-xr-x+ 131 naurc001 SWNA\Domain Users 4.3K Jan 27 09:18 ../
-rw-r--r-- 1 naurc001 SWNA\Domain Users 140K Jan 27 10:07 LICENSE.txt
-rw-r--r-- 1 naurc001 SWNA\Domain Users 1.1K Jan 27 10:07 .LICENSE.txt.crc
drwxr-xr-x 8 naurc001 SWNA\Domain Users 272B Jan 27 10:07 ./
If you have the option, then I recommend running a current version and testing to make sure the -crc option is not being passed anywhere.

Successfully delete stringutil.a but it comes back on its own

I'm following "How to Write Go Code" and tries to delete stringutil.a under $GOPATH/pkg/darwin_amd64/github.com/user. The delete is successful but the file comes back on its own. I'm confused. What is happening?
zps-MacBook-Air:haibin haibin$ rm stringutil.a
zps-MacBook-Air:haibin haibin$ ls -lah
total 0
drwxr-xr-x 2 haibin staff 68B Feb 15 00:57 .
drwxr-xr-x 17 haibin staff 578B Feb 15 00:39 ..
zps-MacBook-Air:haibin haibin$ ls -lah
total 8
drwxr-xr-x 3 haibin staff 102B Feb 15 00:57 .
drwxr-xr-x 17 haibin staff 578B Feb 15 00:39 ..
-rw-r--r-- 1 haibin wheel 2.4K Feb 15 00:57 stringutil.a
You need to delete the stringutil.go source file that is under the src tree. The *.a file is a binary file which results from the compilation (and possibly linking) of source files.

what is ~/.npm dir for?

I have installed the global npm package jslint and it lives here
$ ls -la /usr/local/bin/jslint
lrwxr-xr-x 1 lust admin 40 Feb 12 15:31 /usr/local/bin/jslint -> ../lib/node_modules/jslint/bin/jslint.js
$ ls -la /usr/local/lib/node_modules/jslint/bin
total 8
drwxr-xr-x 3 lust staff 102 Apr 16 2012 .
drwxr-xr-x 10 lust staff 340 Feb 12 15:31 ..
-rwxr-xr-x 1 lust staff 2330 Apr 16 2012 jslint.js
$ which jslint
/usr/local/bin/jslint
$ head -3 /usr/local/bin/jslint
#!/usr/bin/env node
var linter = require("../lib/linter");
So it is without any doubt whatsoever at this point that jslint is in fact being run from this dir and not here:
$ ls -la .npm/jslint/0.1.9/package/bin/
total 8
drwxr-xr-x 3 lust staff 102 Apr 16 2012 .
drwxr-xr-x 9 lust staff 306 Feb 12 15:31 ..
-rwxr-xr-x 1 lust staff 2330 Apr 16 2012 jslint.js
There appear to be two copies of the package, one in /usr/local/ and one in ~/.npm. Why is there one in .npm and is it safe for me to remove it?
~/.npm is a cache that npm uses to avoid re-downloading the same package multiple times. There's no harm in removing it. You can empty it with the command:
npm cache clean

Resources