Quick File Copy on File Name with Sample Extension
By default, some of the application installation provide you a sample configuration file. Usually the sample of configuration will end with name like *.sample, *.default and so on. Let say you have 20 of *.sample files and it will take you some time to copy, move or rename one by one. Lets do some quicker way which will save more time.
Create a sample file file random name ended with *.sample. Example
touch apple.sample.cfg
touch microsoft.sample.cfg
touch php.sample.cfg
touch config.sample.cfg
touch apache.sample.cfg
touch mysql.sample.cfg
touch pgsql.sample.cfg
touch cacti.sample.cfg
touch wordpress.sample.cfg
touch jessicaalba.sample.cfg
Now you have all the sample configuration, you are going to use them. Are you going to copy one by another and change the same with .cfg prefix? We can do it, in a better and faster way.
Make a new directory to store all the sample file
mkdir sample
cp *.sample.cfg sample/
After that, go to sample directory and copy the files to a location
cd sample
for d in `ls *.sample.cfg`; do cp $d `echo $d | sed s/sample.cfg/cfg`; done
That one simple line will easily save you 1-2 minutes.
Related posts:
- Modify or Adjust File Date Time on Unix/Linux You have folders or files in your server last modified...
- How to Install Cacti Plugin Architecture Cacti Plugin Architecture allow you to run useful monitoring plugins...
- How to Change MySQL Data Directory in Linux Centos By default Linux CentOS or other Linux Distro installation, MySQL...
- secure copy with failover – rsync & ssh e.g. rsync -av –progress -e ‘ssh -i /alternate/id/file’ sshusername@host:/directory/or/file /destination/directory/or/file...
- Changing File’s Date and Time on Unix Systems Change Data and Time of a File At times, we...
- Linux/Unix Search and Replace Text from Multiple Files In Linux/Unix, for newbie to do search text from multiple...
- split – but no destination parameter to specify first : cd /destination/directory second : split /source/directory/big-huge-file prefix-to-apply-onto-splited-files Voila...
- Install and Configure Thold on Cacti There are a bunch of Cacti’s plugins which can do...
- What is umask? umask? What? What is umask command use for in linux/unix...
- Install and Configure mod_suphp or suphp on Plesk Server Plesk control panel comes with Media Temple DV package doesn’t...
Tags: copy, linux, linux command, sed, unix, unix command
May 21st, 2010 at 12:21 am
shorter one… assuming we have .sample files from installation
for f in *sample ; do mv $f `basename $f sample`cfg; done
May 21st, 2010 at 8:13 am
thanks mate for the great tips!
June 9th, 2010 at 2:48 am
personally I like the bash (and ksh?) curly-brace extensions (albeit the basename might be a shell-internal command):
for f in *sample; do mv $f ${f/sample.//}; done
granted, it might not be that readable but you get used to it
–
rs