tags:

views:

178

answers:

2

As the title says I want to remove the first 4 letters from a folder name using a Bash script. If you have another way to do it in Linux I don't really mind e.g. Python. Also I need the script to be executed regularly (daily).

+3  A: 

Since you don't mention to rename a directory or so, I assume you want simple string editing. If you want more, you should ask the right questions.

# name of the DIRECTORY (not ''folder''...)
name=fooodir

# compute a new name
editedname=${name#????}
echo "${editedname}"
TheBonsai
Ah, missed the daily execution thing: Check your cron related manpages.
TheBonsai
+9  A: 

Another way in Bash:

$ dname=mydirectory
$ echo ${dname:4}
rectory
ghostdog74
Ah right. No idea how I could miss the most easy way :(+1
TheBonsai
I have to test this first but that looks way to easy :)
RC1140
It should be mentioned for completeness that this parameter expansion is not ISO9945, mine is. If you stick with Bash or Korn, there shouldn't be a problem. But you should never use a #!/bin/sh Shebang when not using ISO constructs.
TheBonsai
Oh, you mean "POSIX"!
Dennis Williamson
Sort of, yes. POSIX, if you like. In XCU, it's the same.
TheBonsai