How to Edit Files in Linux: A Comprehensive Guide

Linux is a powerful and versatile operating system, widely used by developers, system administrators, and enthusiasts. When working with Linux, understanding how to manipulate files is a fundamental skill. In this guide, we will focus on command-line utilities.

Will These Commands Work In My Distro?

These commands should work in most distros.

If not, there is sure to be a guide available that caters directly to your distribution.

Be Careful!

Some of these commands, if incorrectly used, could have unforeseen consequences. Including destroying your operating system or irrecoverably deleting files. It is best to practise on a non-vital system first. The easiest way is to set up a distro in a VM.

How to Rename a File in Linux

Screenshot of Linux showing command how to rename file.

To rename a file in Linux, you can use the mv command (short for “move”). The syntax is as follows:

mv old_filename new_filename

For example, to rename a file called “oldfile.txt” to “newfile.txt,” you would use:

mv oldfile.txt newfile.txt

How to Delete a File in Linux

Screenshot of Linux showing command how to remove file.

To delete a file in Linux, you can use the rm command (short for “remove”). Be cautious when using this command, as deleted files are not typically recoverable. The basic syntax is:

rm filename

For example, to delete a file called “unwanted.txt,” you would use:

rm unwanted.txt

How to Find a File in Linux

Screenshot from Linux showing command how to find file.

To find a file in Linux, you can use the find command. The basic syntax for searching a file by name is:

find /path/to/search -name "filename"

For instance, to find a file named “important.doc” starting from the root directory, you would run:

find / -name "important.doc"

How to Copy a File in Linux

Sctreenshot from Linux showing command how to copy file.

Copying files in Linux can be accomplished using the cp command (short for “copy”). The syntax is as follows:

cp source_file destination_directory

For example, to copy a file named “document.txt” to a directory called “backup,” you would use:

cp document.txt backup/

How to Create a File in Linux

Screenshot from Linux showing command how to copy file.

You can create an empty file in Linux using the touch command. To create a file named “newfile.txt,” simply run:

touch newfile.txt

How to Edit File Permissions in Linux

Screenshot from Linux showing command how to edit file permission.

File permissions in Linux dictate who can read, write, or execute a file. You can change file permissions using the chmod command. For example, to give the owner of a file full read, write, and execute permissions, you can use:

chmod 700 filename

How to Zip and Unzip Files in Linux

Screenshot from Linux showing command how to zip file.

To zip files in Linux, use the zip command:

zip compressed_file.zip file1 file2

To unzip a compressed file, use the unzip command:

unzip compressed_file.zip

How to Compress Files in Linux

Screenshot from Linux showing command how to compress file.

You can compress files in Linux using various compression tools, such as gzip, bzip2, or tar. For example, to gzip a file named “data.txt,” use:

gzip data.txt

How to Move a File in Linux

Screenshot from Linux showing command how to move file.

To move a file in Linux, use the mv command, as shown in the renaming section. You can also move files to a different directory by specifying the destination directory:

mv file_to_move /path/to/destination/

How to Make a File Executable in Linux

Screenshot from Linux showing command how to make file executable.

To make a file executable in Linux, you can use the chmod command. For instance, to make a script named “myscript.sh” executable, you would use:

chmod +x myscript.sh

How to Change the Owner of a File in Linux

Screenshot from Linux showing command how to change owner of file.

To change the owner of a file in Linux, use the chown command. The basic syntax is:

chown new_owner:group filename

For example, to change the owner of a file named “data.txt” to the user “mo,” you would run:

chown mo:data data.txt

How to Find Files Recursively in Linux

Screenshot from Linux showing command how to find file recursively.

The find command can be used to search for files recursively within a directory and its subdirectories. For example, to find all files with the “.log” extension under the “/var/log” directory:

find /var/log -name "*.log"

How to Search for Files on Linux

Screenshot from Linux showing command how to search for files.

The grep command allows you to search for specific content within files. For instance, to search for the word “VPN” in all text files within a directory:

grep -r "VPN" /path/to/directory

How to Check File Size in Linux

Screenshot from Linux showing command how to check file size.

To check the size of a file in Linux, you can use the ls command with the -lh option, which displays file sizes in a human-readable format:

ls -lh filename

How to Split Files in Linux

Screenshot from Linux showing command how to split files.

You can split a large file into smaller pieces in Linux using the split command. For example, to split a file named “largefile.txt” into smaller files with 1MB each:

split -b 1M largefile.txt

How to Count Lines in a File on Linux

Screenshot from Linux showing command how to count lines in file.

To count the number of lines in a file in Linux, you can use the wc command with the -l option:

wc -l filename

Now practise!

Learning how to manipulate files in the command line isn’t as important as it used to be thanks to great graphical options. But it is by far the most efficient and powerful way to interact with Linux files and will serve you well to learn these commands if you plan on using Linux as your daily driver.


We love bringing you this content and hope it helps keep you safe and secure online. Feel free to share it with your friends, too.

Here at hide.me we are all about internet freedom, and we are happy to be in a position to bring that to everyone. That is why we give you a 30-day money-back guarantee on our Premium plan. No questions asked and no logs recorded.

Get hide.me VPN!

If you have any questions, please feel to contact our 24/7 support team either at support@hide.me or via live chat.

Related articles