linux - 如何通过linux终端在文本文件中创建一个名为sth的文件夹?

标签 linux ubuntu terminal

我有一个包含文件夹名称的文本文件。我想通过 Ubuntu 终端读取该文本文件的上下文并创建一个具有该名称的文件夹(写在 txt 文件中)。我不知道该怎么做,我创建了一个名为“in.txt”的文件,它的上下文是“name”,我尝试了下面的 c 代码:

#include <stdio.h>
int main(){
FILE *fopen (const char in.txt, const char r+);
}

我应该在终端中写什么?

最佳答案

设文本文件in.txt为:

foldername1
foldername2

然后就可以创建一个脚本文件script.sh:

#!/usr/bin/env bash

# $1 will be replaced with the first argument passed to the script:
mkdir -p $(cat "$1")    

在 shell 中运行脚本:./script.sh in.txtin.txt 中指定的文件夹名称现在应该可用。这假定 in.txt 中每行一个文件名,没有空格。

关于linux - 如何通过linux终端在文本文件中创建一个名为sth的文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49846611/

相关文章:

R 如何在 Linux 上获取 R 可用的内存量

ruby-on-rails - Secrets.yml 与 ENV 变量与选项?

OS X 中的 C++ spawn shell

c - 如何阻止 poll() 被特定信号中断

python ssh自动化脚本

php - 使用 PHP exec 命令和 scp 复制

ubuntu - 使用 Phusion Passenger (Nginx) 加密导致 SSL 握手中止

php - 如何使用 crontab 执行 Symfony 命令

macos - 使用 ffmpeg 连接多个视频和一个声音

ruby-on-rails - 用于 Rails 测试的编译缓冲区中的 Emacs shell 或终端转义字符