Quick Links

Want to start leveling up your terminal skills? The Linux command line has a wealth of flexible commands for file management. Learn how to use the most common ones for your everyday tasks.

1 pwd

When you’re using the command line, you’re always “in” a specific directory. Linux calls this the working directory. By default, your prompt—the text before your cursor on each line—will display the name of this directory. It’s usually your home directory when you first open a terminal.

The pwd command stands for “print working directory” and you can think of it like a “you are here” marker. When you run pwd, it tells you the full (absolute) path of your working directory:

The linux pwd command showing the current directory is "/usr/local/bin."
Remove Ads

2 cd

Now you know where you are, it’s time to learn how to move around your filesystem with the cd command, which stands for “change directory.” Your working directory is important because all commands and files that use relative paths do so from that directory.

Run the cd command by supplying a directory as the first argument. This directory can be a complete absolute path:

cd /usr/local/bin
The linux cd command changes the current working directory, confirmed by pwd.

Or it can be relative to your current directory:

cd bin
cd ../docs
The Linux cd command showing examples with absolute and relative paths.

You can call cd without any arguments to quickly return to your home directory:

Remove Ads
cd
The Linux cd command with no arguments changes directory to the user's home.

3 ls

Once you’ve navigated to a directory, you’ll often want to know what files (including subdirectories) it contains. The ls command stands for “list” and, unlike the previous two commands, it has many options.

Use ls on its own to show the contents of the current directory:

ls
The linux fs command displaying a set of files in two rows and five columns.

You can list specific files or directories by passing them as arguments. Use the -l flag (long format) to display one file per line with full information including permissions, ownership, size, and modification date/time:

Remove Ads
ls -l /boot
The ls command showing a list of files, one per line, each with metadata like permissions, owner, and modification date.

This format also displays the type of each file. If the first letter of the permission string is a “d”, it’s a directory. If it’s an “l”, it’s a link. If it’s a “-“, it’s a regular file.

If you want a more obvious indicator, try the -F option. It adds a “/” to the end of directories and an “@” to the end of links, making them easier to spot:

ls -F /bin/*.grep
The Linux ls command with the -F option which adds a "*" at the end of executables and an "@" at the end of links.

Note that you can include wildcard characters to list files matching a pattern. You can use wildcards with any command that accepts file arguments, not just ls.

Remove Ads

4 touch

This strange-sounding command lets you update a file’s access & modification times. You might not think you’d need this much, and you’re probably right, but touch has a secondary purpose: to create an empty file.

Run the command with any number of arguments, then touch will update existing files and create new ones:

touch foo bar
The touch command creating a new file, then updating its modification time, confirmed by an ls.

5 mkdir

To organize your filesystem, you’ll want to create directories to group related files. Remember that directories can contain subdirectories, and so on. The mkdir command is simple: it creates a directory at the path of each argument you supply.

mkdir foo foo/bar hum
The Linux mkdir command creating three directories, including one subdirectory.
Remove Ads

Note that each path can be relative or absolute. If you try to create multiple levels of directory at the same time, mkdir will complain:

The Linux mkdir command showing an error when trying to create a deep subdirectory.

Use the -p flag to create the full hierarchy in one go:

mkdir -p one/two/three
The mkdir command using the -p flag to create a deeply nested subdirectory.

6 cp

To create an additional copy of an existing file, use the cp (copy) command. In its simplest form, give the path of an existing file and a path for the new copy:

cp resume.pdf resume2.pdf

You can also use this command to copy several files to a directory. To do so, use as many file arguments as you like, followed by a single directory:

Remove Ads
cp file1.md file2.md file3.md myfiles
The Linux cp command creating copies of three files in a subdirectory.

7 rm / rmdir

Eventually, you’ll find you’ve created too many files and you’ll want to get rid of some. Enter rm, short for “remove.”

The rm command takes one or more files as arguments and will attempt to delete each one:

rm resume *.bak 
The Linux rm command deleting a single file.

Use the -f option to “force” removal of a file. This attempts to delete a file, even if its permissions appear to restrict you from doing so:

rm -f filename

For example, without write permission, you’ll be prompted for confirmation if you try to delete a file. The -f flag skips this step; it also suppresses an error message if the file doesn’t exist.

Remove Ads
The Linux rm command with the -f option forcing deletion of a file.

rm will also let you remove directories, but not by default:

The Linux rm command refusing to delete a directory.

The -d option will let you do so, as will rmdir:

The Linux rm command used with the -d option to remove a directory.

8 mv

Initially, it might seem like the mv command (short for “move”) has a dual-purpose: both renaming files and moving them from one directory to another. However, Linux considers both just ways of changing a file’s path.

Remove Ads
mv old-name new-name

With two arguments, mv will rename—or move—the first to the second:

The Linux mv command renaming a file and a directory and moving a file into a directory.

mv has another mode that works a bit like cp’s second mode. If the final argument is a directory, mv will move all other named files into that directory, even those that are directories.

9 chmod

On Linux, each file has a set of permissions describing who can access it and what they can do with it. The “who” can be the owner of the file, anyone in the same group as the file, or anyone at all. That “what” can be reading, writing, or executing—running the file as a program.

Use of chmod is a bit complicated because of its permissions syntax. Basic use is like this:

chmod <permissions> files

An example of permissions is “go+r” which makes (+) a file readable (r) to users in its group (g) and other users (o). Another typical use is to make a file executable:

Remove Ads
chmod a+x script.sh

This lets you run a script on the command line by typing its path.

10 ln

Links let you reference files in more than one place on the file system, without taking up much extra space. The symbolic—or soft—link is the easiest to understand:

ln -s original link

The link command creates a link that references an original file:

The linux ln command creates a link which ls confirms.

Without the -s option, you’ll create a hard link, which acts more like a second copy of the original file. They are a bit harder to understand and, therefore, are less commonly used.


There are many more important Linux commands you should learn to do anything from killing a process to fetching a remote web page.

Remove Ads