I am not well-versed with Unix commands. While practicing I got following situation.
My current working directory is empty and firstly, I created a file “test*” then I can see the file got created:
Then I removed “test*” file and created two new files named “test1*” and “ test2*”:
But again when I tried to create “test*” file this file is not created:
Query: Why it is not creating “test*” file if “test1*” and “ test2*” files already exists?
Many thanks in advance.
Regards,
Manish
Last edited by Franklin52; 09-30-2012 at 05:54 PM..
Reason: Please use code tags
This probably has to do with you use of *. The file name test* refers to any file that starts with test and has anything after it, like.
test1
test2
test.txt
test.whatever
...
you should probably not use the * to create a single file. It really doesn't make any sense since its purpose is to refer to anything that starts with whatever is before the *, or anything that has a specific ending.
You can use * to do things like "delete all files with the extension .txt"
rm *.txt
or copy everything that starts with 44 to a new directory
You need to know that whenever you type in anything on the command line, your shell interprets the command line first and then the corresponding commands are called.
When your current directory is empty and you issue the command touch test*:
The * character is special to the shell; it's a wildcard which tries to match 0 or more occurrences of any character. So, test* tries to match file-names (in the current directory) starting with test followed by 0 or more occurrences of any character. Since the shell cannot find any such file-names, the pattern is not expanded and the command line remains touch test* and thus, touch creates the file test*.
rm *
Now, * matches test* and the command line becomes rm test* and the file is removed.
touch test1* test2*
No file-names match the 2 patterns and the command-line remains as touch test1* test2* and the 2 files are created.
touch test*
Now, test* matches the 2 files created by 3. So, the command-line becomes touch test1* test2* and the modification and access times of these 2 files are changed by touch.
If you need to create a file name test*, you'll have the escape interpretation of * by the shell by using one of the following ways (or their variations):
touch test\*,or
touch test'*'
It is dangerous to include * in file-names.
Last edited by elixir_sinari; 09-29-2012 at 11:19 AM..
This User Gave Thanks to elixir_sinari For This Post:
Thank you all for the explanations.
I understand that it is dangerous to include * in file-names but only trying to understand some basic working knowledge (behind the scene)
I got to know somewhere that:
rm *\* --> is the script that removes all files that end with an asterisk in the name.
rm *\** --> is the script that removes all files that contain an asterisk in the name.
example:
> touch test test1* test2* make*a*chance create*all
>
> ls -l
total 0
-rw-rw-rw- 1 kimxk users 0 Oct 01 11:32 create*all
-rw-rw-rw- 1 kimxk users 0 Oct 01 11:32 make*a*chance
-rw-rw-rw- 1 kimxk users 0 Oct 01 11:32 test
-rw-rw-rw- 1 kimxk users 0 Oct 01 11:32 test1*
-rw-rw-rw- 1 kimxk users 0 Oct 01 11:32 test2*
>
===================== rm *\* =================================
> rm *\*
>
> ls -l
total 0
-rw-rw-rw- 1 kimxk users 0 Oct 01 11:32 create*all
-rw-rw-rw- 1 kimxk users 0 Oct 01 11:32 make*a*chance
-rw-rw-rw- 1 kimxk users 0 Oct 01 11:32 test
>
=====================================================
> rm *\**
>
> ls -l
total 0
-rw-rw-rw- 1 kimxk users 0 Oct 01 11:37 test
>
======================================================
I understand that in both the commands 1st '*' is meant to read and remove all the files current directory but not able to understand how the 2nd & 3rd '*' impacting this.
I like more to talk about file generation.
* in the filename is only char *.
*\* or *'*' start with 0-n chars (not begin .) and last char is *
=> * , 1*1*1*, **, ***, ****, all match.
Sameway dos a'like *.* result is
=> a.b.c.d match : start with 0-n some chars, then is dot and after that is 0-n chars.
* include all chars including *.
Use echo to test
Why echo is good ?
Because command line is parsed by shell, including file name generation and the result has given for command. So echo print out all arguments = what shell has done for the command line before give it to the command.
Hello.
System : opensuse leap 42.3
I have a bash script that build a text file.
I would like the last command doing :
print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt
where :
print_cmd ::= some printing... (1 Reply)
How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address
and column 3 contains “cc” e-mail address to include with same email.
Sample input file, email.txt
Below is an sample code where... (2 Replies)
I am testing shc to see if it would help with my need.
Im at a point where Im trying to compile and test the "test.ksh" file that comes in the tar ball :
shc-3.8.9> shc -v -r -f test.ksh
shc shll=ksh
shc =-c
shc =exec '%s' "$@"
shc =
shc opts=
shc: cc test.ksh.x.c -o test.ksh.x... (7 Replies)
Please can you help me understand the significance of providing arguments under sh -s in
> ssh -qtt ${user}@${host} "sh -s "${version}"" < test.sh (4 Replies)
Hi all.
I have a .txt file that I need to sort it
My file is like:
1- 88 chain0 MASTER (FF-TE) FFFF 1962510 /TCK T FD2TQHVTT1 /jtagc/jtag_instreg/updateinstr_reg_1 dff1 (TI,SO)
2- ... (10 Replies)
Hi,
I have line in input file as below:
3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL
My expected output for line in the file must be :
"1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL"
Can someone... (7 Replies)
Hello, I'm trying to build a (bff) package from an already installed program (clam antivirus) using mkinstallp. However, mkinstallp fails with "no such file: ./usr/lpp/<package name>/inst_root"
I'm not sure why all files get created ok except for these particular ones. Any help would be... (2 Replies)
Hi,
I've modified the syslogd source to include a thread that will keep track of a timer(or a timer thread). My intention is to check the file size of /var/log/messages in every one minute & if the size is more than 128KB, do a echo " " > /var/log/messages, so that the file size will be set... (7 Replies)
Hi Friends,
Can any of you explain me about the below line of code?
mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`
Im not able to understand, what exactly it is doing :confused:
Any help would be useful for me.
Lokesha (4 Replies)