[LINUX] File renaming using the full path received by the shell

Overview

When I pass the full path of the file to the shell as an argument, I want to change the name while using the original file name Example: Arguments → /home/desk/a.txt Output → /home/desk/bc_a.txt

Source

a=/home/desk/a.txt
echo $(dirname ${a})/bc_$(basename ${a})

Execution result

/home/desk/bc_a.txt

Command details

The dirname command extracts the directory part of the argument basename extracts the file name part Since it is possible to determine the extraction conditions in detail, it is necessary to investigate if necessary. (Extract without extension, etc.)

Recommended Posts

File renaming using the full path received by the shell
Get the file path using Pathlib
Get the full path referenced by .lnk with wsl
Extract the targz file using python
[Python Kivy] How to get the file path by dragging and dropping
A memo organized by renaming the file names in the folder with python
List all files under the current directory line by line with full path
View the full path (absolute path) of a file in a directory in Linux Bash
Download the file from S3 using boto.
Get the path to the systemd unit file
Read the file line by line in Python
Read the file line by line in Python
Read the file by specifying the character code.
Import by directly specifying the directory path
BeautifulSoup trick: Decide the Tag by specifying the path
I tried using the Datetime module by Python
Put the file uploaded by django into MinIO
Download the csv file created by Google Colaboratory