How-To Geek

How to Manage Files from the Linux Terminal: 11 Commands You Need to Know

To use the Linux terminal like a pro, you’ll need to know the basics of managing files and navigating directories. True to the Unix philosophy, each command does one thing and does it well.

Midnight Commander, a full-featured file manager for the Linux terminal, acts as a powerful front end to all these commands.

ls – List Files

The ls command lists the files in a directory. By default, ls lists files in the current directory.

You can also list files recursively — that is, list all files in directories inside the current directory — with ls -R.

ls can also list files in another directory if you specify the directory. For example, ls /home will list all files in the /home directory.

cd – Change Directory

The cd command changes to another directory. For example, cd Desktop will take you to your Desktop directory if you’re starting from your home directory.

You can also specify a full path to a directory, such as cd /usr/share to go to the /usr/share directory on the file system.

cd .. will take you up a directory.

rm – Remove Files

The rm command removes files. Be careful with this command — rm doesn’t ask you for confirmation.

For example, rm file would delete the file named “file” in the current directory. Like with other commands, you could also specify a full path to a file: rm /path/to/file would delete the file at /path/to/file on your file system.

rmdir – Remove Directories

The rmdir command removes an empty directory. rmdir directory would delete the directory named “directory” in the current directory.

If the directory isn’t empty, you can use a recursive rm command to remove the directory and all files in it. rm -r directory would delete the directory named “directory” and all files in it. This is a dangerous command that could easily delete a lot of important files, so be careful when using it. It won’t ask for confirmation.

mv – Move Files

The mv command moves a file to a new location. This is also the command you’ll use to rename files. For example, mv file newfile would take the file named “file” in the current directory and move it to the file named “newfile” in the current directory — renaming it, in other words.

Like with other commands, you can include full paths to move files to or from other directories. For example, the following command would take the file named “file” in the current directory and place it in the /home/howtogeek folder:

mv file /home/howtogeek

cp – Copy Files

The cp command works the same way as the mv command, except it copies the original files instead of moving them.

You can also do a recursive copy with cp -r. This copies a directory and all files inside it to a new location. For example, the following command places a copy of the /home/howtogeek/Downloads directory into the /home/chris directory:

cp -r /home/howtogeek/Downloads /home/chris

mkdir – Make Directories

The mkdir command makes a new directory. mkdir example will make a directory with the name “example” in the current directory.

ln – Create Links

The ln command creates links. The most commonly used type of link is probably the symbolic link, which you can create with ln -s.

For example, the following command creates a link to our Downloads folder on our Desktop:

ln -s /home/howtogeek/Downloads /home/howtogeek/Desktop

Check out our article on symbolic links for more information.

chmod – Change Permissions

chmod changes a file’s permissions. For example, chmod +x would add executable permissions to the file named in the current folder. chmod -x would remove executable permissions from that file.

Linux file permissions can be a bit complicated. Check out our guide to Linux file permissions for more in-depth information.

touch – Create Empty Files

The touch command creates an empty file. For example, touch example creates an empty file named “example” in the current directory.

mc – A Full File Manager

Midnight Commander is one of many fully featured file managers you can use from the Linux terminal. It isn’t installed by default on most distributions; here’s the command you’ll need to install it on Ubuntu:

sudo apt-get install mc

Once it’s installed, just run the mc command to launch it.

Use the arrow keys to select files and the Tab key to switch between panes. Press Alt-1 to see the help screen or Alt-2 to see the menu.

You can also use the mouse in Midnight Commander if your terminal environment has mouse support.

Remember that you’ll need to run these commands with root permissions if you’re modifying a system directory. On Ubuntu, add sudo to the beginning of commands you want to run with root permissions.

Chris Hoffman is a technology writer and all-around computer geek. He's as at home using the Linux terminal as he is digging into the Windows registry. Connect with him on Google+.

  • Published 03/7/12

Comments (11)

  1. garry

    thank you for giving same preference to linux as windows.
    articles here are really helpful for people trying to get a knowledge about linux .

  2. TheFu

    alias ls=’ls -F’
    You will thank me ****tons****. It adds characters to the end of each file showing directories, execute bit, pipes, links, etc … Extremely handy.

    If you ever need a plain ‘ls’ (rarely), just ‘\ls’ to get the non-aliased version.
    A few other aliases here:

    I don’t know anyone using ‘mc’ after using Linux for 6 months. Just sayin’.

  3. lideerr

    I agree with you TheFu

    After some time experimenting with the command line you get familiar with the file tree :)

    But ‘mc’ is a very useful tool !!!

  4. Rasputin

    TheFu reminded me to post my own tidbit, which works under Cygwin and Ubuntu Linux:

    alias ll=’ls -lAF –group-directories-first –time-style=+”%Y-%m-%d %H:%M:%S”‘

    Not all the options work everywhere else; for example the –group-directories-first is not recognized by ls under Solaris (at least not the release I was playing with).

    You can skip the A if you don’t want to see the dot-files (like .profile) in your output.

    BTW, I disagree with the notion of aliasing ls to be ‘ls –with-options” I have worked on systems where it was aliased to an option with color, making many file names nearly invisible against the black background. My .profile always turned those off.

  5. Milo

    Some of my favorites:
    “cd -” Brings you back to the previous directory. (i.e. current directory is “/srv/http/example/books/”, run “cd /etc/httpd/conf/extra”, need to get back quick to edit an html file? “cd -” brings you back to “/srv/http/example/books”)

    mkcd () {
    mkdir $1
    cd $1
    The previous function is from lifehacker (can’t find the page). But it makes working in directories so much better. The function accepts one argument (the directory you want to create and move into). So it is called like “mkcd directory”. It then creates the directory with “mkdir directory” and then moves you into it with “cd directory”.

    Those are my two favorites!

  6. kenedy123

    Good to know about the How to Manage Files from the Linux Terminal 11 Commands You Need to Know

  7. sudobash

    The real purpose of touch is actually not to create files; however, it can be and is often used for this. Originally it was intended to be used to change the last modified & accessed timestamp. This can be useful if you want some program to think that you have updated a file without actually modifying it. For example it is nice to have if you want gcc/g++ to recompile something. Normally gcc looks at the timestamp of foobar.c and compares it to foobar.o to see whether it needs to be recompiled or not.

  8. Chris Hoffman


    Thanks a lot for the knowledge. I’ve often seen touch used for this purpose, but rarely for that one.

  9. Trevor

    Also really useful are “.” and “..”

    For those who are not familiar, both are useful as file location indicators and can be used when typing a directory. “.” refers to the current directory, while “..” refers to one directory level higher then your current directory.

    So if you have ExampleFolder1 which contains SubFolder1 and SubFolder2 and your current directory is SubFolder1 you can access files in SubFolder2 with “../SubFolder2″

  10. CR7

    you can add “-i” after “rm” and “rmdir” to ask for confirmation .

  11. Chris Hoffman


    Yup, you certainly can! Thanks for the tip.

Enter Your Email Here to Get Access for Free:

Go check your email!