Saturday, 20 June 2009

Bash Tips (CLI Command Line Interface)

Bash Tips (CLI Command Line Interface)

list all files in list format:
$ls -alt


prints the contents of text file "defines.h" to the CLI (Command Line Interface):
$cat < defines.h




Renaming a File or Folder

In the below example this would rename the file test.txt to hope.txt.

mv test.txt hope.txt

If the test.txt file was in a different directory then the one you were currently in you would need to specify the path of the file. For example, if the file was in the "computer" directory you would type a command similar to the below example.

mv computer/test.txt hope.txt

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

No comments:

Post a Comment