basename

linux basename dirname

混江龙づ霸主 提交于 2021-01-30 06:51:11
basename #只获取文件名 有两个参数 -s 和 -a, -s 要去掉的后缀 #表示指定要去掉的后缀 -a 表示多个名称 dirname #只获取文件的文件夹名 来源: oschina 链接: https://my.oschina.net/u/2308739/blog/545804

Get name of current script in Python

99封情书 提交于 2019-12-17 05:23:21
问题 I'm trying to get the name of the Python script that is currently running. I have a script called foo.py and I'd like to do something like this in order to get the script name: print Scriptname 回答1: Use __file__ . If you want to omit the directory part (which might be present), you can use os.path.basename(__file__) . 回答2: import sys print sys.argv[0] This will print foo.py for python foo.py , dir/foo.py for python dir/foo.py , etc. It's the first argument to python . (Note that after py2exe

Get name of current script in Python

放肆的年华 提交于 2019-12-17 05:22:12
问题 I'm trying to get the name of the Python script that is currently running. I have a script called foo.py and I'd like to do something like this in order to get the script name: print Scriptname 回答1: Use __file__ . If you want to omit the directory part (which might be present), you can use os.path.basename(__file__) . 回答2: import sys print sys.argv[0] This will print foo.py for python foo.py , dir/foo.py for python dir/foo.py , etc. It's the first argument to python . (Note that after py2exe

Linux dirname 和basename命令

99封情书 提交于 2019-12-03 11:33:33
一、dirname指令 1、功能:从给定的包含绝对路径的文件名中去除文件名(非目录的部分),然后返回剩下的路径(目录的部分) 2、用法:dirname filename 例如下面几个例子 (1)# dirname /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts (2)# dirname /boot/grub/grub.conf /boot/grub (3)# dirname /etc/inittab /etc (4)# echo `pwd` && dirname modprobe.conf /etc . (5)#echo `pwd` && dirname sysconfig/network-scripts/ /etc sysconfig Linux系统管理 二、basename指令 1、功能:从给定的包含绝对路径的文件名中去除左边目录部分或者同时去除某个后缀的内容(目录的部分),然后返回剩下的部分(非目录的部分) 2、用法:basename filename [suffix] 例如下面几个例子 (1)#basename /etc/sysconfig/network-scripts/ifcfg-eth0 ifcfg-eth0 (2)#basename /boot/grub/grub