Linux 中的 > 、 <

本文深入解析了重定向符的功能和用法,包括单大于号(&gt;)、双大于号(&gt;&gt;)及单小于号(&lt;)的作用。单大于号用于覆盖文件内容,双大于号用于追加内容至文件末尾,而单小于号则用于输入重定向。

单大于号

 > file

">" 单大于号,重定向符,没有命令在它之前,这会删除一个已存在文件的内容或是创建一个
新的空文件,作用是覆盖文件,将左侧的内容覆盖有右侧。上面命令由于左侧没有内容,因此将file清空了。如果有两个文件file1和file2,执行 cat file1 > file2,则将文件1的内容覆盖掉文件2的。因此">"左侧可以使用其它命令组合并将输出当做右侧文件的输入。

 

双大于号

file1 >> file2

用于覆盖,将左侧文件内容追加到右侧文件中。使用方式和单大于号相同。

 

单小于号

command < input

表示的是输入重定向的意思,就是把<后面跟的文件取代键盘作为新的输入设备。

<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build"> <PropertyGroup> <ProjectType>local</ProjectType> <ProjectVersion>7.10.377</ProjectVersion> <SchemaVersion>2.0</SchemaVersion> <ProjectGuid>{ADC5A455-0A27-4553-B7AA-BF869BCD8EB1}</ProjectGuid> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <AssemblyName>LinuxCmd</AssemblyName> <OutputType>WinExe</OutputType> <TargetFrameworkVersion>v2.0</TargetFrameworkVersion> <IsWebBootstrapper>false</IsWebBootstrapper> <PublishUrl>publish\</PublishUrl> <Install>true</Install> <InstallFrom>Disk</InstallFrom> <UpdateEnabled>false</UpdateEnabled> <UpdateMode>Foreground</UpdateMode> <UpdateInterval>7</UpdateInterval> <UpdateIntervalUnits>Days</UpdateIntervalUnits> <UpdatePeriodically>false</UpdatePeriodically> <UpdateRequired>false</UpdateRequired> <MapFileExtensions>true</MapFileExtensions> <ApplicationRevision>0</ApplicationRevision> <ApplicationVersion>1.0.0.%2a</ApplicationVersion> <UseApplicationTrust>false</UseApplicationTrust> <BootstrapperEnabled>true</BootstrapperEnabled> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> <PlatformTarget>x86</PlatformTarget> <DebugSymbols>true</DebugSymbols> <DebugType>full</DebugType> <Optimize>false</Optimize> <OutputPath>bin\Debug\</OutputPath> <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> <PlatformTarget>x86</PlatformTarget> <DebugType>pdbonly</DebugType> <Optimize>true</Optimize> <OutputPath>bin\Release\</OutputPath> <DefineConstants>TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <PropertyGroup> <StartupObject>LinuxCmd.Program</StartupObject> </PropertyGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <ItemGroup> <Compile Include="Properties\Resources.Designer.cs"> <AutoGen>True</AutoGen> <DesignTime>True</DesignTime> <DependentUpon>Resources.resx</DependentUpon> </Compile> <EmbeddedResource Include="LinuxCmd\frMain.resx"> <DependentUpon>frMain.cs</DependentUpon> </EmbeddedResource> <EmbeddedResource Include="Properties\Resources.resx"> <Generator>ResXFileCodeGenerator</Generator> <LastGenOutput>Resources.Designer.cs</LastGenOutput> </EmbeddedResource> <Reference Include="NAudio, Version=1.7.2.19, Culture=neutral, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> <HintPath>.\NAudio.dll</HintPath> </Reference> <Reference Include="SDK, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> <HintPath>.\SDK.dll</HintPath> </Reference> <Reference Include="System.Windows.Forms" /> <Reference Include="System" /> <Reference Include="System.Drawing" /> <Compile Include="AssemblyInfo.cs" /> <Compile Include="Global.cs" /> <Compile Include="LinuxCmd\LinuxEvent.cs" /> <Compile Include="LinuxCmd\BluetoothScanEvent.cs" /> <Compile Include="LinuxCmd\frMain.cs"> <SubType>Form</SubType> </Compile> <Compile Include="LinuxCmd\LinuxUdp.cs" /> <Compile Include="LinuxCmd\PlayController.cs" /> <Compile Include="LinuxCmd\Properties\Resources.cs" /> <Compile Include="LinuxCmd\DevItem.cs" /> <Compile Include="LinuxCmd\AudioEvent.cs" /> <Compile Include="LinuxCmd\RTPManager.cs" /> <Compile Include="LinuxCmd\WaveRecordDataHandler.cs" /> <Compile Include="LinuxCmd\RecordController.cs" /> <Compile Include="LinuxCmd\WaveRecorder.cs" /> <Compile Include="LinuxCmd\WaveErrorEventHandler.cs" /> <Compile Include="LinuxCmd\ATClient.cs" /> <Compile Include="LinuxCmd\LinuxSendSocket.cs" /> <Compile Include="LinuxCmd\Program.cs" /> <Compile Include="LinuxCmd\AudioManager.cs" /> <Compile Include="LinuxCmd\UdpBrocast.cs" /> <Compile Include="LinuxCmd\Properties\Settings.cs" /> <EmbeddedResource Include="LinuxCmd.Properties.Resources.resources" /> <EmbeddedResource Include="LinuxCmd.frMain.resources" /> </ItemGroup> <ItemGroup> <Content Include="LinuxCmd.ini"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> </ItemGroup> <ItemGroup> <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1"> <Visible>False</Visible> <ProductName>.NET Framework 3.5 SP1</ProductName> <Install>true</Install> </BootstrapperPackage> </ItemGroup> </Project>
最新发布
07-11
资源标识符冲突错误 `CS1508` 通常发生在 C# 项目中,当两个或多个资源文件被编译为相同的资源标识符时触发。在用户提供的上下文中,标识符为 `LinuxCmd.frMain.resources`,表明此资源名称已在程序集中重复使用。 为了避免此类冲突,应确保所有 `.resx` 文件的资源标识符唯一,并正确配置生成操作和命名空间。以下是一些具体的解决方案: ### 确保资源文件命名唯一 每个资源文件应具有唯一的命名空间和资源名称。例如,避免不同窗体共享相同名称的 `.resx` 文件,如 `frMain.resx`。如果存在多语言支持(如 `fr-FR` 或 `en-US`),则应在文件名中明确区分,例如 `frMain.en-US.resx` 和 `frMain.fr-FR.resx` [^1]。 ### 检查并修改资源标识符 在 Visual Studio 中打开资源文件属性页,检查其 `Custom Tool Namespace` 和 `Resource Name` 属性,确保它们不会与其他资源文件产生冲突。若发现重复项,手动更改命名空间或资源名称以消除冲突 [^1]。 ### 设置正确的生成操作 选中资源文件,在属性窗口中将 `Build Action` 设置为 `Embedded Resource` 或 `Content`,同时确保 `Custom Tool` 设置为 `ResXFileCodeGenerator` 或留空以避免自动生成代码导致冲突 [^1]。 ### 清理并重新添加资源文件 删除当前导致冲突的资源文件,然后重新添加,并确保其与对应的类文件正确绑定。对于 Windows Forms 应用程序,应确认 `.Designer.cs` 文件是否包含正确的资源标识符声明 [^1]。 ### 手动编辑项目文件 (.csproj) 通过文本编辑器打开 `.csproj` 文件,查找是否有重复的 `<EmbeddedResource>` 条目。如果有,请删除重复项并保存文件后重新加载项目 [^1]。 ### 使用命令行工具验证资源冲突 可以使用 `resgen` 工具将 `.resx` 转换为 `.resources` 并检查输出路径是否冲突: ```bash resgen LinuxCmd.frMain.resx ``` --- ### 示例:如何确保资源文件唯一性 以下是一个 `.csproj` 片段,展示如何定义唯一的资源文件条目: ```xml <ItemGroup> <EmbeddedResource Include="Resources\MyForm.en-US.resx"> <Generator>ResXFileCodeGenerator</Generator> <LastGenOutput>MyForm.en-US.Designer.cs</LastGenOutput> <SubType>Designer</SubType> </EmbeddedResource> <EmbeddedResource Include="Resources\MyForm.fr-FR.resx"> <Generator>ResXFileCodeGenerator</Generator> <LastGenOutput>MyForm.fr-FR.Designer.cs</LastGenOutput> <SubType>Designer</SubType> </EmbeddedResource> </ItemGroup> ``` 上述配置确保了不同语言版本的资源文件不会产生标识符冲突 [^1]。 --- ### 相关问题 1. 如何在C#项目中正确管理多语言资源文件? 2. C#中如何通过代码访问嵌入式资源? 3. Windows Forms项目中如何避免.Designer.cs文件引发的资源冲突?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值