What directory is the default bash directory - linux

I am using the bash console for Ubuntu and my console location is
user#MyServer:~$
If user#MyServer:/$ is the root directory, what is user#MyServer:~$ ?

~ represents your home directory. If you are logged in as root, this will typically be /root if you are logged in with another user (say with username user) this will typically be /home/user. The best way to know for certain though is either run echo ~ which will print where ~ points to, or you can run the pwd command while in ~ which will show your present working directory - this command is generally useful to know when navigating.

As noted in other replies, it's your home directory, which is shortened to ~.
You can find out what directory you're in using the pwd command. eg:
[atticus:pgl]:~ $ pwd
/home/pgl

“user#MyServer:~$” is the command prompt. You can echo $PS1 to see the setting of your environment.

Its your home directory you can go to your home directory by cd ~

Not always, you can list all users' home directory by:
cut -d : -f1,6 /etc/passwd
so you will get different paths, some under /export/home/USERNAME, some under /home/USERNAME, some has no home directory. For root account, normal / is its home directly.

Related

am in the Desktop but I cd is not see the desktop

How can I fixs that problem meanwhie I fix last code Selenim
Selenium but I am take same error. And cd is not see the Desktop but I am in the Desktop.
Here ~ is equal to /home/levidonates so when you type cd ~/Selenium it's actually cd /home/levidonates/Selenium but the folder Selenium is in your folder Desktop, so you need to type :
cd ~/Desktop/Selenium
~ is a shorthand for your home directory, /home/levidomates. The directories you're accessing are under there, not under the root, /. That is, ~/Desktop is not the same as /Desktop.
Firstly I see which folder do you try to enter / at the beginning? this is not true method.
/ characters means top of all folders root level.
You should not confuse it with the root user's home folder.
cd: change directory
cd .. : Back to the previous folder or up folder.
Firstly You can check your home folder
echo $HOME
then you must be enter pwd
if the your home folder /home/levidomates/
you must only cd ~ command
than cd Desktop
You shouldn't use / at the beginning of folders
Your absolute way to Deskotp is not correct...You forgot /home/levidomates
So then it should be cd /home/levidomates/Desktop instead of cd /Desktop

Ubuntu: how to enter a directory in shell

On my Desktop I have created a folder called "Files", I would like to know how to access that folder through a shell script
When in Linux file system using bash you can navigate to the home directory in many ways:
After you reach the home directory everything is easy from there including reaching Desktop.
The ~ or $HOME reference:
In Linux based systems the keyword ~ or $HOME refers to the home directory of the computer.
For example say you are currently at /bin, to navigate to home if you know your username you would do :
$ cd /home/yourusername
#The directory is now switched to :
$ pwd #This command stands for print working directory
'/home/yourusername'
Now you can do it alternatively by:
(Again assuming you are in /bin)
$ cd $HOME
$ pwd
'/home/yourusername'
#Alternatively
$ cd /bin
$ cd ~
$ pwd
'/home/yourusername'
These shortcuts let you go to home without writing much and are even recommended.
Now for your problem you can easily navigate to your folder by:
cd ~/Desktop/Files/

How to make Git-bash command line start up with home directory?

Git-bash.exe is installed at this location:
C:\Program Files\Git
Git-bash.exe starts up with these prompts:
bash: /c/Users/GodCoder/git-prompt.sh: No such file or directory
GodCoder / $
(GodCoder is just the username)
This file named, 'git-promt.sh' is definitely present at that location, still that promt!
Now, after I tried to print the current working directory which is the same directory where Git-bash is installed i.e. C:\Program Files\Git , it showed this:
GodCoder / $ pwd
/
Now, how to change this, default startup directory to my home directory location which is C:\Users\GodCoder i.e. I want Git-hub.exe to start up like this
GodCoder ~ $
Instead of starting up in this way
GodCoder / $
How to achieve this GodCoder ~ $?
Start your git bash with a /dir like this: git-bash.exe /dir "C:\Users\GodCoder"
If you are on Windows, do this
Right click on the Windows shortcut that you use to launch git bash, and click Properties. Change the value of "Start In" to your desired workspace path i.e.
Replace the start in values with "C:\Users\GodCoder"
For more information go to this link: https://classroom.udacity.com/courses/ud775/lessons/2980038599/concepts/33417185870923
It may help you in setting up your enviroment further and also, make sure you restart the application or even the pc and try running in admin or different user modes too!

How to set a Linux user's $HOME directory to /dev/null without warnings?

I wrote a python script and put it into /bin. What I need is to let user could only run this script when they log in my computer by ssh.
I set an alias to generate user information as below:
alias USER_GEN='useradd -d /dev/null -s /bin/my_shell.py'
Problems:
Every time when I use USER_GEN to create an user account, the bash warns me "The home directory is exists."
After creating user account and log into my computer the bash warns me """No directory /dev/null!!Logging in with Home = "/" .""""
Question:
How to let those warning disappear?
/dev/null is not a directory. It is a (special) file. A home directory is expected to be a directory. If it is not, the login process will use the root directory as a home directory, as indicated.
If you want the user to not be able to create files in their home directory, don't give them write permissions on the directory. But make sure that it is a directory.

