Unix wildcard character question


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Unix wildcard character question
# 1  
Old 02-10-2009
Unix wildcard character question

1. Is . wildcard? , the documented wildcard are "*", "?", and "[]"

. seems mean everything, the follwing cmd will copy everything

Code:
 
cp -r /tmp/test1/.  /tmp/test2/

However it doesn't work for rm, why?

Code:
$ ls -a
.    ..   .a   .aa  aa   t2
$ rm -rf .
$ ls -a
.    ..   .a   .aa  aa   t2

2. How to delete everthing in current dir with single cmd?
if the dir has hidden files. i have run rm -rf * ;rm -rf .* to delete everything
# 2  
Old 02-10-2009
1. . is not a wildcard

ls -la . = ls -la `pwd`

2.

find . -type f -exec rm {} \; = find `pwd` -type f -exec rm {} \;

y delete all files whith this command
# 3  
Old 02-10-2009
Quote:
Originally Posted by taran
1. . is not a wildcard

ls -la . = ls -la `pwd`
ok, this explains "cp -r /tmp/test1/." can copy everything

Quote:
Originally Posted by taran
2.

find . -type f -exec rm {} \; = find `pwd` -type f -exec rm {} \;

y delete all files whith this command
this command is still complex, even more typing than (rm -rf .*;rm -rf *)

I am looking for a single cmd "rm -rf" followed by a wildcard expression, is it possible?
# 4  
Old 02-10-2009
You NEVER should do something like rm -rf *, it's too risky. If you want to delete all contents of a directory, delete that and recreate it.
Quote:
Originally Posted by honglus
Quote:
Originally Posted by taran
find . -type f -exec rm {} \; = find `pwd` -type f -exec rm {} \;
this command is still complex, even more typing than (rm -rf .*;rm -rf *)
Maybe, but it has the advantage of passing additional parameters for filtering, such as name, size, time, and owner.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script question in special character

when I execute the unix commands its works normally in the 1st part. When I the tried the same in shell scripting the directory is not displayed in 2nd part example. please let me know what needs to be done. Unix : client=~zsvdbs echo $client /shome/zsvhome/zsvdbs Using... (3 Replies)
Discussion started by: keerthi2016
3 Replies

2. Shell Programming and Scripting

WildCard character - not able to understand

Hello, I have one script which looks as given below , . ${0%/*}/init && init_job || exit 1 what I understood is , 1. above syntax has three commands, two on left of || and one on right of ||. 2. ${0%/*} would generate some path. Question. A. What is the meaning of ${0%/*} ,... (2 Replies)
Discussion started by: ParthThakkar
2 Replies

3. Programming

Question how to replace last character string

Hi, Could someone help me how to replace last character string. For example $>export T1=abcde $>export T2=xyz my question is how to get result abcdxyz? Many Thanks (2 Replies)
Discussion started by: nicklau81
2 Replies

4. UNIX for Dummies Questions & Answers

how to search and list file with wildcard character

hi, I want to search all files in the current working direcotry and to print in comma (,) seperated output. But I have two patterns to search for. Files will be in ABC20100508.DAT format. Search should happen on the format (ABC????????.DAT) along with date(20100508). I can do a ls... (2 Replies)
Discussion started by: anandapani
2 Replies

5. Shell Programming and Scripting

sed 'iteration character' question

I'm processing ( trying to anyway ) a file of pipe delimited database output. Sample record: 365026 | ocn424525329 | With his lightening-quick hands and feet The second field in the above data is "ocn424525329". It should be "424525329" with no trailing or leading spaces. This may be better... (2 Replies)
Discussion started by: Bubnoff
2 Replies

6. Shell Programming and Scripting

A question about the newline character in KornShell scripts

Dear all, How can we know in a KornShell script reading a value from the standard input, that the entered value is the newline character? because as far as I know we cannot use \n for pattern matching. For example: #!/bin/ksh print -n "enter your value: " read VALUE if ] then ... (2 Replies)
Discussion started by: dariyoosh
2 Replies

7. Programming

Question about NULL Character & fgets()

Assume client send the message " Hello ", i get output such as Sent mesg: hello Bytes Sent to Client: 6 bytes_received = recv(clientSockD, data, MAX_DATA, 0); if(bytes_received) { send(clientSockD, data, bytes_received, 0); data = '\0';... (2 Replies)
Discussion started by: f.ben.isaac
2 Replies

8. UNIX for Dummies Questions & Answers

Bash Wildcard Question

Hi, I am writing a BASH script. In a directory I have a bunch of files of various filename structures. How do I list all the filenames that begin with either a capital or lowercase A or T. Is there one command that could replace the following 4: ls A* ls a* ls T* ls t* Thanks. Mike (3 Replies)
Discussion started by: msb65
3 Replies

9. Shell Programming and Scripting

Single character wildcard for SED

Could someone tell me the single character wildcard for SED? I have the file below: $ more input2 AAA /A/B/C BBB /D/E/F CCC /G/H/I DDD I want to remove all strings which contain forward slashs "/" to get the below: AAA BBB CCC I tried to do it in SED by the command below but I... (8 Replies)
Discussion started by: stevefox
8 Replies

10. UNIX for Dummies Questions & Answers

Find wildcard .shtml files in wildcard directories and removing them- How's it done?

I'm trying to figure out how to build a small shell script that will find old .shtml files in every /tgp/ directory on the server and delete them if they are older than 10 days... The structure of the paths are like this: /home/domains/www.domain2.com/tgp/ /home/domains/www.domain3.com/tgp/... (1 Reply)
Discussion started by: Neko
1 Replies
Login or Register to Ask a Question