LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to tell if "rename" in your distro supports regular expressions (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-tell-if-rename-in-your-distro-supports-regular-expressions-857074/)

lynne007 01-18-2011 12:30 PM

how to tell if "rename" in your distro supports regular expressions
 
I am trying to do a rename using a regular expression, and it doesn't seem to work.

I did a web scan, and it looks like some versions of linux don't support regular expressions for commands. How do I tell if a version of linux supports regular expressions?

for that matter, how do I tell what version of linux I am using?

tsg 01-18-2011 12:49 PM

Quote:

Originally Posted by lynne007 (Post 4229043)
for that matter, how do I tell what version of linux I am using?

Code:

uname -r

lynne007 01-18-2011 12:57 PM

I get:
2.6.18-194.26.1.el5

how do I tell if that version of linux supports regular expressions in the commands?

markush 01-18-2011 01:02 PM

Hi lynne007,

could you please explain what you want to do? I don't understand your question.

Linux is the kernel.

There are many programs/commands which support regular expressions.

But the kernel and the programs are different things.

Markus

stress_junkie 01-18-2011 01:03 PM

Quote:

Originally Posted by lynne007 (Post 4229065)
2.6.18-194.26.1.el5
how do I tell if that version of linux supports regular expressions in the commands?

The name of the kernel suggests (to me) that you are either using Red Hat or Centos. Those certainly do support regular expressions. I have never heard of any distribution that does not support regular expressions. Perhaps you are confusing that term with something else.

We could provide better information if you described your problem in greater detail. What exactly are you trying to do? Here is an example of a good question:
Quote:

I am trying to list all of the files that begin with the letter "i" in the directory /home/me/test.
I have used the following command in a terminal window (gnome-terminal) without success.
Code:

ls /home/me/test/i*
The result of issuing that command is the following:
Code:

ls: cannot access /home/me/test/i*: No such file or directory

markush makes a good point. The application, whether it is a video player or a shell in a terminal window, is really what does or does not support regular expressions.

lynne007 01-18-2011 02:44 PM

sorry about not giving more detail.

I was trying to do this:

rename -v 's/\.ccp/\.cpp/' /home/xxx/*.ccp

and this:

rename -v 's/????e0\.cpp/????\.cpp/' /home/xxx/*.cpp


I read this:
http://tips.webdesign10.com/how-to-b...n-the-terminal
with this caveat:
Quote:

UPDATE: I believe the Perl-based rename command is only available on Debian-based Linux distros, but there are instructions on adding it to other distros below.
guess this must be a non Debian-based Linux installation.

I finally ended up with this - which worked.. but was more limited - didn't tell me what was renamed, and it doesn't seem to recognize any regular expression in the find/replace string:

rename .ccp .cpp /home/xxx/*.ccp
rename e0.cpp .cpp /home/xxx/*.cpp

markush 01-18-2011 02:58 PM

Hi,

I'm happy to read that you found a solution.
You may as well read more about the shell (bash), for example here: http://tldp.org/LDP/abs/html/
With a little bash-scripting you can do more advanced renaming on the commandline.

Markus

grail 01-18-2011 08:52 PM

OP - I think you should have looked further down the link you gave us :)

Towards the bottom is the following line:
Quote:

The code from Ubuntu's rename/prename is here (Gutsy Gibbon).
Simply click on the link and remove the .txt extension, do a chmod +x on the file and throw it in a bin directory
somewhere. Then you have the same rename you are trying to invoke :)


All times are GMT -5. The time now is 09:14 AM.