" to create a file, the syntax "> file name"; 2. Use the touch command to create a file, the syntax "touch file name"; 3. Use the echo command to create a file; 4. Use printf to create a file; 5. Use cat to create a file; 6. Use the vi/vim command to create a file; 7. Use nano to create a file; 8. Use head to create a file; 9. Use tail to create a file. ;10. Use truncate to create a file."/> " to create a file, the syntax "> file name"; 2. Use the touch command to create a file, the syntax "touch file name"; 3. Use the echo command to create a file; 4. Use printf to create a file; 5. Use cat to create a file; 6. Use the vi/vim command to create a file; 7. Use nano to create a file; 8. Use head to create a file; 9. Use tail to create a file. ;10. Use truncate to create a file.">

Home>Article>Operation and Maintenance> How to create a new file in linux

How to create a new file in linux

青灯夜游
青灯夜游 Original
2023-01-05 15:03:35 18078browse

how to create a new file: 1. use the redirection character ">" file, syntax is "> file name"; 2. touch command "touch 3 , use echo file; 4. printf 5. cat 6. vi vim 7. nano 8. head ;9. tail 10. truncate file. < p>< blockquote>

How to create a new file in linux< p>

#the operating environment of this tutorial: linux7.3 system, dell g3 computer.

we all know that on linux, everything including devices are files. linux administrators should perform creation activities multiple times per day (perhaps 20, 50, or even more, depending their environment).

efficiently creating very important ability. why do i say efficient? if you few ways your current efficiently, can more with less. this will save lot time. you useful time other things.

the following introduce methods files linux. suggest choose simple and efficient ones assist work. not need install any commands as they already installed system part core tools.

