Create the Filefile File Again in Your Home Directory Linux
Download Article
Download Article
This wikiHow commodity teaches you lot how to create a file in a directory in Linux. There are many ways y'all tin create files using the Terminal in Linux. You can create simple text files using short Final commands, or yous tin use one of Linux's built-in text editors to create complex documents.
-
1
Press Ctrl+Alt+T to open the Terminal. The Terminal is a command-line interface that is available on most Linux distributions. Information technology typically has an icon that resembles a blackness screen with a white text cursor. Y'all can either click the Terminal icon in the Apps card, or press Ctrl + Alt + T at the same time to open the Terminal.
-
2
Navigate to the directory you want to create a file in. To do then, type cd followed by the path to the directory you desire to create a file in and press Enter.. For instance, y'all could type cd /home/username/Documents to navigate to your Documents folder.
- Alternatively, you can type cd / to navigate to the Root directory, or blazon cd ~ to navigate to your Home/User directory.[1]
- You lot tin can as well blazon cd ~ followed past the path relative to your Home/User folder to navigate to a directory. For instance, type cd ~/Documents and press enter to navigate to "/dwelling/user/Documents" directory.
- Type pwd and press Enter to see what directory you are currently in.
- Type mkdir followed by the directory name to create a new directory in the directory you are currently in.
Advertisement
-
3
Type touch on. The "touch" command is used to create an empty file in Linux. This is the easiest way to create a file in Linux.
-
iv
Blazon the name of the file and press ↵ Enter . You can type the filename by itself (i.e. "touch on blank_file"}} or add a file extension to the end of it (i.e. "touch on blank_file.txt"). This creates a blank file.
- Add multiple filenames afterwards the "touch" command to create multiple files (i.e. "affect file_1 file_2 file_3").
- Alternatively, you lot can create a file in whatsoever directory you want by adding the directory path after the "touch" command (i.e "bear on /habitation/username/Documents/blank_file.txt")
- You can create a file in multiple directories by adding the directory names later the touch command. For example touch on category/file1.txt subcategory/blank_file.txt or bear on {category,subcategory}/blank_file.txt.[2]
- If the file you are trying to create already exists in the directory, the time postage stamp for that file will be updated instead.
-
5
Type ls and printing ↵ Enter . This displays a list of all files in your current directory and allows you to verify that the file y'all but created is present.
Advertizing
-
ane
Press Ctrl+Alt+T to open the Terminal. The Terminal is a command-line interface that is available on most Linux distributions. It typically has an icon that resembles a black screen with a white text cursor. You can either click the Final icon in the Apps menu, or printing Ctrl + Alt + T at the same time to open the Last.
-
2
Navigate to the directory you desire to create a file in. To do so, type cd followed past the path to the directory you lot want to create a file in and press Enter.. For instance, you lot could type cd /home/username/Documents to navigate to your Documents folder.
- Alternatively, you can type cd / to navigate to the Root directory, or type cd ~ to navigate to your Home/User directory.[3]
- You can as well blazon cd ~ followed by the path relative to your Home/User folder to navigate to a directory. For example, type cd ~/Documents and press enter to navigate to "/home/user/Documents" directory.
- Blazon pwd and press Enter to see what directory you are currently in.
- Type mkdir followed by the directory proper name to create a new directory in the directory you are currently in.
-
three
Type cat > followed by the file name and press + ↵ Enter . For instance, y'all tin type cat >README.txt to create a new text file. You can type the filename by itself (i.e. "README") or add a file extension to the end of it (i.e. "true cat >hello.txt"). Use the "cat" control to create files that comprise text or code.
- Alternatively, you can apply the command cat >> to append an existing file. If no file exists with the specified file proper noun, a new file volition be created. If a file by that proper name already exists, then the text y'all add volition be appended to the cease of the file instead of replacing the existing text.[4]
-
iv
Type the text yous desire to become in the file. After creating a file using the "cat" command, the Concluding enters write mode allowing you to add text to the file. Type the text you desire the file to contain on the next line.
-
5
Press Ctrl+d . This saves the file with the text and exits write mode in the Terminal.
- To view the text in the file, simply blazon "cat" (without the ">" symbol) followed past the file name and press Enter (i.due east. cat README.txt). This displays the text in the Terminal.
-
6
Type ls and press ↵ Enter . This displays a list of all files in your current directory and allows you lot to verify that the file y'all just created is present.
Advertizing
-
1
Printing Ctrl+Alt+T to open the Terminal. The Terminal is a control-line interface that is available on most Linux distributions. It typically has an icon that resembles a blackness screen with a white text cursor. You can either click the Last icon in the Apps carte, or press Ctrl + Alt + T at the same time to open the Terminal.
-
2
Navigate to the directory yous want to create a file in. To exercise and then, type cd followed by the path to the directory you desire to create a file in and printing Enter.. For instance, you could blazon cd /dwelling house/username/Documents to navigate to your Documents folder.
- Alternatively, you can blazon cd / to navigate to the Root directory, or blazon cd ~ to navigate to your Habitation/User directory.[five]
- You can also type cd ~ followed by the path relative to your Home/User folder to navigate to a directory. For case, blazon cd ~/Documents and press enter to navigate to "/dwelling/user/Documents" directory.
- Type pwd and press Enter to see what directory you lot are currently in.
- Type mkdir followed past the directory name to create a new directory in the directory you lot are currently in.
-
3
Type nano followed by a file name and printing ↵ Enter . Y'all tin type the filename by itself (i.eastward. "nano text_file"}} or add together a file extension to the end of it (i.eastward. "nano python_program.py"). This creates a new file and opens information technology in Nano.
- Nano may not be available on all Linux distributions. To install Nano, type sudo apt install nano and press Enter to install Nano on Ubuntu/Debian. Type sudo yum install nano and press Enter to install Nano on CentOS/Fedora.
- You can also specify which directory yous want to create the file in past entering the path of the directory later the "vi" control (i.e nano /home/username/Documents/website/primary.php).
-
4
Blazon the text you want your file to comprise. As presently as Nano opens, you can brainstorm entering your text.
-
5
Press Ctrl+X . Apply this keyboard shortcut to save and exit Nano when you lot are washed editing your text.
-
six
Press y followed by ↵ Enter . This confirms that you lot want to save your file and exits Nano. You volition be returned to the standard Terminal command-line.
Advertisement
-
one
Press Ctrl+Alt+T to open the Terminal. The Last is a control-line interface that is available on most Linux distributions. It typically has an icon that resembles a blackness screen with a white text cursor. You tin either click the Terminal icon in the Apps menu, or press Ctrl + Alt + T at the aforementioned time to open the Last.
-
two
Navigate to the directory yous want to create a file in. To exercise so, type cd followed by the path to the directory you desire to create a file in and press Enter.. For instance, you lot could type cd /home/username/Documents to navigate to your Documents folder.
- Alternatively, you can blazon cd / to navigate to the Root directory, or type cd ~ to navigate to your Home/User directory.[6]
- You can also blazon cd ~ followed by the path relative to your Dwelling house/User folder to navigate to a directory. For example, blazon cd ~/Documents and press enter to navigate to "/home/user/Documents" directory.
- Type pwd and printing Enter to run across what directory you are currently in.
- Type mkdir followed by the directory name to create a new directory in the directory y'all are currently in.
-
iii
Type echo followed by some text in quotations. The text yous enter in quotations will be saved to the file. Use the "echo" command to create files with brusque lines of text.
-
4
Type > followed by the file name and press ↵ Enter . The unabridged control should await something like this echo "Hullo Earth" >hello_world.txt. This saves the file with the text in quotations.
- Alternatively, you can add together >> at the finish of the text. This will create a new file if no file by the file name specified exists. If a file by that name already exists, the text will be appended to the cease of the existing file text.
-
v
Type ls and press ↵ Enter . This displays a listing of all files in your current directory and allows you to verify that the file you lot just created is present.
Advertisement
-
1
Press Ctrl+Alt+T to open the Final. The Final is a command-line interface that is available on most Linux distributions. Information technology typically has an icon that resembles a blackness screen with a white text cursor. You can either click the Terminal icon in the Apps menu, or press Ctrl + Alt + T at the same fourth dimension to open the Terminal.
-
2
Navigate to the directory yous want to create a file in. To do then, type cd followed by the path to the directory you want to create a file in and press Enter.. For example, you could type cd /abode/username/Documents to navigate to your Documents folder.
- Alternatively, yous can type cd / to navigate to the Root directory, or type cd ~ to navigate to your Home/User directory.[7]
- You lot tin can also blazon cd ~ followed past the path relative to your Abode/User folder to navigate to a directory. For case, type cd ~/Documents and printing enter to navigate to "/home/user/Documents" directory.
- Type pwd and press Enter to see what directory yous are currently in.
- Type mkdir followed by the directory proper noun to create a new directory in the directory y'all are currently in.
-
3
Type vi followed by the a file name and press ↵ Enter . You tin type the filename by itself (i.east. "vi file1"}} or add a file extension to the end of it (i.e. "half-dozen file1.txt"). This creates a new file past the name specified and opens the file in the VI text editor. Half-dozen is a Terminal-based text editor. It is the oldest text editor for Linux and works in all versions of Linux.
- Alternatively, you tin can apply the vim in place of the {[kbd|vi}} control. This opens the VIM text editor, which is a newer and more than convenient version of VI. VIM may not exist bachelor on all Linux distributions. If VIM is not installed on your Linux distribution, blazon sudo apt install vim and press Enter to install VIM on Ubuntu/Debian. Blazon sudo yum install vim and press Enter to install VIM on CentOS/Fedora. .
- You tin can also specify which directory you want to create the file in by inbound the path of the directory later the "vi" command (i.e., "vi /home/username/Documents/Website/alphabetize.html").
-
four
Press i to switch to Insert style. VI has 2 modes, Command fashion and Insert fashion. Command mode allows you to perform various tasks using the keyboard keys. Insert manner allows you to enter text. Press I to switch to Insert manner.
-
v
Type the text you want to add. Now that yous are in "Insert" manner, you can blazon the text the way y'all would using any other text editor. Enter the text yous desire the file to contain.
-
6
Press Esc . This switches from Insert mode back to Command fashion..[8]
-
vii
Type the control to relieve and exit 6. To practise so, type :wq and press Enter. This saves the file and returns to the standard Terminal control-line.
Advertizement
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
Advertizing
Nigh This Commodity
Thanks to all authors for creating a page that has been read 1,533 times.
Is this article up to engagement?
Source: https://www.wikihow.com/Create-a-File-in-a-Directory-in-Linux
Belum ada Komentar untuk "Create the Filefile File Again in Your Home Directory Linux"
Posting Komentar