can't display extended file attributes on mac - macos

If I have the following output for a ls -l command on mac :
total 0
-rw-rw-r--# 1 <redicated> <redicated> 0 Mar 23 15:54 filename
In the man page I read that ls -# displays the extended attribute keys.
But for ls -# just the filename is printed to the terminal.
For ls -# filname I get ls: filename: No such file or directory

You need to list the files an entry per line. Like:
ls -l#

Related

Bash: Using asterisk in any bash command in home directory exits with error "Unrecognized options --list-sessions"

Title.
This same/similar error seems to occur with any command in bash if I:
Am in my home directory, i.e. after cd ~. It doesnt occur in other places.
Have an asterisk/wildcard in the command matching all of the files+dirs. It doesnt happen without the asterisk as far as I can tell.
Examples:
me#mypc:~$ ls *
ls: unrecognized option '--list-sessions'
Try 'ls --help' for more information.
me#mypc:~$ ls
...
Desktop
Downloads
...
(prints all directories)
me#mypc:~$ ls ./*
(prints all subdirectory subdirectories)
me#mypc:~$ ls .*
...
.vscode:
argv.json extensions
.wine:
dosdevices drive_c system.reg userdef.reg user.reg
...
(prints all subdirectories with their contents)
me#mypc:~$ du -sch *
du: unrecognized option '--list-sessions'
Try 'du --help' for more information.
me#mypc:~$ du -sch .*
du: cannot read directory './.dbus': Permission denied
du: cannot read directory './.pgadmin': Permission denied
66G .
du: cannot read directory '../postgres/.gnupg': Permission denied
64K ..
66G total
me#mypc:~$ grep "\-\-list-sessions" *
grep: unrecognized option '--list-sessions'
Usage: grep [OPTION]... PATTERN [FILE]...
Try 'grep --help' for more information.
And so on.
The list-sessions flag seems reminiscent of this tmux command:
me#mypc:~$ tmux list-sessions
error connecting to /tmp/tmux-1000/default (No such file or directory)
me#mypc:~$ whereis tmux
tmux: /usr/bin/tmux /usr/share/man/man1/tmux.1.gz
The list-sessions error in other commands persists with and without running tmux server.
Thanks for your help!
I'm guessing you have a file in your home directory named --list-sessions and the *, when expanded, is causing your command (eg, ls, du) to treat the file name as an option:
Consider ...
$ mkdir /tmp/ttt
$ cd /tmp/ttt
$ touch -- '--list-sessions'
$ ls -a
--list-sessions ./ ../
$ ls *
dir: unknown option -- list-sessions
Try 'dir --help' for more information.
$ ls -- * # disable further command line option processing
--list-sessions
$ du -k *
du: unknown option -- list-sessions
Try 'du --help' for more information.
$ du -k -- * # disable further command line option processing
0 --list-sessions
NOTE: The -- used in the above commands disables further command line option processing, eg, What does double dash mean?

Why I am getting 'cat: write error: Input/output error' when using cat on a 3-byte-file

I have a file of 3 bytes. I cannot use cat to see its content.
It happens on Ubuntu-18.04, and also on Windows' WSL - ubuntu (on different machines)
When using vi myfile I see only the letter q.
When using cat -A myfile I get M-AM-1$
When using hexdump myfile I get :
0000000 b1c1 000a
0000003
When using ls -la myfile I get -rw------- 1 iftah iftah 3 Mar 26 11:56 myfile
And my problem is with: cat myfile which returns:
cat: write error: Input/output error
Why? What is so special about this one?

What does # in `-rw-r--r--#` mean in the `ls -l` output?

I was examining output of ls -l in by bash completion folder on Mac OS X
$ ls -alrth /usr/local/etc/bash_completion.d/docker-machine*
-rw-r--r--# 1 abhimskywalker staff 1.4K Jun 13 19:04 /usr/local/etc/bash_completion.d/docker-machine-prompt.bash
-rw-r--r--# 1 abhimskywalker staff 1.5K Jun 13 19:36 /usr/local/etc/bash_completion.d/docker-machine-wrapper.bash
-rw-r--r--# 1 abhimskywalker staff 6.8K Jun 13 19:37 /usr/local/etc/bash_completion.d/docker-machine.bash
I could not understand what does this # mean in -rw-r--r--#?
It indicates that the file has extended attributes. You can use the xattr command-line utility to view and modify them:
xattr -l file # lists the names of all xattrs.
xattr -w attr_name attr_value file # sets xattr attr_name to attr_value.
xattr -d attr_name file # deletes xattr attr_name.
xattr -c file # deletes all xattrs.
xattr -h # prints help
You can also use ls -l# to see more information about those extended attributes.
From the osx ls man page:
The Long Format
If the file or directory has extended attributes, the permissions field printed by the -l option is followed by an # character. Otherwise, if the file or directory has extended security information, the permissions field printed by the -l option is followed by a + character.
And
-# Display extended attribute keys and sizes in long (-l) output.

cd command fails when directory is extracted from windows file

I have one text file in windows that contains lots of directories that I need to extract.
I tried to extract one directory and tried to cd to it in a shell script, but the cd command failed, with prompting cd: /VAR/GPIO/: No such file or directory.
I have confirmed that the directory exists in my local PC and the directory is correct (though it is relative). I have also searched a lot, seems some special windows characters exist in the extract file. I tried to see them with cat -A check and the result is ^[[m^[[K^[[m^[[KVAR/GPIO/$
I don't even know what the meaning of the m^ or [[K.
Could you please help me about this problem? I use Cygwin in Windows 7 64-bit.
Below is my related code for review:
templt_dir=$(cat temp | grep -m 1 "$templt_name" |head -1 | sed -n "s#$templt_name##p" | sed -n "s#\".*##p")
echo $templt_dir ###comment, it runs output: /VAR/GPIO/, that's correct!
cd $templt_dir ###comment, cd error prompts
cat temp | grep -m 1 "$templt_name" |head -1 | sed -n "s#$templt_name##p" | sed -n "s#\".*##p" > check ###comment, for problem checking
Below is the content of the check file:
$ cat -A check
^[[m^[[K^[[m^[[KVAR/GPIO/$
To confirm my directory is correct, below is the results of ls -l on /VAR:
$ ls VAR -l
total 80K
drwxrwx---+ 1 Administrators Domain Users 0 Jun 24 11:11 Analog/
drwxrwx---+ 1 Administrators Domain Users 0 Jun 24 11:37 Communication/
drwxrwx---+ 1 Administrators Domain Users 0 Jun 24 11:10 GPIO/
drwxrwx---+ 1 Administrators Domain Users 0 Jun 24 11:11 HumanInterface/
drwxrwx---+ 1 Administrators Domain Users 0 Jun 24 11:11 Memory/
drwxrwx---+ 1 Administrators Domain Users 0 Jun 24 11:11 PWM/
drwxrwx---+ 1 Administrators Domain Users 0 Jun 24 11:10 Security/
drwxrwx---+ 1 Administrators Domain Users 0 Jun 24 11:11 System/
drwxrwx---+ 1 Administrators Domain Users 0 Jun 25 16:25 Timers/
drwxrwx---+ 1 Administrators Domain Users 0 Jun 24 11:10 UniversalDevice/
The error message cd: /VAR/GPIO/: No such file or directory indicates that
the name stored in $templt_dir doesn’t exist.
This is actually due to the string containing non-printing ANSI escape
sequences.
You need to remove these characters from the string containing the directory.
I found the following sed substitution from this Unix and Linux answer
sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"
which you should include in your pipe command:
templt_dir=$(grep -m 1 "$templt_name" temp | sed -n "s#$templt_name##p; s#\".*##p" | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g")
Note: I concatenated your two sed substitutions into the one command and I removed the unnecessary cat. I also removed the redundant head -1 since grep -m 1 should only output one line. You can probably combine all the sed substitutions into one: sed -r "s#$templt_name##; s#\".*##; s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" (the -n sed option and p sed command can be left out if there’s only line being processed but I can’t test this without having the original file).
Other ways of using sed to strip ANSI escape sequences are listed at Remove color codes (special characters) with sed.
However, a better long-term fix would be to modify the process which creates the text file listing the directories to not include ANSI Escape codes in its output.

How to use shell command to check SVN check-out files and create links in an directory

Basically my question is how to use bash shell command to do following automatically, so I can track modified files easily.
list svn check-out files
create link files to above files in an directory called "change"
laptop$ svn status -q
M rcms/src/config/ta_show.c
M rcms/src/config/ta_config.c
laptop$ cd change
laptop$ link -s ../rcms/src/config/ta_show.c ta_show.c
laptop$ link -s ../rcms/src/config/ta_config.c ta_config.c
laptop$ ls
lrwxrwxrwx 1 root root 59 Nov 27 12:24 ta_show.c -> ../rcms/src/config/ta_show.c
lrwxrwxrwx 1 root root 59 Nov 27 12:24 ta_config.c -> ../rcms/src/config/ta_config.c
I am thinking to use shell command like below:
$ svn status -q | sed 's/M //' | xargs -I xxx ln -s ***BETWEEN REAL FILE AND BASE FILENAME***
you have two things need to be concerned:
the empty line between each file with svn status 'M'
extract the file name
the awk one liner could do it:
awk '$0{x=$2;gsub(".*/","",x);print "ln -s ../"$2" "x}'
so if you pipe your svn status output to the line above, it print the ln -s command lines for you.
if you want the ln -s lines to get executed, you could either pipe the output to sh (svn status|awk ...|sh) or replace the print with system
at the end i would like to show the output below as an exmple:
kent$ echo "M rcms/src/config/ta_show.c
M rcms/src/config/ta_config.c"|awk '$0{x=$2;gsub(".*/","",x);print "ln -s .."$2" "x}'
ln -s ../rcms/src/config/ta_show.c ta_show.c
ln -s ../rcms/src/config/ta_config.c ta_config.c

Resources