File creation in Linux
How do we create a file or a dir in Linux?
There are several different commands that can be used to open, create, edit, or view a file in Linux.
Create a new file
VI command:
-as default on most of the Linux OS we will have the "vi" command. "VI" command can be also used to edit already created files.
How do we use the "vi" command to create a new file :
Syntax:
-to create or edit a file:
vi "file name"."file extension" + ENTER
This is how a empty file looks like, you can edit this file by pressing the "i" key(insert).
To save and exit the file :
Syntax:
ESC + :wq + ENTER ESC + :q! + ENTER
General Syntax used with "VI":
vi [ -| -s ] [-l] [-L] [-R] [ -r [ filename ] ] [-S] [-t tag] [-v] [-V] [-x] [-w] [-n ] [-C] [+command | -c command ] filename
Other Linux editos that can be used:
cat
-Allows you to look, modify or combine a file.
Sintax:
cat "filename" [-n] [-b] [-u] [-s] cat file1.txt file2.txt >
file3.txt tail [+ number] [-l] [-b] [-c] [-r] [-f] [-c number | -n number] [file] man tail mkdir mkdir [option] directory
To remove a dir just use the "rmdir" remove directory Command :
Sintax:
rm[option]"dir name";
Note
- if you try to delete the directory using rmdir command and you have some others files or other directorys you will get and error message.
So in order for us to delete the dir and also what is inside of it we will use the "rmdir"
option command "-r":
Syntax
rmdir -r "dir name"
Very important :
Never run (rm -rf / or rm -rf *)as an administrator or normal Linux user.this command will erase everything you have on your computer, and believe me Linux commands from the bash line are pretty quick, there is no way back from this(only a backup restore will save you).
I will not demonstrate this command asi do not want my file system to go empty.