LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-31-2011, 12:37 AM   #1
azurvii
LQ Newbie
 
Registered: Mar 2006
Posts: 21

Rep: Reputation: 0
Other meanings of `~` (besides `home directory`) in bash


I don't think I'm a newbie anymore, but still sorry that if this is too basic to ask. I failed to find the answer using Google or LQ search. Since the `~` is shown in most PS1 variable, or just could not attract the attention from search engines simply because it's a symbol. And all pages I found introducing bash variables are telling that `~` is your home directory.

But I just came across expressions like
Quote:
~bin
~username
Those are definitely not as simple as `~/` means.

I tried
Code:
echo ~bin
/bin
and
Code:
echo ~backup/
/var/backups/
Can anyone tell me what's going on with `~`?

Big thanks
 
Old 01-31-2011, 01:10 AM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 373Reputation: 373Reputation: 373Reputation: 373
No, nothing else. All it means is "home directory."

When you use it like so:
Code:
$ ls -l ~/
It means to list the contents of the home directory for the current user (you).

When you use it like this:
Code:
$ ls -l ~bin
It means to list the contents of the home directory of the user named "bin". This is just a shorthand to refer to another user's home directory.

If you execute this command:
Code:
cat /etc/passwd
I'm certain you will see entries for a user named "bin" and a user named "backup" -- special system accounts. You'll also see their home directories specified in the /etc/passwd output. It should be obvious from the output, but take a look at man passwd if you can't quite figure out the format of the passwd file.

Last edited by Dark_Helmet; 01-31-2011 at 01:11 AM. Reason: code tag typo
 
Old 01-31-2011, 01:21 AM   #3
azurvii
LQ Newbie
 
Registered: Mar 2006
Posts: 21

Original Poster
Rep: Reputation: 0
Ah, that makes sense.
And so i think this should work (if i'm in the sudoers )
Code:
cd ~Dark_Helmet
sudo touch thanks.txt
 
Old 01-31-2011, 01:25 AM   #4
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 373Reputation: 373Reputation: 373Reputation: 373
Indeed it would

You're quite welcome!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
"Home directory already exists. Please enter another home directory path." Daravon Ubuntu 2 02-15-2009 11:26 PM
Help with bash script to create directory to /home folder wegadnie Linux - General 5 10-25-2008 12:50 PM
contents of 'home' directory found at sda5: mounted as /home, and also on sda6:/home leswatson Linux - Newbie 4 04-18-2008 05:02 PM
bash - size of home directory klavuzkarga Linux - Newbie 9 12-17-2007 06:58 AM
Need to chroot bash users to thier home directory coloradopaul Linux - Security 1 09-16-2004 11:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration