Getting stat (ls or cp) of hidden files - linux

I have a folder with a .tmux.conf file under source control, and I would like to copy that file over to ~. Here is an ls of that:
ubuntu#ip-172-180:~$ ls -alh .vim/others
total 12K
drwxrwxr-x 2 ubuntu ubuntu 4.0K May 2 19:05 .
drwxrwxr-x 6 ubuntu ubuntu 4.0K May 2 19:05 ..
-rw-rw-r-- 1 ubuntu ubuntu 706 May 2 19:05 .tmux.conf
However, when I do ls on that directory, I get nothing:
ubuntu#ip-172-30-1-180:~$ ls .vim/others/*
ls: cannot access '.vim/others/*': No such file or directory
Same with cp:
ubuntu#ip-172-30-1-180:~$ cp .vim/others/* .
cp: cannot stat '.vim/others/*': No such file or directory
Is there some additional parameter I have to add when copying over dot files?

check this command
ls -ld .[!.]*
ls -ld .vim/others/[!.]*

Related

setuid on echo command but not working as expected

I have a question about setuid:
for example, there is a file - 1.txt, only root has write permission:
$ll 1.txt
-rw-r--r--. 1 root root 57 Jul 1 12:19 1.txt
For an ordinary user to modify the file, I did the following:
$ sudo chmod u+s /usr/bin/echo
$ ll /usr/bin/echo
-rwsr-xr-x. 1 root root 33128 Oct 31 2018 /usr/bin/echo
However, when the user ran below command, it still got permission error.
$ echo 111 > 1.txt
bash: 1.txt: Permission denied
Then I did a similar test on ls command:
Only root has write permission to test/ directory:
$ ll -d test/
drw-------. 2 root root 34 Jul 1 14:18 test/
a user that run ls command would report an error
$ ls test/
ls: cannot open directory test/: Permission denied
Then setuid on ls command:
$ sudo chmod u+s /usr/bin/ls
$ ll /usr/bin/ls
-rwsr-xr-x. 1 root root 117680 Oct 31 2018 /usr/bin/ls
after this, the user was able to run the command
$ ls test/
1 23 4
What's the difference between echo and ls? Or what I missed here?

How to tar a branch of file tree?

I currently have some files and directories at this path:
/var/tmp/mydir/
I want to tar the whole path, excluding any other content in 'var' and 'tmp'.
Example:
$ ls /var
tmp
dir1 *(exclude)*
file1 *(exclude)*
$ ls /var/tmp
mydir
dir2 *(exclude)*
file2 *(exclude)*
$ ls /var/tmp/mydir
tarme1
tarme2
tarme3
In this case, I want to tar the directory tree /var/tmp/mydir and the content of 'mydir'.
Use tar -cf <archive_name>.tar /var/tmp/mydir which will give you what you need.
Use man tar to get more help (should be quite easy to understand).
If you want to modify your path some other way consider using -C switch. From man:
-C, --directory DIR
change to directory DIR
Do
tar -c --recursion --file backup.tar tmp/mydir
and
tar -tvf backup.tar
gives me :
drwxrwxr-x ssam/ssam 0 2016-05-02 12:02 tmp/mydir/
-rw-rw-r-- ssam/ssam 0 2016-05-02 12:02 tmp/mydir/tarme3
-rw-rw-r-- ssam/ssam 0 2016-05-02 12:02 tmp/mydir/tarme1
-rw-rw-r-- ssam/ssam 0 2016-05-02 12:02 tmp/mydir/tarme2
which is what you need. You can extract/restore it using
tar -xf backup.tar -C /var
Remember this will overwrite the files in mydir

realpath on Cygwin is not same as PWD

$ pwd
/home/Thomas/Utveckling/Cgreen/thoni56/cgreen
$ realpath .
/cygdrive/c/Users/Thomas/Utveckling/Cgreen/thoni56/cgreen
$ cygpath -a .
/cygdrive/c/Users/Thomas/Utveckling/Cgreen/thoni56/cgreen/
Why is this? Why is absolute path from the root /cygdrive and not /?
How do I get an absolute path that starts with /home from a relative path, such as .., if I'm in that tree?
It is the effect of the presence of a link in the path.
Eg:
ls -ld /pub /tmp
lrwxrwxrwx 1 marco Administrators 19 Jun 26 2014 /pub -> /cygdrive/e/cyg_pub
drwxrwxrwx+ 1 marco Administrators 0 May 2 17:49 /tmp
$ realpath /pub /tmp
/cygdrive/e/cyg_pub
/tmp

Subdirectory not created with proper group even parent has SGID

I have a folder with the SGID bit on:
lucas#arturito:/home$ ls -l | grep share
drwxrwsr-x 11 share sambashare 4096 May 5 14:54 share
If I move into share an I create a folder within it, that folder will have the group 'sambashare'. So far, so good...
lucas#arturito:/home$ cd share/
lucas#arturito:/home/share$ mkdir test
lucas#arturito:/home/share$ ls -l | grep test
drwxrwsr-x 2 lucas sambashare 4096 May 5 15:07 test
Now, if I move under /home/share/test and create a new folder, that new folder inherits the group: SGID is working.
lucas#arturito:/home/share$ cd test
lucas#arturito:/home/share/test$ mkdir test1
lucas#arturito:/home/share/test$ ls -l | grep test1
drwxrwsr-x 2 lucas sambashare 4096 May 5 15:09 test1
However, under /home/share I do have other folders other than the newly created 'test'. If I move under any of those, and create a new folder (say 'test2'), that new folder will ignore the SGID and the group will be my group.
lucas#arturito:/home/share$ ls -l | grep 99
drwxrwxr-x 9 share sambashare 4096 May 5 15:11 99_varios
lucas#arturito:/home/share$ cd 99_varios/
lucas#arturito:/home/share/99_varios$ mkdir test2
lucas#arturito:/home/share/99_varios$ ls -l | grep test2
drwxrwxr-x 2 lucas lucas 4096 May 5 15:11 test2
Why is that happening? Isn't it enough for /home/share to have g+s for any other directory below it (new or old) to inherit /home/share's group?
I'm lost. Any hint or idea will be highly appreciated!
Thanks!
Lucas
New folders will inherit the bit but existing ones need to have it set explicitly. You can run the command below once to recursively set it on any existing subfolders.
find /home/share -type d -exec chmod g+s '{}' \;

Unable to set SGID bit on linux directory

I am trying to set SGID bit on all directories within this directory, but uanble to do so.
Can anybody please help ?
$ ls -ld Music
drwxrwxr-x 16 pankaj usrgrp 1024 Apr 14 14:54 Music
$ chmod -R g+s Music
$ echo $?
0
$ ls -ld Music
drwxrwxr-x 16 pankaj usrgrp 1024 Apr 14 14:54 Music
$

Resources