Unix Command to get file path without basename Unix Command to get file path without basename shell shell

Unix Command to get file path without basename


Try

$ dirname /home/files/myfiles/good.txt


Should do the job:

echo /home/files/myfiles/good.txt | sed s,/*[^/]*$,,


Without spawning another process, you can use parameter expansion:

file=/home/files/myfiles/good.txtecho "${file%/*}"/home/files/myfiles