unix shell - ls -d $PWD
NickName:jay Ask DateTime:2020-07-15T05:20:44

unix shell - ls -d $PWD

I would like to make an alias called Ls which prints out the current directory and file name when I try to list a specific file

unix> ls a.txt
unix> a.txt -> print out

I want it to print out the directory name too:

unix> /hier1/hier2/hier3/a.txt

When I do 'ls -d $PWD/a.txt'
it prints out

unix> /hier1/hier2/hier3/a.txt

When I make an alias of the above

alias Ls 'ls -d $PWD', it prints out the as below with a space.

unix> Ls a.txt
unix> /hier1/hier2/hier3 a.txt 

How do I get the below print without the space and with a slash as below:

unix> Ls a.txt
unix> /hier1/hier2/hier3/a.txt -> THIS IS WHAT I WANT

Copyright Notice:Content Author:「jay」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/62904190/unix-shell-ls-d-pwd

Answers
nav610 2020-07-14T23:30:25

You are better off making a function. Go into your ~/.bashrc file and create the function as such with the export command:\nfunction Ls(){\n p="$PWD" \n out="${p}/${1}"\n echo $out\n}\n\nThen save and quit :wq, and type in:\nsource ~/.bashrc \n\nAnd the command should be ready to go\nIf you are using zsh, then add:\nif [ -f ~/.bashrc ]; then\n . ~/.bashrc\nfi\n\nto the ~/.zshrc file.",


More about “unix shell - ls -d $PWD” related questions

unix shell - ls -d $PWD

I would like to make an alias called Ls which prints out the current directory and file name when I try to list a specific file unix> ls a.txt unix> a.txt -> print out I want it to print ...

Show Detail

shell built in pwd versus /bin/pwd

I would like to know the code implementation of built-in pwd and /bin/pwd especially when the directory path is a symbolic link. Example: hita@hita-laptop:/home$ ls -l lrwxrwxrwx 1 root root 3...

Show Detail

execv works for "/bin/ls" but not "pwd"

I am new to C programming language on Unix and trying to build a shell-like C program. However the program gives error if I try to change the function according to my own choices. For example as it...

Show Detail

How to do this recursivly: ls -lrt -d -1 $PWD/{*,.*}

In another post located here: List file using ls command in Linux with full path The answer to the question was given as this: ls -lrt -d -1 $PWD/{*,.*} But this does not work recursively even...

Show Detail

Shorthand for specifying path as pwd in Unix?

I'd like to know if there's a built in shortcut or a way to create an alias for the path in a command when the path is the pwd. For example, lets say my pwd is ~/Desktop/Unix_Folder/Unix_Sub_Folder...

Show Detail

basic shell - ls command after chdir()

I'm trying to create a basic shell, but I have a problem. The shell changes directory just fine, and outputs an error if the user inputs an invalid directory. The shell also has an internal comman...

Show Detail

Enter to unix shell with specific working directory

I want to accomplish this: [zsh]$ pwd /home/user *[zsh]$ bash # enter to a bash shell at the same time as `cd ~/Desktop`. [bash]$ pwd /home/user/Desktop [bash]$ exit [zsh]$ pwd **/home/user I would

Show Detail

Hadoop ls vs unix ls

This may be a silly question but I am very new to Hadoop. I have a unix server path as /tmp/abc where I am writing a file test.txt from Informatica BDM using hadoop connection. A part of Hadoop clu...

Show Detail

Using Unix find `pwd`

I am trying to use the Unix find command in Python and can't get to input pwd, `pwd` did not work either. import commands import os f = raw_input('Enter name of the file: ') fh = open(f, 'r') pr.

Show Detail

UNIX commands from R via shell function

I need to issue unix commands from an R session. I'm on Windows R2 2012 server using RStudio 1.1.383 and R 3.4.3. The shell() function looks to be the right one for me but when I specify the path...

Show Detail