Menu
Newbedev LogoNEWBEDEV Python Javascript Linux Cheat sheet
Newbedev LogoNEWBEDEV
  • Python 1
  • Javascript
  • Linux
  • Cheat sheet
  • Contact

Get home directory by username

You can use eval:

eval echo ~$USER

But see Andrew's comment and glenn's reply below.


This might work for you:

homedir=$( getent passwd "$USER" | cut -d: -f6 )

This will also work on users that are not you. For instance,

homedir=$( getent passwd "someotheruser" | cut -d: -f6 )

It seems you are that user -- why not

echo $HOME

?

Tags:

Linux

Bash

Related

How to get the original of the e-mail in Lotus Notes 8.5? Run Windows inside a virtual machine on Linux for gaming Lenovo T420 integrated camera is not working Converting a VMDK to VHD How do I use my keyfile to sftp transfer data from one server to another OS X + Vim: Open Finder for a Folder in NerdTree (Vim) Does a computer screen consume more power to display black or white? including files in a symlink directory when backing up with duplicity How to split a string based on ":" in MS-Excel? What is the purpose of "C:\swapfile.sys" in Windows 8? How to edit the list of files to download in a .torrent file? Make exact mp4 (H264) format for uploading to youtube

Recent Posts

Pandas how to find column contains a certain value Recommended way to install multiple Python versions on Ubuntu 20.04 Build super fast web scraper with Python x100 than BeautifulSoup How to convert a SQL query result to a Pandas DataFrame in Python How to write a Pandas DataFrame to a .csv file in Python
© 2021 newbedevPrivacy Policy