mkdir qeFiles and Directories
Let’s create a new directory called thesis using the command mkdir QE (which has no output):
As you might guess from its name, mkdir means “make directory”. Since qe is a relative path (i.e., doesn’t have a leading slash), the new directory is created in the current working directory:
Since we’ve just created the qe directory, there’s nothing in it yet:
ls -F qels: qe: No such file or directory
Moving Files Around
We can move our new file into the new directory with the move command, mv. The syntax of mv is $ mv file_being_moved location_moving_to. Moving our new file “QE” to our new directory “qe” can be done as follows:
mv qe QEmv: rename qe to QE: No such file or directory
$ cd QELet’s change our working directory to QE using cd, then run a text editor called vi to create a file called si.in :
$ vi si.inWhich Editor?
Text editors can be used for writing code, editing text files such as configuration files, creating user instruction files, and many more. In Linux, text editors are of two kinds that is the graphical user interface (GUI) and command-line text editors (console or terminal).
Vi/Vim Editor
Vim is a powerful command-line based text editor that has enhanced the functionalities of the old Unix Vi text editor. It is one the most popular and widely used text editors among System Administrators and programmers that is why many users often refer to it as a programmer’s editor.
The procedure to save a file in vi/vim and quit the editor is as follows:
- open the file with
vi filename( e.g vi si.in) - to save a file and quit press
Esckey , type:wq ( or `:x`) - hit
Enterkey
Creating Files in Different way
We have seen how to create text files using the vi/vim editor. Now, try the following command in your home directory:
touch QE/si.outCopying Files
We can also copy files, leaving the original file while a second version is created either elsewhere or in the same location. The copy command is cp and its syntax is the same as for mv: $ cp file_being_copied location_copying_to. We can create a copy of “QE” into “qe” directory as follows:
cp QE qe cp: QE: No such file or directory
Removing Files and Directories
If we try to remove the entire thesis directory using rm QE, we get an error message:
rm QEWhat happens when we execute rm -i QE/si.out? Why would we want this protection when using rm?
rm: remove regular file 'QE/si.out'?
The -i flag will prompt before every removal. The Unix shell doesn’t have a trash bin, so all the files removed will disappear forever. By using the -i flag, we have the chance to check that we are deleting only the files that we want to remove.
Removing the files in a directory recursively can be a very dangerous operation. If we’re concerned about what we might be deleting we can add the “interactive” flag -i to rm which will ask us for confirmation before each step
$ rm -r -i QE
rm: descend into directory ‘QE’? y
rm: remove regular file ‘QE/si.in’? y
rm: remove regular file ‘QE/si.out’? y
rm: remove directory ‘QE’? ycp old newcopies a file.mkdir pathcreates a new directory.mv old newmoves (renames) a file or directory.rm pathremoves (deletes) a file.*matches zero or more characters in a filename, so*.txtmatches all files ending in.txt.?matches any single character in a filename, so?.txtmatchesa.txtbut notany.txt.Use of the Control key may be described in many ways, including
Ctrl-X,Control-X, and^X.The shell does not have a trash bin: once something is deleted, it's really gone.
Depending on the type of work you do, you may need a more powerful text editor than
vi.