touch: cannot touch file: No such file or directory
Solution 1
You do not have the path that holds the file:
/opt/tsrm/compliance/cme/log/
That's where the error come from.
Solution 2
Sounds like you misspelled the path. For example, this folder /stuff/more_stuff
does not exist. This gives me the result:
user@linux:~ $ touch /stuff/more_stuff/stuff.file
touch: cannot touch `/stuff/more_stuff/stuff.file': No such file or directory
Both /stuff
and /stuff/more_stuff
need to exist in order for touch
to work.
Solution 3
As silly as this reply sounds, other than missing directory, there could be string delimiter surrounding the value in $LOGFILE
Working:
LOGFILE=/stuff/more_stuff/stuff.file
touch $LOGFILE
Not Working:
LOGFILE="/stuff/more_stuff/stuff.file"
touch $LOGFILE
Some Linux distro have the quirk above, so be careful ;)
Solution 4
Yes there might be chances of miss typo or directory not exists .
LOGFILE="/opt/tsrm/compliance/cme/log/20121207.log"
LOG_DIR=`dirname $LOGFILE`
[ ! -d $LOG_DIR ] && mkdir -p $LOG_DIR
touch $LOGFILE
Related videos on Youtube
Swagatika
Updated on September 18, 2022Comments
-
Swagatika almost 2 years
I am getting the error:
touch: cannot touch `/opt/tsrm/compliance/cme/log/20121207.log`: No such file or directory
on the touch command:
touch $LOGFILE
I also checked the link: touch: cannot touch `foo': No such file or directory, But I didn't understand the answer.
Note: I was also getting
mkdir: cannot create directory
; I fixed this by adding the-p
option.Could this be something with the version of Linux I am working in?
-
S edwards over 6 yearsexplanation pretty simple, if the folder your were in was destroy when you invoke touch then it fails.
-
Jason Swett over 3 yearsAh yes, the "MC Hammer error"
-
-
Basile Starynkevitch over 6 yearsI would call that a directory not a path
-
Aaron Franke over 6 yearsIn my case I am trying to use
touch /etc/resolv.conf
and it saystouch: cannot touch '/etc/resolv.conf': No such file or directory
./etc
definitely does exist. -
Admin about 2 years
mkdir -p /opt/tsrm/compliance/cme/log