You mean like this, just prepending the current directory to each filename?
ls -l | awk -v PWD=$PWD '{printf("%s %s/%s\n", $5, PWD, $9); }'
(the -v
just imports the $PWD
shell variable into the awk script).
Or something else?
OK, apparently what you want is
$ cd /some/path/to/somewhere
$ <insert command here>
somewhere/file1 size1
somewhere/file2 size2
...
Is that correct?
If so, the change you need is this:
ls -l | awk -v PWD=$(basename $PWD) '{printf("%s/%s %s\n", PWD, $9, $5); }'
If you have an older shell, the $()
may not work, in which case try:
ls -l | awk -v PWD=`basename $PWD` '{printf("%s/%s %s\n", PWD, $9, $5); }'
instead. I don't have immediate access to any shell that doesn't support $()
, but I can't think where else your Illegal variable name
error would come from, when this works for me.
If it still doesn't work, please describe your platform, shell, version of awk etc. in your question - the comment thread is getting pretty long and I'm running out of guesses :-)
See if your ls has the options:
-H, --dereference-command-line
follow symbolic links listed on the command line
--dereference-command-line-symlink-to-dir
follow each command line symbolic link that points to a directory
If those don't help, you can make your macro work without messing up cd -
by doing:
(cd /rmn ; ls -l)
which runs in a subshell.
Best Answer
Selecting columns to print with awk
One method would be to parse the output of
ls
.Example
By the way, you can clean up the output using
column
.Selecting columns to remove with awk
If you'd rather remove the other columns, while keeping others you can use this
awk
method to blank out the undesirable columns.Example
Eventual solution
The OP came up with this chain of commands, using a mix of the examples from above.