C L
C L

Reputation: 1

Bash mkdir with a datetime stamp

To make a directory including some information, the server name, and a date, I am using:

mkdir ~/abcd-$(home -f)-$(date +"Y%m%d%H%M%S")

trying to get ~/abcd-servername-20130418210802

I get a ? on the end. If I use a variable and a substring (ie, {STR1:0:29}) function, I get one or more ?. Just an annoyance really but would like to know why.

Upvotes: 0

Views: 3910

Answers (2)

gc-p
gc-p

Reputation: 21

Tested on openSUSE 42.3:

NEWCOMPUTER=`uname -n`
THEDATE=`date +%Y%m%d%H%M%S`
mkdir ~/Desktop/computers/$NEWCOMPUTER-$THEDATE

Upvotes: 2

GoZoner
GoZoner

Reputation: 70145

You have 'non-graphic' characters in your directory name. From the man page for ls:

-q Force printing of non-graphic characters in file names as the character `?'; this is the default when output is to a terminal.

Additionally it looks like your directory has some problems as you stated it. Your Y should be %Y and your home should be hostname (but you haven't stated your operating system).

Upvotes: 1

Related Questions