Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: On my PC I use RHEL, at office AIX, Solaris, HP-UX, RHEL.
Posts: 254
Original Poster
Rep:
Now here is another scenario:
1) Delete all files which have no extension names- do keep the ones which have them.
2) Delete all files which have extensions names- don't delete the ones which have them.
*Note: Using dot (.) in the criteria may not server the purpose in cases where a file name has multiple dots in it.
Example# 1:
Code:
[root@localhost ~]# ls
0 44 anaconda-ks.cfg h PingReport
1 5 d hi Ping Report for the Date of:
11 556 data install.log PingStatus.txt
2 56 Desktop install.log.syslog s
22 6 e jj t
3 7 er k work
333 8 f logout-script.txt z
4 9 g names
[root@localhost ~]# rm *.*
rm: remove regular file `anaconda-ks.cfg'? n
rm: remove regular file `install.log'? n
rm: remove regular file `install.log.syslog'? n
rm: remove regular file `logout-script.txt'? n
rm: remove regular file `PingStatus.txt'? n
[root@localhost ~]#
Example# 2: This includes only those file names which begin with a dot (.)
Whenever you need to change the meaning of a character, the typical thing is to "escape" it with "\". The details depend on the context, but---in general---the use of "\" toggles the meaning of a character from whatever the default is in that situation. You can slog thru something like the Advanced Bash Scripting Guide---or you can simply experiment.
One example:
sed 's/./DOT/g' ##replaces all single characters with "DOT"
sed 's/\./DOT/g' ##replaces all literal "."s with "DOT"
(Obviously?) this only applies to characters which may have a special meaning in the context.....
FYI. In your first example, rm [[:lower:]]* will remove files that start with a lower case letter. The "*" in the shell globs "zero or more characters". It isn't used as in grep, sed or awk where it means "zero or more of the preceding character". You can however enable normal regular expressions with the "extglob" option.
Also, in another post, you were looking at hidden files. Be careful if you try to delete hidden files, because ".*" will also match ".." which is the parent directory.
Use ".[^.]*" instead.
There is another gotcha in the order of characters. The $LC_CTYPE locale variable can effect which characters match a regular expression.
Distribution: On my PC I use RHEL, at office AIX, Solaris, HP-UX, RHEL.
Posts: 254
Original Poster
Rep:
Okay, pixellany and jschiwal. I will try that tomorrow because my tummy is aching so much because I have not taken any meals today. I must leave the lab now!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.