Wednesday, July 11, 2007

Linux command

Renaming multiple files or directories at once

To rename multiple files at once you must utilize some form of wild character, below are some examples of how this could be done.

In the below example this would rename all the files in the current directory that end with .rtf to .txt files.

mv *.rtf *.txt

In this next example the command would rename a file with an unknown character in the file name to something that can be read. The "?" used in the below example is the wild character for an unknown character.

mv h?pe.txt hope.txt

Renaming a directory

Renaming a directory in Linux / Unix is much like renaming a file simply replace the file name with the directory name that you wish to rename. For example, if we wanted to rename the directory "test" to "hope" you would type the below command.

mv test hope


Using tar, gzip, and bzip2

untar/gzipping a file
The following will decompress .tar.gz and .tgz files. cd into the dir with the file/s then type “tar zxvf yourfile.tar.gz” or “tar zxvf yourfile.tgz”.

un-tar a .tar
cd into the dir with the file/s then type “tar xvf yourfile.tar”.

un-gzip a file
Type “gzip -d filename.gz”.

un-bzip2 a file
Type “bzip2 -d filename.bz2″.

tar plus gzip a dir/multiple files
cd into the dir of the files you want to tar(warning, this will put ALL files of the current dir you’re in into a tar file), type “tar cvf newTarFile.tar * “. Now to gzip the file, type “gzip -9 newTarFile.tar”.

No comments: