【Linux】【创建文件】Linux系统下在命令行中创建文件的方法

  • 作者简介:花神庙码农(专注于Linux、WLAN、TCP/IP、Python等技术方向)
  • 博客主页:花神庙码农 ,地址:https://blog.csdn.net/qxhgd
  • 系列专栏:Linux技术
  • 如觉得博主文章写的不错或对你有所帮助的话,还望大家三连支持一下呀!!! 关注✨、点赞、收藏、评论。
  • 如需转载请参考转载须知!!

Linux系统下在命令行中创建文件的方法

    • touch
    • >、>>
    • cat
    • echo
    • printf
    • cp或mv
    • dd命令
    • fallocate
    • vi、vim等

touch

  • 通过touch命令,可以创建空的文件:
touch test.txt              #创建单个文件
touch test1.txt test2.txt   #创建两个文件
touch test{0001..10000}.txt ##创建10000个文件

>、>>

  • 利用重定向,也可以生成一个空文件:
> test.txt
>> test.txt
ls > test.txt
ls >> test.txt
ps -ef | grep java >test.txt

cat

  • 利用cat命令,可以交互式的将内容写入文件,以Ctrl+C结束:
cat > test.txt
cat >> test.txt
cat >> test.txt<<eof
cat >> test.txt<<exit
cat << EOF > file1.txt

echo

  • 利用echo可以将
echo 'some infomation' > test.txt
echo 'some infomation again' >> test.txt

printf

  • printf的用法类似于echo:
printf "Hello, Shell" > hello.txt

cp或mv

  • 利用cp或mv可以利用已有文件,生成一个新的文件:
cp src.txt dst.txt
mv log.txt log.txt.bak

dd命令

  • 适合用于生成大文件:
dd if=/dev/zero of=1G.test bs=1 count=0 seek=1G

fallocate

  • 适合用于生成大文件:
fallocate -l 1G 1G.test

vi、vim等

vi test.txt
vim touch.txt

如本文对你有些许帮助,欢迎大佬加关注、评论、点赞,有关必回关

你可能感兴趣的:(linux,shell,创建,文件,命令行,touch,cat)