pctechguide.com

  • Home
  • Guides
  • Tutorials
  • Articles
  • Reviews
  • Glossary
  • Contact

Find, View and Delete Files and Directories Using Linux Commands

Most basic Linux file and directory management – creating, renaming, moving and copying – can be achieved with the use of just three Linux commands. Their use is fairly straightforward, though it’s probably a good idea to be reasonably familiar with the Linux directory structure before getting too adventurous with file work (or download Knoppix to test drive Linux).

To rename a file, we use the mv command, giving two arguments. The first is the current name of the file, and the second is the name to change the file to.

$ mv oldname.txt newname.txt

Here the file oldname.txt is renamed to newname.txt. The same absolute and relative rules apply when addressing files here, so the file oldname.txt has to be in the current working directory.

Moving a file is achieved using the same command.

$ mv something.txt newplace/something.txt

This will move the file something.txt from the current directory to the directory newplace. The directory has to exist, and we’ll look at creating directories in a moment.

It might be worth pointing out that using the mv command can achieve both moving a file and renaming it at the same time, like this.

$mv oldname.txt newplace/newname.txt

So we come to copying files. This is done using the cp command.

$ cp this.txt there.txt

In this example the file this.txt is copied to file there.txt. This is extremely useful for creating backups of files before editing them. The convention in this case is to use a .BAK extension.

$ cp important.txt important.txt.B

In this last part of our brief run through of basic Linux commands for directory structure and manipulation, we’ll cover some final everyday operating system tasks: to find, view and delete files and directories. As with all Linux commands, they can seem a little strange when we’re used to mouse point and click operation of our operating systems, but with just a little practice they become very familiar, particularly once the directory structure is clear in mind.

Linux Commands: Finding files

Finding files is always going to be necessary, especially when you’re unfamiliar with an operating system. The first thing to do is to build the search index for the operating system.

$ updatedb

This command will have the operating system building a database of the files on the system. It may take a while, but be patient. You’ll need to keep updating the database as new files and applications are added, or it will become out of date. You can set up the updating of the database to happen automatically with a cron job, but we’ll come to that later. For now, entering this command will make sure that the files are all ready to be searched.

Then, to find a file, or directory, use the locate command.

$ locate yourfile.txt

This will search the system for the file yourfile.txt, and will present the absolute location of it in the results. Sometimes, you may want to search for a substring of a filename. This is possible, but it may return an awful lot of results.

$ locate txt

This will return every file that includes txt anywhere in the name, not just the extension. The results can be vast, so in this case it can be useful to pipe the command to a less command.

$ locate txt | less

This will return exactly the same search results, but will present them in a more manageable format using less. That way you can navigate up and down the list of results until you find what you’re after. Press q to quit less and return to the command prompt when you’re finished.

Linux Commands: Viewing files

To view a file’s contents we can use the less command. For instance, if we have a text file info.txt, we’d type the following.

$ less info.txt

This will present the text in the file for reading. We can use the arrow keys to navigate around large files, and the page up, page down, home and end keys too. Note that in Linux there are many text files with many different extensions, but typically .conf and .ini files are worth looking at. Reading through these files (very often in the /etc directory) can start to give some inkling of how the operating system and various applications are working as they are often very well commented.

When you have finished looking at a file, simply press the q key to quit. Note that the less command will not allow you to edit files, which is something that we will come to.

Linux Commands: Deleting Files

Deleting files is achieved with the rm command, as long as you have permissions. Deleting a single file is straightforward.

$ rm thisfile.txt

With this command the file thisfile.txt will be deleted. The power of this command can be extended with the use of wildcards. For instance, if you want to delete all the files in a directory that end with .txt, you can use the following command.

$ rm *.txt

The * character can represent any number of characters, so that in this example all files that end with .txt will be matched. Obviously you need to take a lot of care using this facility.

Linux Commands: Deleting Directories

The rmdir command can be used to delete directories as follows.

$ rmdir [directory]

Note, though, that this will only work if the directory is empty of files. To empty a directory that contains files you need to use the following command format.

$ rm -r [directory]

The -r option tells the operating system to delete the directory and everything in it. This is clearly something to be very careful of! Notice, too, that rmdir is used for empty directories, but rm -r for directories that contain files.

You now know how to log on to your server, set up a user account for yourself, and navigate the file system with a set of basic Linux commands. Next we’ll look at how to edit text files with vi, and so make a start on setting up our dedicated server.

AK

Notice that the previous file extension of .txt has been kept, which isn’t necessary but just means that you won’t forget it.

Finally a point on the tilde character, ~. This is a special character that represents the current user’s home directory, and can provide a useful shorthand. For instance, take this command:

