Linux may be easier to use than ever before, but you'll still need to open up a command line from time to time. That includes managing your storage, which isn't exactly easy to do in Linux, even with a visual file management application. Thankfully, you can accomplish just about anything directly from the terminal window, assuming you know a few basic commands.

Many storage commands in Linux have the ability to delete your data, which you can accidently do if you're not careful. Proceed with caution if you're a newcomer, and always remember to keep a backup of important data.

11 Getting around storage with Linux commands

The basics everyone should know

I'm not going to waste your time, nor the space of this article, giving every tiny Linux command its own section. If you're completely new, there are a handful of commands you should know to navigate around the file system from the command line:

  • cd change the working directory
  • cd ~ — go to home directory
  • cd .. — move up one level of your directory
  • cd - — go to previous directory
  • ls — list the content of a directory
  • pwd — shows your current working directory
  • rm and rmdir — remove a file or directory
  • cp — copy a file or directory
  • mv — move a file or directory

Those are the basics you need to even get around the Linux file system, and you should become well-acquainted with most of them if you use Linux for an extended period of time. Considering how many times you need to resort to a terminal to install and configure software, it's a good idea to have these memorized, as you'll often need to move files around from a terminal window.

Many storage commands require administrator privileges, so you'll need to enter "sudo" before your command, followed by your password.

10 mount

Get your drives working

mount-linux

One of the strange aspects of Linux for those coming from Windows is the fact that there are no drive letters. Drives are not special in the Linux file system. You simply mount them, and they become part of the directory. Instead of representing your drives as a drive, they're represented as a folder. And, short of your OS drive, you'll usually need to mount your drives manually.

In some distros, all you need to do is double-click the drive in question through the file manager window, but otherwise, you'll need the "mount" and "unmount" commands, followed by the drive and the directory you want to attach the file system to.

Arch Linux running AUR in a terminal window
I run these 4 commands first on every fresh Linux install

This is a good place to start if you're new to the platform.

20

9 fdisk

Quickly create and remove partitions

fdisk-linux

If you want to quickly create and manage your partitions, you can use fdisk. It gives you basic control over partitions, including creating and removing partitions, and changing the partition type. You don't have the option to extend or shrink a partition with fdisk, however — we'll get to that a bit later.

fdisk is an application that runs from the command line, and to start it up, you just need to enter the following:

fdisk /dev/[drive name]

After you've entered fdisk, you need to enter another command to do anything useful. There are a bunch of commands available, including advanced options, but here are a few to get you started:

  • m — print the help menu
  • n — create a partition
  • d — delete a partion
  • p — print the partition table
  • t — change partition type
  • w — write table to disk and exit
  • q — quit without saving changes
Command Prompt in Windows 11
16 lesser-known uses of Command Prompt

Do you know Command Prompt well? Think again! Check these 16-lesser known uses

7

8 parted

Extended partition management

parted-linux

You can also use the "parted" command to manage your partitions. GNU Parted gives you a few more options than fdisk, most notably the ability to quickly resize an existing partition. Just like fdisk, GNU Parted is a command line application that you'll need to start up before entering commands:

parted /dev/[drive name]

Once you're inside GNU Parted, you can enter commands to execute different functions, just like fdisk. Thankfully, the commands here are full words, making them a bit easier to remember and parse. Here are a few basics to get you started:

  • help — display a list of commands
  • mkpart — create a new partition
  • resizepart — resize an existing partition
  • rm — delete a partition
  • print — print the current partition table
  • quit — exit GNU parted, saving all changes
docmost running on ubuntu
5 software and tools for Linux that aren't available on Windows

Linux also has some exclusive tricks up its sleeve.

18

7 mkfs

For creating a new partition in an instant

mkfs-linux

You can manage your existing partitions with fdisk or GNU Parted, but if you just need to quickly partition a new drive after installing it, you can use the "mkfs" command to quickly set it up. The command should look something like this:

mkfs.xfs /dev/sda2

