Extract Filename From the Full Path in Linux Last Updated : 03 Jun, 2022 Comments Improve Suggest changes Like Article Like Report Linux is a family of open-source operating systems and comes as various distributions or distros. The full path in Linux means starting from the root directory "/", the address of the file includes the directories and subdirectories until the file name. A full file path in Linux looks as follows: /home/user/Documents/test.txt It always starts with a "/" and ends with the file name. When dealing with a single file, it is quite easy to get the file name but when a large number of filenames is required from their path, we can automate it. In this article, we will learn different ways to extract file names. Using the basename commandUsing Bash parameter substitution Let's go through all the methods one by one. Method 1: Using the basename command The basename command is solely created for the purpose of extracting the base name, that is the file name. Enter the following command in the following pattern to get the file name basename full_path Example: basename /home/user/Desktop/exam1.pdf Output: Multiple paths: Use the -a flag to pass multiple paths and retrieve their file names respectively. basename -a /home/user/Desktop/exam1.pdf /home/user/Desktop/exam2.pdf /home/user/Desktop/exam3.pdf Output: Method 2: Using Bash parameter substitution In this method, we store the path in a variable, and then remove the part of the path before the last "/" using the following command. $ filepath="/home/user/Desktop/exam1.pdf" $ filename=${filepath##*/} $ echo $filename Output: Comment More infoAdvertise with us Next Article Extract Filename From the Full Path in Linux M manavsarkar07 Follow Improve Article Tags : Linux-Unix linux-command Linux-file-commands Similar Reads How to Get the Full Path of a File in Linux While dealing with files on Linux, especially shell scripts, one may require determining the full path of a file at times. Now, let's consider several methods of getting the full path of a file in Linux. In this article, we will be discussing several different solutions to a popular problem.Before w 3 min read List One Filename Per Line in Linux One of the most frequent tasks when using the Linux command line is listing the files in a directory. Sometimes we want the list of files to be in a specific format, such as one file per line. ls is a Linux shell command that lists directory contents of files and directories. It is one of the most o 3 min read Get filename from path without extension using Python Getting a filename from Python using a path is a complex process. i.e, In Linux or Mac OS, use "/" as separators of the directory while Windows uses "\" for separating the directories inside the path. So to avoid these problems we will use some built-in package in Python.File Structure: Understandin 3 min read basename Command in Linux with examples The 'basename' command in Linux is a fundamental utility used in file manipulation and script writing. It simplifies file paths by stripping directory information and optional suffixes from file names. Here a detailed overview of the 'basename' command, including its syntax, options, and practical u 3 min read Listing All Files Matching a Full-Path Pattern in R When working with large directories of files in R, there are often times when you need to find and list all files that match a specific pattern. This can be particularly useful when dealing with complex file structures, where files are scattered across multiple subdirectories. R provides powerful to 4 min read Like