$ cp thisfile.txt ~

This will copy the file thisfile.txt into the home directory. This applies to mv too.

$ mv thisfile.txt ~

This moves the file to the home directory. It’s useful to remember, then, that the tilde ~ character means home.

Creating Directories

Organising your file system is hugely important so there will be times when you need to make directories for your files. This is done using the mkdir command. The argument is the name and location of the new directory, and the location can, as usual, be absolute or relative.

$ mkdir [directory]

As long as you have permission, this command will create a subdirectory, relative to the current directory, called whatever name you give it.

  • Advantage to Shared Web Hosting
  • Shared Hosting Issues – Shared Bandwidth and Server Resources
  • The Ins and Outs of Dedicated Web Hosting
  • When To Move To A Dedicated Server
  • Choosing a Dedicated Server for your Website
  • Managing and Operating a Dedicated Server Over the Internet Using Online Control Panels
  • Accessing the Linux Operating System on Dedicated Servers with PuTTY or SSH
  • How to Create a Secure Password
  • Using Sudo for Super User Access to Root Privileges in Linux
  • The Linux Directory Structure
  • Linux Commands for Navigating and Viewing Directories
  • Creating, Moving, Renaming and Copying Files and Directories in Linux
  • Find, View and Delete Files and Directories Using Linux Commands
  • Using vi to Edit Text Files on A Linux Dedicated Server

Filed Under: Moving from Shared to Dedicated Web Hosting Tagged With: how to delete directories in Linux, how to delete files in Linux, how to find files in Linux, how to view files in Linux

Latest Articles

Disclaimer

Brain Box Consultants LLC Web Site Agreement The pctechguide.com Web Site (the "Site") is an online information service provided by Brain Box Consultants LLC ("pctechguide.com "), subject to your compliance with the terms and conditions set forth below. PLEASE READ THIS DOCUMENT CAREFULLY … [Read More...]

AMD Barton

In February 2003, AMD introduced the first processor based on the new Athlon XP core, codenamed Barton. While this Athlon 3000+ chip had all the features of previous Athlon XP processors, the new core allowed it to boast a more efficient memory … [Read More...]

A Cool Computer– Fans and Overclocking

Heat and computers do not get along. A cool computer runs more smoothly and efficiently. A computer that can not rid itself of heat properly can actually underperform and over a long period of time it can result in damage to the computer. This can significantly shorten the lifespan of the computer. … [Read More...]

Importance of Inbound Marketing in the Digital Age

A couple of months ago, Zacks reported that Hubspot was starting to make some major changes to its inbound marketing strategy. They talk a lot about … [Read More...]

Damage Control Strategies for Resolving Online PR Crises

Last July, Astrologer faced a major crisis after its CEO went viral at a ColdPlay concert when having an affair. This was just one of the many times a … [Read More...]

AI is Not Killing Computer Jobs Like Doomers Projected

There is no denying the reality that AI technology has played a massive role in disrupting our lives. A growing number of people claim that AI … [Read More...]

Everything You Need to Know About Sourcing Circuit Boards From U.S. Suppliers

In This Article This article includes: Why Source PCBs From the United States?How to Get a Quote From a U.S.-Based PCB ManufacturerThe Top U.S. … [Read More...]

Top Taplio Alternatives in 2025 : Why MagicPost Leads for LinkedIn Posting ?

LinkedIn has become a strong platform for professionals, creators, and businesses to establish authority, grow networks, and elicit engagement. Simple … [Read More...]

Shocking Cybercrime Statistics for 2025

People all over the world are becoming more concerned about cybercrime than ever. We have recently collected some statistics on this topic and … [Read More...]

Guides

  • Computer Communications
  • Mobile Computing
  • PC Components
  • PC Data Storage
  • PC Input-Output
  • PC Multimedia
  • Processors (CPUs)

Recent Posts

CMOS – complementary metal oxide silicon – RAM chips on motherboards

Motherboards also include a separate block of memory made from very low power consumption CMOS (complementary metal oxide silicon) RAM chips, … [Read More...]

Dysfunctional Hard Drive Diagnostics – Part 2

We previously wrote an article on issues that you may encounter with a hard drive. You need to take the right steps to diagnose the issue. Some of the … [Read More...]

Simple Data Encryption and Boost Protection

Nowadays it is more important than ever to have security and protection over all aspects of your PC. We've learned the hard way that even wealthy … [Read More...]

[footer_backtotop]

Copyright © 2026 About | Privacy | Contact Information | Wrtie For Us | Disclaimer | Copyright License | Authors