Safely change home directory

I'm trying to safely update the home directory as specified in /etc/passwd,
but the standard Linux utils - usermod and vipw - for doing so aren't provided
by Cygwin.
Could anyone tell me how they changed this in Cygwin?
EDIT: For recent versions of Cygwin (1.7.34 and beyond), see this newer question.
Like sblundy's answer, you can always edit by-hand.
But if you want to do it the "official" way, use the cygwin-specific mkpasswd command. Below is a snippet from the official docs on mkpasswd :
For example, this command:
Example 3.11. Using an alternate home root
$ mkpasswd -l -p "$(cygpath -H)" > /etc/passwd
would put local users' home directories in the Windows 'Profiles' directory.
There's a bunch of other really useful commands described on the Cygwin Utilities documentation page (which includes mkpasswd). The use of cygpath in the example above is another of these cygwin-specific tools.
While you're at it, you probably also want to read the Using Cygwin Effectively with Windows documentation. There's a bunch of really good advice.
I ended up exiting all my cygwin shells and editing it by hand in a text editor. So far, so good.
Note: don't escape the spaces in the "Documents and Settings" directory. The entry will look like
user:...:/cygdrive/c/Documents and Settings/user:/bin/bash
The line is tokenized on the : character.
The simplest answer I have found is to make /home to be a soft link to your Windows Home/UserProfile directory
cd /
mv home oldhome
ln -s "$(cygpath -H)" home
I used cygpath as it will get the proper location for the HOME directory on the current version of Windows. On my box cygpath -H returns /cygdrive/c/Users
For the current user the following worked for me:
Close Cygwin.
Set the HOME Windows user environment variable.
Start Cygwin.
run "mkpasswd -c -p "$(cygpath -H)" > /etc/passwd".
Restart Cygwin.
I confirmed it worked by running ssh-keygen without any arguments. After making this change the app now defaults to saving the key to /cygdrive/c/Users/user instead of /home/user.
I don't know if setting HOME is required, but I did it anyway per instructions for setting up TortoiseGit with Cygwin using Tortoise's official documentation for unofficial Cygwin support here. Setting HOME alone though was not enough for ssh-keygen to recognize the home directory change.
Also, note that Cygwin's official documentation on this issue can be found here.
Confirmed in Windows 7 using 64-bit Cygwin v1.7.35.
I always set HOME as a user-specific environment variable in Computer Properties.
To avoid problems caused by having spaces in the path to your home directory, use the short-form of the Windows 'Profiles' directory - i.e. /cygdrive/c/DOCUME~1/user.
You can do this by typing the command:
mkpasswd -l -p "$(cygpath $(cygpath -dH))" > /etc/passwd
Original answer by Christopher from elsewhere
Cygwin 1.7.34+
For those using Cygwin 1.7.34 or higher Cygwin supports configuring how to fetch home directory, login shell, and gecos information in /etc/nsswitch.conf. This is detailed in the Cygwin User Guide section:
Cygwin user names, home dirs, login shells
If you've previously created an /etc/passwd or /etc/group file you'll want to remove those and configure Cygwin using the new Windows Security model to POSIX mappings.
[[ -f /etc/passwd ]] && mv /etc/passwd /etc/passwd.bak
[[ -f /etc/group ]] && mv /etc/group /etc/group.bak
The /etc/nsswitch.conf file's db_home: setting defines how Cygwin fetches the user's home directory. The default setting for db_home: is
db_home: /home/%U
So by default, Cygwin just sets the home dir to /home/$USERNAME. You can change that though to point at any other custom path you want. The supported wildcard characters are:
%u The Cygwin username (that's lowercase u).
%U The Windows username (that's uppercase U).
%D Windows domain in NetBIOS style.
%H Windows home directory in POSIX style. Note that, for the db_home: setting, this only makes sense right after the preceeding slash, as in db_home: /%H/cygwin
%_ Since space and TAB characters are used to separate the schemata, a space in the filename has to be given as %_ (that's an underscore).
%% A per-cent character.
In place of a path, you can specify one of four named path schemata that are predefined.
windows The user's home directory is set to the same directory which is used as Windows home directory, typically something along the lines of %USERPROFILE% or C:\Users\$USERNAME. Of course, the Windows directory is converted to POSIX-style by Cygwin.
cygwin AD only: The user's home directory is set to the POSIX path given in the cygwinHome attribute from the cygwinUser auxiliary class. See also the section called “The cygwin schema”.
unix AD only: The user's home directory is set to the POSIX path given in the unixHomeDirectory attribute from the posixAccount auxiliary class. See also the section called “The unix schema”.
desc The user's home directory is set to the POSIX path given in the home="..." XML-alike setting in the user's description attribute in SAM or AD. See the section called “The desc schema” for a detailed description.
The following will make the user's home directory in Cygwin the same as is used for the Windows home directory.
db_home: windows
Cygwin 1.7.33 or earlier
For those using Cygwin 1.7.33 or earlier, update to the latest version Cygwin and remove previously used /etc/passwd and /etc/group files, then see the steps above.
Else, follow these older steps below.
Firstly, set a Windows environment variable for HOME that points to your user profile:
Open System on the Control Panel
On the Advanced tab click Environment Variables (toward the bottom)
In the User Variables area click "New…"
For Variable name enter HOME
For Variable value enter %USERPROFILE%
Click OK in all the open dialog boxes to apply this new setting
Now we are going to update the Cygwin /etc/passwd file with the Windows %HOME% variable we just created. Shell logins and remote logins via ssh will rely on /etc/passwd to tell them the location of the user's $HOME path.
At the Cygwin bash command prompt type the following:
cp /etc/passwd /etc/passwd.bak
mkpasswd -l -p $(cygpath -H) > /etc/passwd
mkpasswd -d -p $(cygpath -H) >> /etc/passwd
The -d switch tells mkpasswd to include DOMAIN users, while -l is to only output LOCAL machine users. This is important if you're using a PC at work where the user information is obtained from a Windows Domain Controller.
Now, you can also do the same for groups, though this is not necessary unless you will be using a computer that is part of a Windows Domain. Cygwin reads group information from the Windows account databases, but you can add an /etc/group file if your machine is often disconnected from its Domain Controller.
At the Cygwin bash prompt type the following:
cp /etc/group /etc/group.bak
mkgroup -l > /etc/group
mkgroup -d >> /etc/group
Now, exit Cygwin and start it up again. You should find that your HOME path points to the same location as your Windows User Profile -- i.e. /cygdrive/c/Users/username
I like to keep my cygwin installation sync'd to a pen drive and another computer, so I hate hard-coding the home directory. I use the following cygwin.bat:
echo off
SETLOCAL
set SHELL=\\bin\\bash
set HOME=%~dp0..\..\doc\unix
bin\bash --login -i
ENDLOCAL
SETLOCAL and ENDLOCAL make sure that SHELL and HOME don't clobber existing env variables for other programs. HOME=%~dp0..\..\doc\unix sets HOME to be two directories up, in the doc/unix subdirectory. Then in ....\doc\unix.bashrc, I include PATH="/bin:/usr/local/bin:/usr/X11R6/bin:/usr/bin".
I did not use start /wait %CD%\bin\bash to start bash, because I am using Console2, so I don't need an additional cmd window.
Using Windows Environment Variable: HOME
This works for me for a permanent, non-portable, non-network solution; i.e. setting the HOME Environment variable permanently in Windows.
Note that this doesn't affect ssh or telnet sessions which always refer to /etc/passwd
ref: Setting up Cygwin- My HOME environment variable is not what I want.
CMD
For current user (needs to run once per user)::
reg add HKCU\Environment /v HOME /t REG_EXPAND_SZ /d ^%USERPROFILE^%
For new Users:
reg add HKU\.DEFAULT\Environment /v HOME /t REG_EXPAND_SZ /d ^%USERPROFILE^%
Note: Carets ^ before percent-signs %
IMPORT REG FILE
Import this reg file (current user):
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Environment]
"HOME"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,4c,\
00,45,00,25,00,00,00
For new users:
Windows Registry Editor Version 5.00
[HKU\.DEFAULT\Environment]
"HOME"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,4c,\
00,45,00,25,00,00,00
REGEDIT
In Regedit, under:
For current user:
HKEY_CURRENT_USER\Environment
For new Users:
HKU\.DEFAULT\Environment
Create HOME as a new Expandable String Value (*REG_EXPAND_SZ*) and put in %USERPROFILE%
cd /home
rm -rf chris
ln -s /cygdrive/z chris
I am not really sure if it is the safest solution but it is a possible solution that works for me ;)
I edited my /etc/passwd file directly (making sure nothing else would be accessing it), and changed all references to /home to be /Users (on Windows 7). I found that, in order for everything to work correctly, I had to delete any directories in the /home directory (or move them to the appropriate other location). Otherwise, cygwin would develop a split personality where, for example, 'bash -l' would start in /home/Pablo but $HOME would be /Users/Pablo and emacs would appear to do the reverse. Once I deleted /home/Pablo, everything worked fine.
I only needed to be in C:\Users\username when I start cygwin. So, I just added to .bashrc and .profile
cd ${HOMEPATH}
If you prefer to use ~/. instead of $HOMEPATH, you can also add the following:
export HOME=${HOMEPATH}
This way I don't disturb the cygwin installation.

Resources