Bash - Path

Bash Liste Des Attaques Ovh

About

This article is about the path management in bash. ie /dir/childDir/fileName.

See also: Bash - pathname expansion (Filename expansion)

How to

get the name of the file

basename $path

from relative to absolute

MYPATH="../whatever"
MYPATH=$(readlink -f ${MYPATH})

is Absolute

if [[ "$PATH" = /* ]]; then
echo "absolute path";
else 
echo "relative path";
fi
case $PATH in
  /*) echo "absolute path" ;;
  *) echo "relative path" ;;
esac

from Windows to Linux and vice-versa

cygpath -u path # from Windows to Linux
cygpath path # from Linux to Windows

File or Directory

if [[ -d ${ARG} ]]; then
    echo "${ARG} is a directory";
elif [[ -f ${ARG} ]]; then
    echo "${ARG} is a file";
else
    echo "${ARG} is not a path";
    exit 1;
fi





Discover More
Bash Liste Des Attaques Ovh
Bash - Conditional Expression

A predicate or boolean expression is known in Bash as a Conditional Expression. It is a command that returns an exit status of 0 or 1. The conditional expression is part of the compound expression. ...
Undraw File Manager Re Ms29
File System - Path

in a file system. A file is identified by its path through the file system. A file path is a hierarchical URI where: scheme is the scheme that represents the file system such as: file (default)...



Share this page:
Follow us:
Task Runner