OS2 World Community Forum

OS/2, eCS & ArcaOS - Technical => Utilities => Topic started by: Rick Smith on November 26, 2023, 10:11:17 pm

Title: touch?
Post by: Rick Smith on November 26, 2023, 10:11:17 pm
Greetings,

I am wondering if I can (from CLI) create a file?  In linux I would just say touch newfile, then I could nano and edit it.  On Arca I use file commander but I do not see a way to create a file (I could have missed it), touch does exist Ive noticed in Arca but does not act in how I would expect.  So basically I want to be able to create a new file in a directory using the CLI.

Regards,

Rick
Title: Re: touch?
Post by: Dariusz Piatkowski on November 26, 2023, 11:35:08 pm
Hi Rick,

Code: [Select]
[Y:\tmp]copy con: file2
test
^Z
        1 file(s) copied.

...gets you the following:

Quote
[Y:\tmp]dir

The volume label in drive Y is RAMDISK.
The Volume Serial Number is 5777:6CCF.
Directory of Y:\tmp

11-26-23  5:32p             6      0 a---  file2

Is that what you are looking to do?

BTW: I haven't tried any other combos, as in: "copy con: filename" but w/o actual input...
Title: Re: touch?
Post by: Tom on November 26, 2023, 11:41:08 pm
So basically I want to be able to create a new file in a directory using the CLI.

Maybe I misunderstand you, but I would expect the following to work:

cd <directory>
e (or tedit or epm or whichever editor)
start typing
use Save as and give it a filename (some editors might even allow you to start the editor with a desired file name which will be created if it doesn't exist already)

Another possibility:

cd <directory>
copy con: <filename>
start typing
Ctrl+Z


Title: Re: touch?
Post by: Lars on November 26, 2023, 11:44:30 pm
echo. >newfile.txt
Title: Re: touch?
Post by: Dave Yeo on November 27, 2023, 12:09:27 am
touch new.file creates a new file here and it's how I usually create one with file commander.
Code: [Select]
Directory of H:\tmp\test

11-26-23  3:06p         <DIR>      0 ----  .
11-26-23  3:06p         <DIR>      0 ----  ..
        2 file(s)           0 bytes used
                    4,755,963 K bytes free

[H:\tmp\test]touch new.file

[H:\tmp\test]dir

Volume in drive H has no label.
The Volume Serial Number is 4558:45C3.
Directory of H:\tmp\test

11-26-23  3:07p         <DIR>      0 ----  .
11-26-23  3:06p         <DIR>      0 ----  ..
11-26-23  3:07p             0    124 a---  new.file
        3 file(s)           0 bytes used
                    4,755,963 K bytes free

[H:\tmp\test]touch --version
touch (GNU coreutils) 8.31

Title: Re: touch?
Post by: Dariusz Piatkowski on November 27, 2023, 12:27:54 am
Rick!

...In linux I would just say touch newfile, then I could nano and edit it...touch does exist Ive noticed in Arca but does not act in how I would expect...

Lars' trick is by far the quickest one I think!!! (kudos to you sir 8))

...ok, but having said that, what's the issue you're running into with 'touch'? I just tried it here, no problems...
Title: Re: touch?
Post by: Rick Smith on November 27, 2023, 03:10:49 am
touch new.file creates a new file here and it's how I usually create one with file commander.
Code: [Select]
Directory of H:\tmp\test

11-26-23  3:06p         <DIR>      0 ----  .
11-26-23  3:06p         <DIR>      0 ----  ..
        2 file(s)           0 bytes used
                    4,755,963 K bytes free

[H:\tmp\test]touch new.file

[H:\tmp\test]dir

Volume in drive H has no label.
The Volume Serial Number is 4558:45C3.
Directory of H:\tmp\test

11-26-23  3:07p         <DIR>      0 ----  .
11-26-23  3:06p         <DIR>      0 ----  ..
11-26-23  3:07p             0    124 a---  new.file
        3 file(s)           0 bytes used
                    4,755,963 K bytes free

[H:\tmp\test]touch --version
touch (GNU coreutils) 8.31

touch new.txt gets me

SYS0002: The system cannot find the file specified. "C:\temp\new.txt"

Regards

Rick
Title: Re: touch?
Post by: Dave Yeo on November 27, 2023, 04:15:13 am
That's weird, what does touch --version report? Perhaps you have another touch in your PATH? That looks like the wrong error for a coreutils touch.
Title: Re: touch?
Post by: Rick Smith on November 27, 2023, 07:34:18 am
That's weird, what does touch --version report? Perhaps you have another touch in your PATH? That looks like the wrong error for a coreutils touch.

I get an error when I do touch --version.. Is this installed by default or do I have to install something with yum?

Rick
Title: Re: touch?
Post by: Dave Yeo on November 27, 2023, 07:47:15 am
It's part of the coreutils package. I thought it was installed by default, but perhaps not. Possible you have a broken install of it, which can be fixed by reinstalling.
Look in your @unixroot\usr\bin directory to see if it there.
Title: Re: touch?
Post by: Rick Smith on November 27, 2023, 03:03:30 pm
It's part of the coreutils package. I thought it was installed by default, but perhaps not. Possible you have a broken install of it, which can be fixed by reinstalling.
Look in your @unixroot\usr\bin directory to see if it there.

I tried through ANPM didnt seem to work.  Is there a way to uninstall and start over?

Rick
Title: Re: touch?
Post by: Neil Waldhauer on November 27, 2023, 03:23:41 pm
if you have touch, perhaps you also have which? What is the result of

Code: [Select]
which touch
?
Title: Re: touch?
Post by: Dave Yeo on November 27, 2023, 04:09:41 pm
Try "yum reinstall coreutils" on the command line. Report the output.
Title: Re: touch?
Post by: Gregg Young on November 27, 2023, 09:48:34 pm
Hi

You must be using 4OS2. It has an internal touch command which returns the error you reported. To use the touch.exe from the coreutils use the command touch.exe filename. If you are interested in having the touch command in 4os2 behave like touch.exe put in a feature request at http://trac.netlabs.org/4os2 and I will look at it. Thanks

Gregg
Title: Re: touch?
Post by: Alfredo Fernández Díaz on November 28, 2023, 12:06:49 am
Hi,

[...] In linux I would just say touch newfile, then I could nano and edit it.  On Arca I use file commander but I do not see a way to create a file (I could have missed it) [...]

I would guess FC does not have an obvious, explicit way to create new files because most of these will be application-specific, so there's basically no point in that. However, your saying "nano and edit it" suggests me that you are trying to create a plain text file, and FC has a built-in text editor indeed. The easiest way you can create such a new file with FC is using Shift+F4. This will prompt you for a filename; type the name of a non-existing file, and the editor will ask you if a new file with that name should be created. Answer Yes, optionally write some text, and exit the editor.

Hope this helps,
Title: Re: touch?
Post by: Andi B. on November 28, 2023, 02:14:20 pm
Quote
In linux I would just say touch newfile, then I could nano and edit it.
With OS/2 I would simlply say 'e filename' or on my systems where I'm used to med.exe 'med filename' or 'vs filename' or 'edit filename'. This opens the editor with the file filename even without the touch before. Guess nano would do the same without touch, does it?

You may see there are a lot of ways to do what you want. A simple 'dir >filename' creates a file too beside the other options already mentioned. But I know sometimes it's handy to have a touch.exe especially when porting software from nix. For that I often use OpenWatcoms wtouch.exe.