Tag Info

New answers tagged

3

Can you do this only using POSIX sed? Yes: sed -e 's/.^H//g' < data where ^H is just a literal backspace character. POSIX sed uses POSIX basic regular expressions, which are defined over bytes - printing characters or not, they don't care, so this behaves the same as if ^H were a letter. There are no extensions involved here. Note that all you really ...


0

I will contribute my own answer. An option, in the context of interactive shell (the question focuses on this context), could be automatically maintaining a link à la /proc/$PID/cwd, using the automation opportunity Bash provides: PROMPT_COMMAND="ln -sfT \$(pwd) ~/$LINK_NAME" The f option is required, as the link will be frequently overridden. The T ...


4

POSIX doesn't offer much in terms of getting information about unrelated processes. There's only ps, really, and it doesn't give any information about the current directory. The C-level APIs aren't any better (in fact most of the information retrieved by ps can only be retrieved by parsing its output¹). Funnily enough POSIX does offer a portable way to go ...


7

I have a solution that uses lsof. It is not installed on BSD by default so if anyone want to use it on BSD, it is required to install it. Make a shell script: #!/bin/sh lsof -p $1 | grep cwd | awk '{print $9}' Copy it to a directory in your path. It prints the working directory of PID given in the first argument, I.E. $ script 1987 /home/enedil


6

The standard (POSIX) syntax is: find /path/to/parent -type f -exec grep 'XXX' /dev/null {} + (the /dev/null is to make sure grep always prints a file name). That will work on all POSIX systems including Solaris. The only known post-90s systems where that's known not to work is old (very old now) GNU systems. GNU initially introduced a -print0 predicate ...



Top 50 recent answers are included