creating be done in six ways:

  • >< code>: the standard allows us an empty 0kb. li> touch< does exist, code> 0kb echo< display line text through parameter. printf< used display given terminal. cat< it concatenates prints output. vi< vim< vim editor upward compatible vi. commonly used for editing various types plain text. nano< user-friendly editor. replicates look benefits pico< code>, but free software. head< print beginning tail< last truncate< reduce expand size specified size. ul>

    creating using (>) linux< strong>< h2>

    the typically redirect output when symbol without command, it creates >but allow enter into when it. however less diligent administrators. just followed by name want.

    $ > daygeek.txt< pre>< div> >use ls< view just created. >$ ls -lh daygeek.txt -rw-rw-r-- 1 daygeek daygeek 0 feb 4 02:00 daygeek.txt< 

    use >touch< often access each modification updated >if some at same default. >$ touch daygeek1.txt< >$ ls -lh daygeek1.txt -rw-rw-r-- 1 daygeek daygeek 0 feb 4 02:02 daygeek1.txt< >echo< built most systems. scripts, batch files, single inserts >it of course also later. >$ echo "2daygeek.com is a best linux blog to learn linux" > daygeek2.txt< >$ ls -lh daygeek2.txt -rw-rw-r-- 1 daygeek daygeek 49 feb 4 02:04 daygeek2.txt< >you contents >$ cat daygeek2.txt 2daygeek.com is a best linux blog to learn linux< two redirectors (>>< code>) add content >$ echo "it's five years old blog" >> daygeek2.txt< added content. 2daygeek.com is a best linux blog to learn linux it's five years old blog<

    在 上使用 命令创建一个新的文件< >printf< 命令也可以以类似 的方式执行。< 命令常用来显示在终端窗口给出的字符串。printf< 可以有格式说明符、转义序列或普通字符。< >$ printf "2daygeek.com is a best linux blog to learn linux\n" > daygeek3.txt< >使用 命令查看刚刚创建的文件。< >$ ls -lh daygeek3.txt -rw-rw-r-- 1 daygeek daygeek 48 feb 4 02:12 daygeek3.txt< 命令查看文件的内容。< >$ cat daygeek3.txt >你可以使用两个重定向符 添加其他的内容到同一个文件中去。< >$ printf "it's five years old blog\n" >> daygeek3.txt< >你可以使用 命令查看这个文件中添加的内容。< 中使用 创建一个文件< >cat< 表示 串联(concatenate)< em>。在 经常用于读取一个文件中的数据。< 是在类 unix 系统中最常使用的命令之一。它提供了三个与文本文件相关的功能:显示一个文件的内容、组合多个文件的内容到一个输出以及创建一个新的文件。(lctt 译注:如果 命令后如果不带任何文件的话,下面的命令在回车后也不会立刻结束,回车后的操作可以按 ctrl-c< 或 ctrl-d< 来结束。)< >$ cat > daygeek4.txt 命令查看创建的文件。< >$ ls -lh daygeek4.txt -rw-rw-r-- 1 daygeek daygeek 74 feb 4 02:18 daygeek4.txt< >$ cat daygeek4.txt >如果你想向同一个文件中添加其他内容,使用两个连接的重定向符(>>< code>)。< >$ cat >> daygeek4.txt this website is maintained by magesh m, it's licensed under cc by-nc 4.0.< 命令查看添加的内容。< it's five years old blog 命令创建一个文件< >vim< 是一个向上兼容 的文本编辑器。它通常用来编辑所有种类的纯文本。在编辑程序时特别有用。< 中有很多功能可以用于编辑单个文件。< >$ vi daygeek5.txt 查看刚才创建的文件。< >$ ls -lh daygeek5.txt -rw-rw-r-- 1 daygeek daygeek 75 feb 4 02:23 daygeek5.txt< >$ cat daygeek5.txt >nano< 是一个编辑器,它是一个自由版本的 克隆。nano< 是一个小且用户友好的编辑器。它复制了 的外观及优点,并且是一个自由软件,它添加了 缺乏的一系列特性,像是打开多个文件、逐行滚动、撤销 重做、语法高亮、行号等等。< >$ nano daygeek6.txt >$ ls -lh daygeek6.txt -rw-rw-r-- 1 daygeek daygeek 148 feb 4 02:26 daygeek6.txt< 命令来查看一个文件的内容。< >$ cat daygeek6.txt >head< 命令通常用于输出一个文件开头的一部分。它默认会打印一个文件的开头 10 行到标准输出。如果有多个文件,则每个文件前都会有一个标题,用来表示文件名。< >$ head -c 0k  dev zero > daygeek7.txt< >$ ls -lh daygeek7.txt -rw-rw-r-- 1 daygeek daygeek 0 feb 4 02:30 daygeek7.txt< >tail< 命令通常用来输出一个文件最后的一部分。它默认会打印每个文件的最后 >$ tail -c 0k  zero > daygeek8.txt< >$ ls -lh daygeek8.txt -rw-rw-r-- 1 daygeek daygeek 0 feb 4 02:31 daygeek8.txt< >truncate< 命令通常用作将一个文件的尺寸缩小或者扩展为某个指定的尺寸。< >$ truncate -s 0k daygeek9.txt< 命令检查创建的文件。< >$ ls -lh daygeek9.txt -rw-rw-r-- 1 daygeek daygeek 0 feb 4 02:37 daygeek9.txt< >在这篇文章中,我使用这十个命令分别创建了下面的这十个文件。< >$ ls -lh daygeek* -rw-rw-r-- 1 daygeek daygeek 0 feb 4 02:02 daygeek1.txt -rw-rw-r-- 1 daygeek daygeek 74 feb 4 02:07 daygeek2.txt -rw-rw-r-- 1 daygeek daygeek 74 feb 4 02:15 daygeek3.txt -rw-rw-r-- 1 daygeek daygeek 148 feb 4 02:20 daygeek4.txt -rw-rw-r-- 1 daygeek daygeek 75 feb 4 02:23 daygeek5.txt -rw-rw-r-- 1 daygeek daygeek 148 feb 4 02:26 daygeek6.txt -rw-rw-r-- 1 daygeek daygeek 148 feb 4 02:32 daygeek7.txt -rw-rw-r-- 1 daygeek daygeek 148 feb 4 02:32 daygeek8.txt -rw-rw-r-- 1 daygeek daygeek 148 feb 4 02:38 daygeek9.txt

    相关推荐:《linux视频教程< a>》< p>

    The above is the detailed content of How to create a new file in linux. For more information, please follow other related articles on the PHP Chinese website!

how>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn