Just moved to Linux? Saying goodbye to Windows in favor of an open source alternative such as Ubuntu? Once you make the change, you'll find a sensible desktop that is easy to use, from installing new apps and launching them to organizing your data.

Managing files and folders in Linux is straightforward, whether you're using the desktop or the command line. Indeed, it can be quicker to use the Terminal input in many situations, so we’re going to take a look at what commands are available, and how they compare to the desktop, mouse-driven alternative.

The Terminal and Nautilus

As we're using Ubuntu 16.04 LTS to look at file management in Linux, we're going to be using Nautilus. This is the default file manager for Ubuntu, although others can be installed (although they cannot be easily set as defaults). To open Nautilus, all you need to do is click on the file icon in the Unity Launcher.

muo-linux-nautilus-terminal-fileview

The Terminal, meanwhile, is pretty much as you would expect it -- a black box with a prompt, and a flashing cursor waiting for a command. You can find this by clicking the Ubuntu Unity button, and typing terminal. The list of results should display a command line app, so click this to open.

List Your Files with ls

In the file manager, listing files is relatively simple. Just left-click to select the drive or directory you wish to view the contents of, and they will be displayed. Opening a sub-directory will display further contents.

Similarly, it's just as simple to view the contents of a directory in the Terminal. After you launch the command line, you'll be defaulted to your personal directory, Home. To view the contents enter:

        ls
    

This lists the files in the current directory. If you want to also see the contents of any sub-directories, use:

        ls -R
    

The -R switch indicates to the Terminal that you wish to observe a recursive list of sub-directories and their contents.

muo-linux-nautilus-terminal-ls

Individual directory contents can be listed, meanwhile, with ls /[DIRECTORY NAME]. So, for example:

        ls /Music
    

…will display the contents of the Music sub-directory.

Use cd to Change Directory

In the file manager, you can click directories in the left-hand panel to quickly get an overview of what files are stored where. Each time you select one of these directories, you're opening them, changing your position within the file management hierarchy.

The same effect is achieved in the command line using cd. For instance:

        cd Documents
    

…will change directory to the Documents sub-directory. If you prefer, however, you can specify a full filepath to open directories elsewhere on the drive.

        cd /etc/fonts
    

Meanwhile, you can go up a directory -- that is, for example, from Documents back to Home -- using:

        cd ..
    

Also, make sure you know about cd / -- this command will send you back to the default Home directory from any other.

Deleting Files and Directories

In the Terminal, file deletion is frighteningly simple; no confirmation is offered, so once you enter the command, the file is gone, for good (unless you employ recovery software to retrieve it.

To delete a file in the terminal, use rm, like this:

        rm myfile
    

You can also use the full path to the file you wish to delete:

        rm /path/to/myfile
    

The same action can be completed in the desktop environment by right-clicking the file and selecting the Delete option (in Ubuntu this is labeled Move to the rubbish bin). You can also simply select the file and hit the Delete button on your keyboard. The same is true for directories -- but make sure there's nothing inside that you need to keep!

muo-linux-nautilus-terminal-rm

Removing a directory in the Terminal requires the rmdir command:

        rmdir mydirectory
    

Again, a full path specification can be included to delete a directory from another location on the directory tree:

        rmdir /path/to/mydirectory
    

To delete a directory and its contents, use the -r condition. Again, using the command line with rm won't offer confirmation, so use with care!

Move and Copy with mv and cp

If you need to move a file in the Terminal, the mv command is your friend. Simply employ it with the name of the file you wish to move, and its new directory:

        mv myfile /home/mydirectory
    

To perform this action in the GUI, right-click the file and select Move To....

Rather than move a file, you may prefer to copy it. This is done using the cp bash command, with sudo, like this:

        sudo cp myfile /home/mydirectory
    

You might also copy a directory and its contents with the -r recursive condition:

        sudo cp -r /home/mydirectory /home/otherdirectory
    

This command copies the contents of "mydirectory" and drops them into "otherdirectory".

Make Directories in the Terminal with mkdir

Creating a new directory in the Terminal is also very simple, thanks to the mkdir command (which you've probably guessed abbreviates the term "make directory").

        mkdir newdirectory
    

…will create a new directory with that name in the current location.

muo-linux-nautilus-terminal-mkdir

You can also use the command to create a directory elsewhere:

        mkdir /home/mydirectory/newdirectory
    

On the GUI side of things, you can use the mouse-driven file explorer to create directories by right-clicking into the file browser window and selecting the New Folder option.

Command Line or Desktop?

Navigating through a computer's directory tree is how we find the files and folders we use regularly. But one other thing is worth sharing: how to create a desktop link (known in Windows as a shortcut).

While such links cannot be used in the Terminal, they can be created, using ln -s:

        ln -s /home/mydirectory/newdirectory /home/mydirectory/Desktop
    

Here, a link is made from the "newdirectory" folder to the Desktop, from where it can be opened. This should save you time finding important directories. You can do the same in the file manager by right-clicking and selecting Make Link.

muo-linux-nautilus-terminal-ln

Do you find the command line or the desktop most efficient and user friendly? Have we opened your eyes to the flexibility and power of the command line options in Linux? Tell us about it -- the comments box awaits!