Answered by the Webhosting Experts

Linux
Managed Services

Just Leave Linux to Us
Is maintaining your Linux server keeping your team bogged down? Alleviate unnecessary stress with one of Hivelocity’s Linux Managed Services plans. With reboots, monitoring, updates, and more, your team can rest easy knowing your hardware and OS are in the hands of hosting experts.

Configure your server today and see the benefits a Hivelocity managed Linux solution can offer you!

Tags
...
...

How to Open, Edit, Move, and Copy a File in Linux

In this tutorial we’ll cover how to open, edit, move, and copy a file within Linux using the terminal window and a few basic commands.

Use the the table of contents below to jump to a specific section or read on to learn more!

 

How to Open a File in Linux

To learn how to open a file in Linux using the terminal, just follow these simple steps:

  1. While there are multiple ways to open a file in Linux, the easiest way to display the contents of a file is using the cat command. For example, lets say you have a text file named SampleText.txt, which contains a single string of text saying “This is a test file.” Use the cat command followed by the name of the file you want to open, like this:
     
    cat SampleText.txt
     
    You should receive an output to the terminal containing the text, “This is a test file.” If the file had contained more text than this, all of it would have been displayed.
     
  2. While the example used above contains only one line of text, for large or multipage documents, it may be cumbersome to attempt to open their entire contents in the terminal at once. This is where the less command comes in handy. By using the less command, you can have Linux display the contents of your file one page at a time. Use it the same way you would use the cat command:
     
    less SampleLongText.txt
     
    This command would then output the contents of the SampleLongText.txt file, one page at a time, allowing you to scroll to view more.

 

How to Edit a File in Linux

To learn how to edit a file in Linux using the terminal, just follow these steps: 

  1. There are several different tools within Linux that can be used to edit files. The two most popular are Vi (or Vim) and Nano. While each has its advantages, the biggest differences between the two are ease-of-use and functionality. Vi is a more powerful and complicated tool, and Nano is simpler but can do less. We’ll start with Nano.
     
  2. To open a file in Nano, you must enter the nano command followed by the path of the file you are attempting to open. You may also first navigate to the proper directory using the cd command, then open the file for editing just using nano followed by the filename. For example:
     
    nano SampleText.txt
     
    If the file specified already exists, it will be opened for editing. If no file exists with this name at this location, a new file will be created.
     
    1. One of the advantages of Nano is, it features a list of shortcuts at the bottom of its interface. This allows users to use the tool without having to memorize every command, making it ideal for those who are newer to Linux. Arrow keys can be used for navigation, and the backspace key is used to delete. All-in-all, Nano works like a simplified but familiar text editor.
       
  3. The other popular option for editing a file in Linux is to use the vi command. Like nano, vi must be followed either by a specific file path, or if you’re already within the desired directory, just the file name can be used. For example:
     
    vi SampleText.txt
     
    The primary difference between Vi and Nano is that Vi features different modes, allowing users to interact with the document in different ways. While this gives a greater degree of control over the document, it can also be very confusing and somewhat counter-intuitive for those new to the tool.
     
    1. The default mode that you enter Vi in is the Command mode, used for navigation and entering commands. Like Nano, Vi uses the arrow keys for navigation. However unlike Nano, any text entered into Vi won’t be treated as a string of text being added to the document, but rather a command being relayed directly to Vi. We’ll cover some of these commands below.
       
    2. To add text to the document, you must first enter Insert mode. To enter Insert mode, move your cursor to the location where you’d like to enter new text, then press the i key. You’ll see the phrase “INSERT” appear in the bottom left corner of your screen. Now, any text you enter will be treated as a string of text being added to the document. To return to Command mode, hit the Esc key a few times. You’ll know you’ve exited Insert mode when the “INSERT” phrase disappears from the bottom corner.
       
    3. Unlike Nano, to delete a character in Vi, you must use the x key while in Command mode. This will delete whichever character is currently highlighted by the cursor.
       
    4. To enter a command in Vi, you must first start with a colon “:”. For example, to save (or write to) a file that you’ve made edits to, use the :w command. To quit Vi, use the :q command. To save and quit all at once, combine both commands into :wq. You can add an exclamation point “!” to any command to force it. For example, :q! would force Vi to quit, overriding any confirmation screens that may otherwise be triggered.
       
    5. For a list of available navigation shortcuts, check out this post on Editing Files with Vi. Scroll to the bottom for a full list of additional movement and editing options.

 

How to Move a File in Linux

To learn how to move a file in Linux using the terminal, just follow these easy steps:

  1. First, it is important to understand that moving a file in Linux and renaming it are the same action. This is because when you are moving a file to a new location within Linux, you are really renaming its filepath to include new information.
     
  2. To move a file in Linux, use the mv command followed by the source location and then the intended destination. For example, if you wanted to move the file SampleText.txt from it’s current location in the home directory to a new location in the /tmp directory, you would do so with the following command:
     
    mv SampleText.txt /var/tmp
     
    You can even rename the file as it’s being moved. Doing so would look similar to this:
     
    mv SampleText.txt /var/tmp/NewSampleText.txt
     
    Or, if you wanted to rename the file without moving it to a new location, you could simply repeat the above command while omitting the “/var/tmp/”.

 

