15

This question already has an answer here:

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?

marked as duplicate by Kiwy, Christopher, Timothy Martin, Hauke Laging, Jesse_b Apr 5 '18 at 19:23

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • explanation pretty simple, if the folder your were in was destroy when you invoke touch then it fails. – Kiwy Apr 5 '18 at 8:01
16

You do not have the path that holds the file:

/opt/tsrm/compliance/cme/log/

That's where the error come from.

6

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.

  • In my case I am trying to use touch /etc/resolv.conf and it says touch: cannot touch '/etc/resolv.conf': No such file or directory. /etc definitely does exist. – Aaron Franke Mar 9 '18 at 1:24
  • Have you checked if resolv.conf is a symlink to a file that doesn't exist? – Kotte Mar 9 '18 at 10:34
3

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
0

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 ;)

Not the answer you're looking for? Browse other questions tagged or ask your own question.