I'm newbie for a shell script. So I need to cut the directory name from my $file. e.g.
fullpath='/var/log/apache/access.log
Now I need to cutting "apache" to output. How can I do.
Thank in advance.
I'm newbie for a shell script. So I need to cut the directory name from my $file. e.g.
fullpath='/var/log/apache/access.log
Now I need to cutting "apache" to output. How can I do.
Thank in advance.
The combination of basename
and dirname
will give you the parent directory of the file you provided in $fullpath
For example:
FULLPATH=/var/log/apache/access.log; basename $(dirname $FULLPATH)
will print "apache"
vim Filename
fullpath='/var/log/apache/access.log
then save and exit
cut -d'/' -f4 Filename