Il comando basename è uno strumento utile in Linux che permette di rimuovere il percorso di un file e restituire solo il nome del file. Questo può essere particolarmente utile quando si lavora su un server VPS.
Utilizzo del comando basename
La sintassi di base del comando è:
basename [percorso]
Esempi dell’utilizzo del comando basename
Esempio 1: Nome del file semplice
Se abbiamo un file chiamato /home/utente/documenti/esempio.txt, possiamo estrarne il nome così:
basename /home/utente/documenti/esempio.txt
Output:
esempio.txt
Esempio 2: Rimuovere l’estensione del file
Se vogliamo rimuovere l’estensione dal nome del file, possiamo usare il parametro -s:
basename -s .txt /home/utente/documenti/esempio.txt
Output:
esempio
Esempio 3: Utilizzo con variabili
Possiamo anche utilizzare variabili in uno script. Ad esempio:
FILE="/home/utente/documenti/esempio.txt"
basename $FILE
Output:
esempio.txt
Conclusione
Il comando basename è uno strumento semplice ma potente che può aiutarti a gestire i percorsi dei file nei tuoi script e comandi in Linux. Ricorda che l’utilizzo di un server VPS può rendere il tuo lavoro ancora più efficace.
Windows VPS Deutschland
Windows VPS España
Windows VPS Nederland
Windows VPS Italia
Windows VPS Portugal
VPS Windows Italia
Windows VPS
Windows VPS
Windows VPS Sverige
Windows VPS Norge
Windows VPS
Windows VPS Türkiye
Windows RDS (Remote Desktop Services)
Windows VPS
Author: Łukasz Bodziony
Website: Windows VPS
Łukasz Bodziony is the CEO and founder of NETCLOUD24, a global VPS hosting brand proudly originating from Poland. With extensive experience in cloud computing, virtualization, and server management, he delivers high-performance Windows VPS and Remote Desktop Services (RDS) solutions to clients across Europe, North America, and beyond.
His expertise covers a wide range of technologies, including Microsoft Azure, Proxmox VE, Amazon Web Services (AWS), and numerous other virtualization and cloud platforms.
Beyond running his hosting business, Łukasz also provides professional paid server configuration and optimization services for companies and individuals. Outside of work, he is dedicated to caring for his children and building a secure future for them.
If you are interested in working with him or need expert assistance with your hosting, cloud environment, or server setup, feel free to reach out via Windows VPS.