How to Copy a File in Linux

To learn how to copy a file in Linux using the terminal, just follow these steps:

  1. To copy a file in Linux, just use the cp command followed by the name of the source file and then the new file. For example:
     
    cp SampleText.txt SampleText_2.txt
     
    The above command would generate a new file, named SampleText_2.txt, which contains all the contents of the previous file. By default, this new file will be created in the same directory as your current file, unless otherwise specified. If you’d like to copy the file to a new directory, you can use the desired filepath instead of the second file name, or include both to copy the file to a new location under a new name. For an idea of what this would look like, see the section above covering the mv command, but use the cp command instead.

 

Popular Links

Looking for more information on Linux? Search our Knowledge Base!

Interested in more articles about Operating Systems? Navigate to our Categories page using the bar on the left or check out these popular articles:

Popular tags within this category include: Linux, Windows, Apache, CentOS, Debian, Fedora, RedHat, and more.

Don’t see what you’re looking for? Use the search bar at the top to search our entire Knowledge Base.

 

The Hivelocity Difference

Seeking a better Dedicated Server solution? In the market for Private Cloud or Colocation services? Check out Hivelocity’s extensive list of products for great deals and offers.

With best-in-class customer service, affordable pricing, a wide-range of fully-customizable options, and a network like no other, Hivelocity is the hosting solution you’ve been waiting for.

Unsure which of our services is best for your particular needs? Call or live chat with one of our sales agents today and see the difference Hivelocity can make for you.

Share

Facebook
Twitter
LinkedIn
Email
WhatsApp

Need More Personalized Help?

If you have any further issues, questions, or would like some assistance checking on this or anything else, please reach out to us from your my.hivelocity.net account and provide your server credentials within the encrypted field for the best possible security and support.

If you are unable to reach your my.hivelocity.net account or if you are on the go, please reach out from your valid my.hivelocity.net account email to us here at: [email protected] We are also available to you through our phone and live chat system 24/7/365.

Rapid Restore

Backup your entire server’s data every night and have access to 5 days of rolling restore points.  Restore your server’s data, OS and configuration any time you need it.

Our Rapid Restore service saves the day during accidental data loss, hardware failures and virus contraction. Simply pick your recovery point and restore the data from that day. 

DDoS Protection

While our competitors may advertise DDoS protection, most often, they are merely implementing easily evaded router rules or simply black-holing targeted servers. They consider this “DDoS protecting their network.” However, neither of these solutions should give comfort to any online business. Should your site be attacked, chances are likely both of these options will end with your server being taken offline. At Hivelocity, we take the responsibility of keeping your servers online very seriously. For this reason, we offer two very serious forms of DDoS protection.

FREE

Every solution we provide includes our Filtering Edge of Network System (FENS). FENS is a series of proprietary systems that proactively monitors and protects the entire Hivelocity Network from most common Denial of Service (DOS) and Distributed Denial of Service (DDoS) attacks.

$15/MONTH PER SERVER

For an extra fee, you can enhance your server’s protection further with the addition of our Server Defense System. Our Server Defense System sits in front of your server, inspecting inbound data and looking for malicious traffic. The moment an attack is detected, it instantly begins scrubbing each data packet. Hivelocity’s Server Defense System delivers business continuity even in the face of massive and complex attacks.

Our Server Defense System is like adding an alarm and armed guard to your business, alerting you to and destroying anything attempting to jump that fence. Our Server Defense System utilizes internally developed proprietary systems in addition to Corero’s Threat Defense Smartwalls for data packet scrubbing. Each of our data centers is a scrubbing center with Corero Smartwalls on-premise, allowing us to provide on-prem zero-lag data scrubbing.

SSL Certificates

The security of your online commerce and protecting your customers’ data is as important to us as it is to you. When your customers see the green bar, they will know their connection to you is protected. We offer single domain, multi-domain, and wild-card certificates.

We offer industry leading 128-bit encryption certificates, allowing you to conduct e-commerce with complete security. Inspire confidence in your customers by displaying any number of seals and indicators certifying that your site is secure.

Load Balancing

Adding this service to two servers with identical content will allow you to distribute your load evenly across your hardware. Don’t lose business because you couldn’t handle the demand. Load balance and handle your biggest resource spikes with ease.

Firewalls

Stop attacks, prevent unauthorized access, and achieve regulatory compliance. Our Juniper hardware firewalls offload the work so your server never has to consume resources protecting itself from malicious traffic. A single firewall can be used to protect multiple servers.

Cloud Storage

Cloud storage offers users redundancy and easy accessibility, ensuring your data remains secure and readily available. Scale to as much as you need for only a 20¢/GB.

Cloud Storage is distributed and replicated across many servers, protecting your data from hardware failure. Highly scalable, it can handle thousands of client connections via TCP/IP. Connect to your virtual drive with SFTP, FTP, and SSHMount and in the future NFS and AFP. Cloud Storage is based on a stackable design which is upgradeable up to 2TB per instance.