Где лежит bashrc linux

Где находится .bashrc?

Я чувствую глупость, но я не могу найти ответ на это где угодно. Я пытаюсь выполнить эти инструкции, чтобы отредактировать мое приглашение bash, но нет .bashrc ни в моем каталоге пользователя (~/.bashrc), ни в моем домашнем каталоге, ни в главном каталоге файловой системы.

В /etc/ нет .bashrc (однако есть bash.bashrc).

Создать файл .bashrc в моем пользовательском или домашнем каталоге? Есть ли лучший, более свежий набор инструкций для изменения подсказки bash?

13 ответов

Пользовательский, скрытый по умолчанию.

Если нет, просто создайте его.

Пользовательский характер :

В домашней папке каждого пользователя (99.99% времени) есть .bashrc, а также одна системная (я не знаю, где находится Ubuntu).

Самый быстрый способ доступа к ней — nano ~/.bashrc с терминала (замените nano на то, что вы хотите использовать).

Если этого нет в домашней папке пользователя, используется общесистемная .bashrc как резерв, когда он загружается перед файлом пользователя. Вы можете просто скопировать и вставить его (конечно, с правами root), но .bashrc не является абсолютно необходимым (может потребоваться, чтобы все работало, я не обнаружил) на уровне пользователя, поскольку он в основном переопределяет общесистемный с пользовательскими настройками. Вы можете написать свой собственный, хотя.

Основными компонентами для этих пользователей могут быть PS1 (приглашение Bash по умолчанию отображает user@localhost:pwd $) и псевдонимы, а также установку цветового приглашения и, возможно, (сообщение состояния занятости).

Он скрыт из-за . начинается с имени файла. Перечислите его с помощью

или включите «Показать скрытые файлы» в меню просмотра в nautilus (Ctrl-H также выполнит трюк).

Вы можете редактировать его с помощью любимый текстовый редактор из вашего домашнего каталога, например cd, чтобы перейти в ваш домашний каталог:

Источник

Where I can find the contents of the default /etc/bash.bashrc file?

I accidentally overwrote the /etc/bash.bashrc file. Please give me the default content in that file to restore, or the file itself.

5 Answers 5

If you overwrote your bash the best way is to copy it again from your system itself instead of someone else:

rm ~/.bashrc cp /etc/skel/.bashrc ~/ 

My /etc/bash.bashrc file is the following:

# System-wide .bashrc file for interactive bash(1) shells. # To enable the settings / commands in this file for login shells as well, # this file has to be sourced in /etc/profile. # If not running interactively, don't do anything [ -z "$PS1" ] && return # check the window size after each command and, if necessary, # update the values of LINES and COLUMNS. shopt -s checkwinsize # set variable identifying the chroot you work in (used in the prompt below) if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then debian_chroot=$(cat /etc/debian_chroot) fi # set a fancy prompt (non-color, overwrite the one in /etc/profile) PS1='$\u@\h:\w\$ ' # Commented out, don't overwrite xterm -T "title" -n "icontitle" by default. # If this is an xterm set the title to user@host:dir #case "$TERM" in #xterm*|rxvt*) # PROMPT_COMMAND='echo -ne "\033]0;$@$: $\007"' # ;; #*) # ;; #esac # enable bash completion in interactive shells #if [ -f /etc/bash_completion ] && ! shopt -oq posix; then # . /etc/bash_completion #fi # sudo hint if [ ! -e "$HOME/.sudo_as_admin_successful" ]; then case " $(groups) " in *\ admin\ *) if [ -x /usr/bin/sudo ]; then cat ". See "man sudo_root" for details. EOF fi esac fi # if the command-not-found package is installed, use it if [ -x /usr/lib/command-not-found -o -x /usr/share/command-not-found ]; then function command_not_found_handle < # check because c-n-f could've been removed in the meantime if [ -x /usr/lib/command-not-found ]; then /usr/bin/python /usr/lib/command-not-found -- $1 return $? elif [ -x /usr/share/command-not-found ]; then /usr/bin/python /usr/share/command-not-found -- $1 return $? else return 127 fi >fi 

However, you could also just boot from a live CD and copy the live CD file onto your hard-disc i.e.

sudo mkdir /mnt/tempmount sudo mount -t ext4 /dev/sda1 /mnt/tempmount sudo cp /etc/bash.bashrc /mnt/tempmount/etc/bash.bashrc 

Change /dev/sda1 for whatever partition your ubuntu is installed on.

Читайте также:  Удалить шрифт в linux

Источник

Where is .bashrc file found in Linux?

Is there always only one .bashrc and .bash_profile file for every user? And, is .bashrc and .bash_profile always found in the /home/»user name» directory?

4 Answers 4

The only ones that bash looks at by default are in the user’s home directory, yes. There is also typically a single source for them in Linux — /etc/skel. The user’s home directory does not need to be under /home, though.

I see you’ve edited your question to ask where your .bash_login and .bash_profile files are. Based on the # prompt, I’m going to assume you’re running this as root. In that case, your files are

/root/.bash_history /root/.bashrc 

See my original answer above regarding a user’s home directory — it’s not always /home; in this case, root’s home directory is /root .

When bash is invoked as an interactive login shell, or as a non-interactive shell with the —login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable.

~/.bash_profile The personal initialization file, executed for login shells ~/.bashrc The individual per-interactive-shell startup file 

