What's the bash equivalent to os.path.normpath
? Specifically I'm interested in removing the leading ./
given when executing find
.
matt@stanley:~/src/libtelnet-0.20/test$ find . ./Makefile ./Makefile.in ./Makefile.am ...
os.path. normpath (path) Normalize a pathname by collapsing redundant separators and up-level references so that A//B , A/B/ , A/./B and A/foo/../B all become A/B . This string manipulation may change the meaning of a path that contains symbolic links. On Windows, it converts forward slashes to backward slashes.
In this case, first, we need the current script's path, and from it, we use dirname to get the directory path of the script file. Once we have that, we cd into the folder and print the working directory. To get the full or absolute path, we attach the basename of the script file to the directory path or $DIR_PATH.
In order to obtain the Current Working Directory in Python, use the os. getcwd() method. This function of the Python OS module returns the string containing the absolute path to the current working directory.
path. dirname() method in Python is used to get the directory name from the specified path.
Well, for that, you can simply pipe the output through sed
, you don't have to normalise the entire path:
your_command_goes_here | sed 's?^\./??'
That will get rid of all ./
sequences at the start of a line.
The following transcript shows this in action:
pax$ find -name 'qq*sh'
./qq.ksh
./qq.sh
./qq.zsh
./qq2.sh
./qq2.zsh
./qqq/qq.sh
pax$ find -name 'qq*sh' | sed 's?^./??'
qq.ksh
qq.sh
qq.zsh
qq2.sh
qq2.zsh
qqq/qq.sh
As you can see, I have a fairly intuitive naming standard for my temporary shell scripts :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With