It should look like that, but you'll probably want to change the specifics of the command. Regardless, it should be "mkfs," followed by the file system type and the path to the drive you want to partition.

An image of the Windows Command Prompt in action.
Basic command line entries everyone should know

Make troubleshooting pain-free

6 partprobe

Let the OS know about your changes

partprobe-linux

Once you're done doing all your partition work, you need to update Linux about your changes, and you can do so with the "partprobe" command. To run it, enter the following:

sudo partprobe /dev/[drive name]

This will let the Linux kernel know about the changes made to your partitions in the event they aren't showing up after management is done. You don't always need to run this command, however. You can use "lsblk" to list your drives and partitions, and if you see everything there, you're good to go. If not, fall back on "partprobe."

A Windows desktop next to a Linux desktop
5 reasons I stopped dual-booting Windows and Linux on my PC

It's just not worth the hassle anymore.

52

5 swapoff and swapon

Get your swap on

swapon-linux

With Linux, you can set up a special place on a drive to handle swapping. In the event your RAM is filled, swapping allows your memory to store part of the data it needs on a disk and swap it out with data in memory as needed. Data in memory is stored in pages, and you can swap those pages in and out with your swap partition as needed. The "swapon" and "swapoff" commands allow you to turn on or off the swap partition. It looks like this:

sudo swapoff /dev/[partition name]

​​​​​​​Note that this command only turns swapping on or off for a partition that's already defined for swapping. If you want to remove or add a partition, you'll need to do so through the fstab configuration file, which is located at /etc/fstab on most distros.

Running VS Code on Ubuntu
4 Linux distros you should use instead of upgrading to Windows 11

Get rid of your Windows bad habit with one of these Linux distros.

45

4 du and df

See how much space your files take up

du-linux

Both the "du" and "df" commands allow you to see how much space files are taking up, but they have slightly different purposes. Starting with "du," its main purpose is to show the size of files and directories. You'll enter the command, followed by a flag, and finally a path or file name. Here are a few useful flags to get started:

  • -h — Print data in human-readable format, such as gigabytes
  • -c — Sum of all files in location, broken down by file and directory size
  • -s — Sum of all files in location without file and directory size

The "df" command, on the other hand, shows you how much free space is available. Similar to "df," you enter the command, followed by a flag, followed by the location of the drive. You'll want to use the "-h" flag here, as well, which will show the read-out in a human-readable format.

Red Star OS 3 running in a virtual machine, showing the app list and the
I used North Korea's leaked Linux distribution, and it still has secrets a decade later

Red Star OS 3 is a weird (and old) operating system, but it has some pretty interesting tech inside.

1

3 find

Locate a file, directory, and much more

find-linux

If you're looking for a particular file, you can use the "find" command. It allows you to search a specified path for a specific file, and after setting up the proper flags, your command should look something like this:

​​​​​​​find /path/XXX -name "file name"

Although the basic use case of "find" is to find a specific file, you can do a lot more with the command. Here are a few flags you can use to get some more use out of it:

  • -type — specify what you want to search for, such as "f" for files and "d" for directories
  • -mtime — limit the search to files or directories modified within a certain timeframe, such as "+30" to show files that haven't been modified in 30 or more days
  • -ls — lists the contents of a directory
  • -iname — allows searching for partial matches to a file or directory name.
Linux Mint 22.1
New to Linux? Here are 7 of the best beginner-friendly distros for you to try

Get up and running with Linux in no time.

22

2 locate

A faster find alternative

locate-linux

You can use "find" to track down a specific file, though it should hopefully be clear that it's a command capable of far more. If you want to just find a particular file, and need to do so quickly, you can use the "locate" command instead. It looks like this:

​​​​​​​locate filename.extension

​​​​​​​The difference between "find" and "locate" is that the latter searches a prebuilt database, while "find" can uncover new files during its search. If you need to update the database, you can do so by running the "updatedb" command.

run command window on Windows PC
100+ run commands that can help you work efficiently on Windows

Skip the clicks! Master these run commands to save your time running Windows

7