There is also /etc/bashrc ( /etc/bash.bashrc in Debian-based Linux) which contains System wide functions and aliases . By default, this is set, even for non-interactive, non-login shells.

The tilde in the paths indicates the home directory of the currently logged in user. Bash is only able to use one of ~/.bash_profile, ~/.bash_login, or ~/.profile (per currently logged in user), in that order, for reading and executing commands. (Debian-based operating systems typically do not have ~/.bash_profile or ~/.bash_login. They use the file ~/.profile . This file explains that it will be read and used unless ~/.bash_profile or ~/.bash_login are created.

#~/.profile: executed by the command interpreter for login shells.

#This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login exists.

Источник

Читайте также:  Kernel that linux uses

No bashrc file in my home directory

The problem is that I do not have a .bashrc file in my home directory. There is only a .bash_history file in my home.

If i go to the root, there is a etc/bash.bashrc file there but what i think is that it will make changes for all users and not just for me. I want to add this path just for myself. It shouldn’t effect others. Also there is no $PATH variable in that bashrc file so I am even more confused.

6 Answers 6

Don’t forget it is a hidden file inside your home directory (you would not be the first to do a ls -l and thinking it is not there).

There should be a .bashrc on the first page. If not just create it with

And simply write following line into it.

OR Most of the distributions keep a standard .bashrc file in /etc/skel/ You can copy it to home directory.

OK I get that now. On other computers, I can type lego and the software starts. On my system, the lego folder is in my ~/data/user1/bin folder. I have added this path to .bashrc file. Now what do I have to do so that when i type lego, it should start the software? Do i have to set up an alias? If yes, how? alias lego=’

@detraveller Have you added ~/data/user1/bin to your PATH environment variable in the .bashrc file? (add this line: export PATH=$PATH:~/data/user1/bin ) — if so, you should be able to just type lego in the terminal, and the program should start.

I added only PATH=$PATH:~/data/user1/bin . You didn’t mention export so I didn’t put it there. I will try again tomorrow when I go to Uni.

Most distributions keep a standard .bashrc file in /etc/skel/ you can just copy to your home dir. Otherwise you could just make a new empty .bashrc file in your home dir.

Create Your Own Startup File for Interactive Shells

About Bash Startup Files

From the INVOCATION section of man 1 bash says:

When an interactive shell that is not a login shell is started, bash reads and executes commands from /etc/bash.bashrc and ~/.bashrc, if these files exist.

Note that these startup files are optional; Bash doesn’t require them. Bash also differentiates between login shells and interactive shells. An interactive shell is defined thus:

An interactive shell is one started without non-option arguments and without the -c option whose standard input and error are both connected to terminals (as determined by isatty(3)), or one started with the -i option.

Many distributions source one type of startup file from the other, but some don’t, so this issue can be difficult to address canonically. You need to examine all your startup files to see how and when your ~/.bashrc will be invoked on your system.

Читайте также:  Файл resolve conf linux

Creating Your Per-User Interactive Shell Startup File

If you’re simply missing a user-specific ~/.bashrc file, just create one. This will be invoked by Bash for non-login shells (e.g. shells started without the —login flag), or whenever you force the shell to be interactive by invoking it with the -i flag.

If you don’t have a .bashrc , you can simply create one and add the lines you wish to it, such as:

to add your user bin directory to the end of the path.

But you should be careful if there are other startup files. The rules as to what files get used are rather complex, but they’re detailed in the bash man page. Enter man bash on a command line and look for INVOCATION .

Short answers:

  1. find ~ -maxdepth 1 -name ‘.bashrc’
  2. vi ~/.bashrc
  3. echo $PATH | grep ~/MyNewCoolProgramFolder

Detailed one:
I take a more close literal interpretation.

    «Find file .bashrc in your home directory»
    Since it exists the command find , maybe the treacherous editor would suggest you to use it:

find ~ -maxdepth 1 -name '.bashrc' 

Search in the home directory ~ , descend only of one level (no subdir -maxdepth 1 ). For all the options write man find .
The line below the will do the minimal job

Note: In case ~/.bashrc doesn’t exist you can create it with a simple echo >> ~/.bashrc . The >> will create the file if doesn’t exists. If the ~/.bashrc instead exists it will append only the harmless output of empty echo , avoiding an unintentional deletion a such critical file, that is incidentally difficult to restore without a backup. (The following is because seldom I have to honour the meaning of my nickname, do not execute if you are in doubt).

if [ ! -f ~/.bashrc ] ; then cp -i /etc/skel/.bashrc ~/.bashrc ; else ls -la ~/.bashrc; fi || echo " # Auto Generated " >> ~/.bashrc 
echo $PATH | grep ~/MyNewCoolProgramFolder 
PATH=$PATH:~/MyNewCoolProgramFolder 

(b) You can try its auto completion. Start to write CoolDetravelle and press Tab . If it is in the $PATH it will be auto completed (always if auto completion is enabled). (c) You can ask to the bash shell which command will be used if you write the command CoolDetraveller .

Note: If in your application path there is one or more spaces, which could be unable to find CoolDetraveller , although (here I honour my nickname again) the auto completion of CoolDetraveller as a valid parameter of the which command will work! Ad nauseam: You cannot ask whereis CoolDetraveller because whereis

Источник

Оцените статью
Adblock
detector