LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-11-2020, 05:01 PM   #1
justin12
LQ Newbie
 
Registered: Oct 2017
Posts: 3

Rep: Reputation: Disabled
touch command


is there anyway to make this one command

touch ../logs/black.c ../logs/red.pdf ../logs/blue.txt
 
Old 10-11-2020, 05:05 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206
Have you tried what you typed? That is one command.

Or perhaps you mean something else. Please explain what you mean by "one command".

Last edited by astrogeek; 10-11-2020 at 05:07 PM.
 
1 members found this post helpful.
Old 10-11-2020, 05:15 PM   #3
justin12
LQ Newbie
 
Registered: Oct 2017
Posts: 3

Original Poster
Rep: Reputation: Disabled
i have typed this out and it works fine i was just wondering how come touch ../logs/black.c red.pdf blue.txt won't work
 
Old 10-11-2020, 05:28 PM   #4
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931
Because that second way you typed it means those last two files are in the same directory as you are typing from.
 
Old 10-11-2020, 05:34 PM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,770

Rep: Reputation: 5933Reputation: 5933Reputation: 5933Reputation: 5933Reputation: 5933Reputation: 5933Reputation: 5933Reputation: 5933Reputation: 5933Reputation: 5933Reputation: 5933
To expand on the above.

As per your other thread...
https://www.linuxquestions.org/quest...pt-4175683478/

Could this be homework?

Without knowing what you are trying to accomplish or looking at your script it is difficult to say why it will not work. Do you understand what ../ means, file/directory permissions and current working directory?
 
Old 10-11-2020, 05:47 PM   #6
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206
Quote:
Originally Posted by justin12 View Post
i have typed this out and it works fine i was just wondering how come touch ../logs/black.c red.pdf blue.txt won't work
That will "work", but red.pdf and blue.txt will be in your current directory, while black.c will be in the directory ../logs/. The difference is the path specification that precedes the filenames, none (same as ./) in the case of red.pdf and blue.txt.

You should read up on file paths and how the shell interprets things like ../ (parent directory), ./ (present directory, same as no path) and /.. (absolute path from filesystem root).

Follow the link in rtmistler's sig to his Bash Blog for some helpful tips. Also, explore wolledge.org, one of the best bash shell scripting guides around!

Here is an alternate syntax which will put all files in the same directory, see why that works>:

Code:
touch ../logs/{black.c,red.pdf,blue.txt}

Last edited by astrogeek; 10-11-2020 at 05:49 PM.
 
1 members found this post helpful.
Old 10-11-2020, 05:52 PM   #7
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,819

Rep: Reputation: 1212Reputation: 1212Reputation: 1212Reputation: 1212Reputation: 1212Reputation: 1212Reputation: 1212Reputation: 1212Reputation: 1212
In bash you can use brace expansion
Code:
touch ../logs/{black.c,red.pdf,blue.txt}
In all shells you can change directory in a subshell
Code:
(cd ../logs && touch black.c red.pdf blue.txt)
 
  


Reply

Tags
command



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] group permissions: touch: cannot touch `filename': Permission denied bartonski Linux - General 2 11-27-2008 09:23 AM
One Touch backup versus One Touch II q6supvr Linux - Software 4 12-16-2007 08:28 PM
LXer: Touch Drivers: Elo Offers New Touch Drivers For Linux And Mac OS LXer Syndicated Linux News 0 08-29-2006 12:54 PM
touch: cannot touch `/var/log/mysqld.log': Permission denied massoo Linux - General 1 08-01-2006 01:56 AM
Error - can't touch touch: /var/lock - filesystem problem? xanas3712 Linux - Newbie 0 05-10-2004 05:26 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration