https://wiki.archlinux.org/api.php?action=feedcontributions&user=Jul&feedformat=atomArchWiki - User contributions [en]2024-03-28T08:23:22ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=NVIDIA/Tips_and_tricks&diff=779866NVIDIA/Tips and tricks2023-05-29T23:30:27Z<p>Jul: Add a tip for some motherboards that do not unlock higher efifb resolutions when booting with CSM enabled</p>
<hr />
<div>[[Category:Graphics]]<br />
[[Category:X server]]<br />
[[ja:NVIDIA/ヒントとテクニック]]<br />
[[ru:NVIDIA (Русский)/Tips and tricks]]<br />
== Fixing terminal resolution ==<br />
<br />
Transitioning from nouveau may cause your startup terminal to display at a lower resolution.<br />
<br />
For GRUB, see [[GRUB/Tips and tricks#Setting the framebuffer resolution]] for details. [https://forums.fedoraforum.org/showthread.php?t=306271] [https://web.archive.org/web/20170405115954/https://www.reddit.com/r/archlinux/comments/4gwukx/nvidia_drivers_and_high_resolution_tty_possible/]<br />
<br />
For [[systemd-boot]], set {{ic|console-mode}} in {{ic|''esp''/EFI/loader/loader.conf}}. See [[systemd-boot#Loader configuration]] for details.<br />
<br />
For [[rEFInd]], add to {{ic|''esp''/EFI/refind/refind.conf}} and {{ic|/etc/refind.d/refind.conf}} (latter file is optional but recommended): [https://www.reddit.com/r/archlinux/comments/86lqc5/tty_resolution_nvidia_psaish/]<br />
<br />
use_graphics_for linux<br />
<br />
A small caveat is that this will hide the kernel parameters from being shown during boot.<br />
<br />
{{Tip|If the above methods do not fix your terminal resolution, it may be necessary to disable Legacy BIOS mode entirely (often referred to as Compatibility Support Module, CSM, or Legacy Boot) in your UEFI settings. Before proceeding, make sure that all of your devices are configured to use UEFI boot.}}<br />
<br />
== Using TV-out ==<br />
<br />
See [[Wikibooks:NVIDIA/TV-OUT]].<br />
<br />
== X with a TV (DFP) as the only display ==<br />
<br />
The X server falls back to CRT-0 if no monitor is automatically detected. This can be a problem when using a DVI connected TV as the main display, and X is started while the TV is turned off or otherwise disconnected.<br />
<br />
To force NVIDIA to use DFP, store a copy of the EDID somewhere in the filesystem so that X can parse the file instead of reading EDID from the TV/DFP.<br />
<br />
To acquire the EDID, start nvidia-settings. It will show some information in tree format, ignore the rest of the settings for now and select the GPU (the corresponding entry should be titled "GPU-0" or similar), click the {{ic|DFP}} section (again, {{ic|DFP-0}} or similar), click on the {{ic|Acquire Edid}} Button and store it somewhere, for example, {{ic|/etc/X11/dfp0.edid}}.<br />
<br />
If in the front-end mouse and keyboard are not attached, the EDID can be acquired using only the command line. Run an X server with enough verbosity to print out the EDID block:<br />
$ startx -- -logverbose 6<br />
After the X Server has finished initializing, close it and your log file will probably be in {{ic|/var/log/Xorg.0.log}}. Extract the EDID block using nvidia-xconfig:<br />
$ nvidia-xconfig --extract-edids-from-file=/var/log/Xorg.0.log --extract-edids-output-file=/etc/X11/dfp0.bin<br />
<br />
Edit {{ic|xorg.conf}} by adding to the {{ic|Device}} section:<br />
Option "ConnectedMonitor" "DFP"<br />
Option "CustomEDID" "DFP-0:/etc/X11/dfp0.bin"<br />
The {{ic|ConnectedMonitor}} option forces the driver to recognize the DFP as if it were connected. The {{ic|CustomEDID}} provides EDID data for the device, meaning that it will start up just as if the TV/DFP was connected during X the process.<br />
<br />
This way, one can automatically start a display manager at boot time and still have a working and properly configured X screen by the time the TV gets powered on.<br />
<br />
If the above changes did not work, in the {{ic|xorg.conf}} under {{ic|Device}} section you can try to remove the {{ic|Option "ConnectedMonitor" "DFP"}} and add the following lines:<br />
Option "ModeValidation" "NoDFPNativeResolutionCheck"<br />
Option "ConnectedMonitor" "DFP-0"<br />
<br />
The {{ic|NoDFPNativeResolutionCheck}} prevents NVIDIA driver from disabling all the modes that do not fit in the native resolution.<br />
<br />
== Headless (no monitor) resolution ==<br />
<br />
In headless mode, resolution falls back to 640x480, which is used by VNC or Steam Link. To start in a higher resolution ''e.g.'' 1920x1080, specify a {{ic|Virtual}} entry under the {{ic|Screen}} subsection in {{ic|xorg.conf}}:<br />
Section "Screen"<br />
[...]<br />
SubSection "Display"<br />
Depth 24<br />
Virtual 1920 1080<br />
EndSubSection<br />
EndSection<br />
<br />
{{Tip|Using headless mode may be tricky and prone to error. For instance, in headless mode, desktop environments and {{Pkg|nvidia-utils}} do not provide a graphical way to change resolution. To facilitate setting up resolution one can use a DP or an HDMI dummy adapter which simulates the presence of a monitor attached to that port. Then resolution change can be done normally using a remote session such as VNC or Steam Link.}}<br />
<br />
== Check the power source ==<br />
<br />
The NVIDIA X.org driver can also be used to detect the GPU's current source of power. To see the current power source, check the 'GPUPowerSource' read-only parameter (0 - AC, 1 - battery):<br />
<br />
{{hc|$ nvidia-settings -q GPUPowerSource -t|1}}<br />
<br />
== Listening to ACPI events ==<br />
<br />
NVIDIA drivers automatically try to connect to the [[acpid]] daemon and listen to ACPI events such as battery power, docking, some hotkeys, etc. If connection fails, X.org will output the following warning:<br />
<br />
{{hc|~/.local/share/xorg/Xorg.0.log|<br />
NVIDIA(0): ACPI: failed to connect to the ACPI event daemon; the daemon<br />
NVIDIA(0): may not be running or the "AcpidSocketPath" X<br />
NVIDIA(0): configuration option may not be set correctly. When the<br />
NVIDIA(0): ACPI event daemon is available, the NVIDIA X driver will<br />
NVIDIA(0): try to use it to receive ACPI event notifications. For<br />
NVIDIA(0): details, please see the "ConnectToAcpid" and<br />
NVIDIA(0): "AcpidSocketPath" X configuration options in Appendix B: X<br />
NVIDIA(0): Config Options in the README.<br />
}}<br />
<br />
While completely harmless, you may get rid of this message by disabling the {{ic|ConnectToAcpid}} option in your {{ic|/etc/X11/xorg.conf.d/20-nvidia.conf}}:<br />
<br />
Section "Device"<br />
...<br />
Driver "nvidia"<br />
Option "ConnectToAcpid" "0"<br />
...<br />
EndSection<br />
<br />
If you are on laptop, it might be a good idea to install and enable the [[acpid]] daemon instead.<br />
<br />
== Displaying GPU temperature in the shell ==<br />
<br />
There are three methods to query the GPU temperature. ''nvidia-settings'' requires that you are using X, ''nvidia-smi'' or ''nvclock'' do not. Also note that ''nvclock'' currently does not work with newer NVIDIA cards such as GeForce 200 series cards as well as embedded GPUs such as the Zotac IONITX's 8800GS.<br />
<br />
=== nvidia-settings ===<br />
<br />
To display the GPU temp in the shell, use ''nvidia-settings'' as follows:<br />
$ nvidia-settings -q gpucoretemp<br />
<br />
This will output something similar to the following:<br />
Attribute 'GPUCoreTemp' (hostname:0.0): 41.<br />
'GPUCoreTemp' is an integer attribute.<br />
'GPUCoreTemp' is a read-only attribute.<br />
'GPUCoreTemp' can use the following target types: X Screen, GPU.<br />
<br />
The GPU temps of this board is 41 C.<br />
<br />
In order to get just the temperature for use in utilities such as ''rrdtool'' or ''conky'':<br />
<br />
{{hc|$ nvidia-settings -q gpucoretemp -t|41}}<br />
<br />
=== nvidia-smi ===<br />
<br />
Use ''nvidia-smi'' which can read temps directly from the GPU without the need to use X at all, e.g. when running Wayland or on a headless server. <br />
To display the GPU temperature in the shell, use ''nvidia-smi'' as follows:<br />
<br />
$ nvidia-smi<br />
<br />
This should output something similar to the following:<br />
<br />
{{hc|$ nvidia-smi|<nowiki><br />
Fri Jan 6 18:53:54 2012 <br />
+------------------------------------------------------+ <br />
| NVIDIA-SMI 2.290.10 Driver Version: 290.10 | <br />
|-------------------------------+----------------------+----------------------+<br />
| Nb. Name | Bus Id Disp. | Volatile ECC SB / DB |<br />
| Fan Temp Power Usage /Cap | Memory Usage | GPU Util. Compute M. |<br />
|===============================+======================+======================|<br />
| 0. GeForce 8500 GT | 0000:01:00.0 N/A | N/A N/A |<br />
| 30% 62 C N/A N/A / N/A | 17% 42MB / 255MB | N/A Default |<br />
|-------------------------------+----------------------+----------------------|<br />
| Compute processes: GPU Memory |<br />
| GPU PID Process name Usage |<br />
|=============================================================================|<br />
| 0. ERROR: Not Supported |<br />
+-----------------------------------------------------------------------------+<br />
</nowiki>}}<br />
<br />
Only for temperature:<br />
<br />
{{hc|$ nvidia-smi -q -d TEMPERATURE|<nowiki><br />
<br />
====NVSMI LOG====<br />
<br />
Timestamp : Sun Apr 12 08:49:10 2015<br />
Driver Version : 346.59<br />
<br />
Attached GPUs : 1<br />
GPU 0000:01:00.0<br />
Temperature<br />
GPU Current Temp : 52 C<br />
GPU Shutdown Temp : N/A<br />
GPU Slowdown Temp : N/A<br />
<br />
</nowiki>}}<br />
<br />
In order to get just the temperature for use in utilities such as ''rrdtool'' or ''conky'':<br />
<br />
{{hc|<nowiki>$ nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader,nounits</nowiki>|52}}<br />
<br />
Reference: https://www.question-defense.com/2010/03/22/gpu-linux-shell-temp-get-nvidia-gpu-temperatures-via-linux-cli{{Dead link|2023|05|07|status=domain name not resolved}}.<br />
<br />
=== nvclock ===<br />
<br />
[[Install]] the {{AUR|nvclock}} package.<br />
<br />
{{Note|''nvclock'' cannot access thermal sensors on newer NVIDIA cards such as Geforce 200 series cards.}}<br />
<br />
There can be significant differences between the temperatures reported by ''nvclock'' and ''nvidia-settings''/''nv-control''. According to [https://sourceforge.net/projects/nvclock/forums/forum/67426/topic/1906899 this post] by the author (thunderbird) of ''nvclock'', the ''nvclock'' values should be more accurate.<br />
<br />
== Overclocking and cooling ==<br />
<br />
=== Enabling overclocking ===<br />
<br />
{{Warning|Overclocking might permanently damage your hardware. You have been warned.}}<br />
<br />
{{Note|<br />
* Overclocking settings cannot be applied if the Xorg server is running in rootless mode. Consider [[Xorg#Xorg as Root|running Xorg as root]].<br />
* Enabling DRM kernel mode setting may cause overclocking to become unavailable, regardless of the Coolbits value.}}<br />
<br />
Overclocking is controlled via ''Coolbits'' option in the {{ic|Device}} section, which enables various unsupported features:<br />
Option "Coolbits" "''value''"<br />
<br />
{{Tip|The ''Coolbits'' option can be easily controlled with the ''nvidia-xconfig'', which manipulates the Xorg configuration files: {{bc|1=# nvidia-xconfig --cool-bits=''value''}}}}<br />
<br />
The ''Coolbits'' value is the sum of its component bits in the binary numeral system. The component bits are:<br />
<br />
* {{ic|1}} (bit 0) - Enables overclocking of older (pre-Fermi) cores on the ''Clock Frequencies'' page in ''nvidia-settings''.<br />
* {{ic|2}} (bit 1) - When this bit is set, the driver will "attempt to initialize SLI when using GPUs with different amounts of video memory".<br />
* {{ic|4}} (bit 2) - Enables manual configuration of GPU fan speed on the ''Thermal Monitor'' page in ''nvidia-settings''.<br />
* {{ic|8}} (bit 3) - Enables overclocking on the ''PowerMizer'' page in ''nvidia-settings''. Available since version 337.12 for the Fermi architecture and newer.[https://www.phoronix.com/scan.php?px=MTY1OTM&page=news_item]<br />
* {{ic|16}} (bit 4) - Enables overvoltage using ''nvidia-settings'' CLI options. Available since version 346.16 for the Fermi architecture and newer.[https://www.phoronix.com/scan.php?page=news_item&px=MTg0MDI]<br />
<br />
To enable multiple features, add the ''Coolbits'' values together. For example, to enable overclocking and overvoltage of Fermi cores, set {{ic|Option "Coolbits" "24"}}.<br />
<br />
The documentation of ''Coolbits'' can be found in {{ic|/usr/share/doc/nvidia/html/xconfigoptions.html}} and [https://download.nvidia.com/XFree86/Linux-x86_64/430.14/README/xconfigoptions.html#Coolbits here].<br />
<br />
{{Note|An alternative is to edit and reflash the GPU BIOS either under DOS (preferred), or within a Win32 environment by way of [https://www.techpowerup.com/download/nvidia-nvflash/ nvflash] and [https://www.guru3d.com/files-details/nvidia-bios-editor-download-nibitor.html NiBiTor 6.0]. The advantage of BIOS flashing is that not only can voltage limits be raised, but stability is generally improved over software overclocking methods such as Coolbits. [https://ivanvojtko.blogspot.sk/2014/03/how-to-overclock-geforce-460gtx-fermi.html Fermi BIOS modification tutorial]}}<br />
<br />
==== Setting static 2D/3D clocks ====<br />
<br />
{{Out of date|RegistryDwords gets ignored in Xorg configuration files now, please update this and add a method that works.}}<br />
<br />
Set the following string in the {{ic|Device}} section to enable PowerMizer at its maximum performance level (VSync will not work without this line):<br />
Option "RegistryDwords" "PerfLevelSrc=0x2222"<br />
<br />
==== Allow change to highest performance mode ====<br />
<br />
{{Accuracy|This section refers to the limits for [[wikipedia:Kepler_(microarchitecture)#GPU_Boost|GPU boost]], which is unrelated to overclocking discussed above. The {{ic|nvidia-smi(1)}} man page says that it is "For Tesla devices from the Kepler+ family and Maxwell-based GeForce Titan." And as far as [[User:Lahwaacz|Lahwaacz]] is aware, the only GPU which supports this and does not have the default clocks equal to the maximum, is Tesla K40 [https://www.nvidia.com/content/PDF/kepler/nvidia-gpu-boost-tesla-k40-06767-001-v02.pdf]. Since the Pascal architecture, [https://www.anandtech.com/show/10325/the-nvidia-geforce-gtx-1080-and-1070-founders-edition-review/15 Boost 3.0] handles automatic clocking even differently.}}<br />
<br />
Since changing performance mode and overclocking memory rate has little to no effect in ''nvidia-settings'', try this:<br />
<br />
* Setting Coolbits to 24 or 28 and remove Powermizer RegistryDwords -> Restart X<br />
* find out max. Clock and Memory rate. (this can be LOWER than what your gfx card reports after booting!): {{bc|$ nvidia-smi -q -d SUPPORTED_CLOCKS}}<br />
* set rates for GPU 0: {{bc|# nvidia-smi -i 0 -ac memratemax,clockratemax}}<br />
<br />
After setting the rates the max. performance mode works in ''nvidia-settings'' and you can overclock graphics-clock and memory transfer rate.<br />
<br />
==== Saving overclocking settings ====<br />
<br />
Typically, clock and voltage offsets inserted in the ''nvidia-settings'' interface are not saved, being lost after a reboot.<br />
Fortunately, there are tools that offer an interface for overclocking under the proprietary driver, able to save the user's overclocking<br />
preferences and automatically applying them on boot. <br />
Some of them are:<br />
<br />
* {{AUR|gwe}} - graphical, applies settings on desktop session start<br />
* {{AUR|nvclock}} and {{AUR|systemd-nvclock-unit}} - graphical, applies settings on system boot<br />
* {{AUR|nvoc}} - text based, profiles are configuration files in {{ic|/etc/nvoc.d/}}, applies settings on desktop session start<br />
<br />
Otherwise, {{ic|GPUGraphicsClockOffset}} and {{ic|GPUMemoryTransferRateOffset}} attributes can be set in the command-line interface of ''nvidia-settings'' on [[Autostarting|startup]]. For example:<br />
<br />
$ nvidia-settings -a "GPUGraphicsClockOffset[''performance_level'']=''offset''"<br />
$ nvidia-settings -a "GPUMemoryTransferRateOffset[''performance_level'']=''offset''"<br />
<br />
Where {{ic|''performance_level''}} is the number of the highest performance level. If there are multiple GPUs on the machine, the GPU ID should be specified: {{ic|1=[gpu:''gpu_id'']GPUGraphicsClockOffset[''performance_level'']=''offset''}}.<br />
<br />
=== Custom TDP Limit ===<br />
<br />
Modern NVIDIA graphics cards throttle frequency to stay in their TDP and temperature limits. To increase performance it is possible to change the TDP limit, which will result in higher temperatures and higher power consumption. <br />
<br />
For example, to set the power limit to 160.30W:<br />
# nvidia-smi -pl 160.30<br />
<br />
To set the power limit on boot (without driver persistence):<br />
<br />
{{hc|/etc/systemd/system/nvidia-tdp.timer|2=<br />
[Unit]<br />
Description=Set NVIDIA power limit on boot<br />
<br />
[Timer]<br />
OnBootSec=5<br />
<br />
[Install]<br />
WantedBy=timers.target<br />
}}<br />
<br />
{{hc|/etc/systemd/system/nvidia-tdp.service|2=<br />
[Unit]<br />
Description=Set NVIDIA power limit<br />
<br />
[Service]<br />
Type=oneshot<br />
ExecStart=/usr/bin/nvidia-smi -pl 160.30<br />
}}<br />
<br />
=== Set fan speed at login ===<br />
<br />
{{Style|Refer to [[#Enabling overclocking]] for description of ''Coolbits''.}}<br />
<br />
You can adjust the fan speed on your graphics card with ''nvidia-settings''' console interface. First ensure that your Xorg configuration has enabled the bit 2 in the [[#Enabling overclocking|Coolbits]] option.<br />
<br />
{{Note|GeForce 400/500 series cards cannot currently set fan speeds at login using this method. This method only allows for the setting of fan speeds within the current X session by way of ''nvidia-settings''.}}<br />
<br />
Place the following line in your [[xinitrc]] file to adjust the fan when you launch Xorg. Replace {{ic|''n''}} with the fan speed percentage you want to set.<br />
<br />
nvidia-settings -a "[gpu:0]/GPUFanControlState=1" -a "[fan:0]/GPUTargetFanSpeed=''n''"<br />
<br />
You can also configure a second GPU by incrementing the GPU and fan number.<br />
<br />
nvidia-settings -a "[gpu:0]/GPUFanControlState=1" -a "[fan:0]/GPUTargetFanSpeed=''n''" \<br />
-a "[gpu:1]/GPUFanControlState=1" -a [fan:1]/GPUTargetFanSpeed=''n''" &<br />
<br />
If you use a login manager such as [[GDM]] or [[SDDM]], you can create a desktop entry file to process this setting. Create {{ic|~/.config/autostart/nvidia-fan-speed.desktop}} and place this text inside it. Again, change {{ic|''n''}} to the speed percentage you want.<br />
<br />
[Desktop Entry]<br />
Type=Application<br />
Exec=nvidia-settings -a "[gpu:0]/GPUFanControlState=1" -a "[fan:0]/GPUTargetFanSpeed=''n''"<br />
X-GNOME-Autostart-enabled=true<br />
Name=nvidia-fan-speed<br />
<br />
{{Note|Before driver version 349.16, {{ic|GPUCurrentFanSpeed}} was used instead of {{ic|GPUTargetFanSpeed}}.[https://devtalk.nvidia.com/default/topic/821563/linux/can-t-control-fan-speed-with-beta-driver-349-12/post/4526208/#4526208]}}<br />
<br />
To make it possible to adjust the fanspeed of more than one graphics card, run:<br />
$ nvidia-xconfig --enable-all-gpus<br />
$ nvidia-xconfig --cool-bits=4<br />
<br />
{{Note|On some laptops (including the ThinkPad [https://devtalk.nvidia.com/default/topic/1052110/linux/can-t-control-gtx-1050-ti-max-q-fan-on-thinkpad-x1-extreme-laptop/post/5340658/#5340658 X1 Extreme] and [https://devtalk.nvidia.com/default/topic/1048624/linux/how-to-set-gpu-fan-speed/post/5321818/#5321818 P51/P52]), there are two fans, but neither are controlled by nvidia.}}<br />
<br />
== Kernel module parameters ==<br />
<br />
{{Style|Giving advanced examples without explaining what they do is pointless.}}<br />
<br />
Some options can be set as kernel module parameters, a full list can be obtained by running {{ic|modinfo nvidia}} or looking at {{ic|nv-reg.h}}. See [[Gentoo:NVidia/nvidia-drivers#Kernel module parameters]] as well.<br />
<br />
For example, enabling the following will turn on kernel mode setting (see above) and enable the PAT feature [https://docs.kernel.org/x86/pat.html]{{Dead link|2023|05|20|status=404}}, which affects how memory is allocated. PAT was first introduced in Pentium III [https://www.kernel.org/doc/ols/2008/ols2008v2-pages-135-144.pdf] and is supported by most newer CPUs (see [[wikipedia:Page attribute table#Processors]]). If your system can support this feature, it should improve performance.<br />
<br />
{{hc|/etc/modprobe.d/nvidia.conf|2=<br />
options nvidia-drm modeset=1 <br />
options nvidia NVreg_UsePageAttributeTable=1<br />
}}<br />
<br />
On some notebooks, to enable any NVIDIA settings tweaking you must include this option, otherwise it responds with "Setting applications clocks is not supported" etc.<br />
<br />
{{hc|/etc/modprobe.d/nvidia.conf|2=<br />
options nvidia NVreg_RegistryDwords="OverrideMaxPerf=0x1"<br />
}}<br />
<br />
{{Note|As per [[Kernel module#Using files in /etc/modprobe.d/]], you will need to [[regenerate the initramfs]] if using [[NVIDIA#DRM kernel mode setting|early KMS]].}}<br />
<br />
== Preserve video memory after suspend ==<br />
<br />
By default the NVIDIA Linux drivers save and restore only essential video memory allocations on system suspend and resume. Quoting NVIDIA ([https://download.nvidia.com/XFree86/Linux-x86_64/515.65.01/README/powermanagement.html], also available with the {{Pkg|nvidia-utils}} package in {{ic|/usr/share/doc/nvidia/html/powermanagement.html}}): <br />
:The resulting loss of video memory contents is partially compensated for by the user-space NVIDIA drivers, and by some applications, but can lead to failures such as rendering corruption and application crashes upon exit from power management cycles.<br />
<br />
The '''still experimental''' system enables saving all video memory (given enough space on disk or main RAM). The interface is through the {{ic|/proc/driver/nvidia/suspend}} file as follows: <br />
<br />
* write "suspend" (or "hibernate") to {{ic|/proc/driver/nvidia/suspend}} immediately before writing to the usual Linux {{ic|/sys/power/state}} file<br />
* write "resume" to {{ic|/proc/driver/nvidia/suspend}} immediately after waking up, or after an unsuccessful attempt to suspend or hibernate.<br />
<br />
To save and restore all video memory contents, [[Kernel modules#Setting module options|load]] the {{ic|nvidia}} kernel module with the {{ic|1=NVreg_PreserveVideoMemoryAllocations=1}} option and [[enable]] {{ic|nvidia-suspend.service}} and {{ic|nvidia-hibernate.service}}. <br />
<br />
{{Note|<br />
* The video memory contents are saved by default to {{ic|/tmp}}, which is a [[tmpfs]]. [https://download.nvidia.com/XFree86/Linux-x86_64/515.65.01/README/powermanagement.html#PreserveAllVide719f0 NVIDIA recommends] using an other filesystem to achieve the best performance. This is also required if the size is not sufficient for the amount of memory: point to a different location with the {{ic|NVreg_TemporaryFilePath}} option, (e.g. {{ic|1=NVreg_TemporaryFilePath=/var/tmp}}). <br />
* The chosen file system containing the file needs to support unnamed temporary files (e.g. ext4 or XFS) and have sufficient capacity for storing the video memory allocations (i.e. at least 5 percent more than the sum of the memory capacities of all NVIDIA GPUs). Use the command {{ic|1=nvidia-smi --query-gpu=memory.total --format=csv,noheader,nounits}} to list the memory capacities of all GPUs in the system.}}<br />
<br />
To make the changes permanent, [[create]] the following: <br />
<br />
{{hc|/etc/modprobe.d/nvidia-power-management.conf|2=<br />
options nvidia NVreg_PreserveVideoMemoryAllocations=1 NVreg_TemporaryFilePath=''/path/to/tmp-nvidia''<br />
}}<br />
<br />
{{Note|As per [[Kernel module#Using files in /etc/modprobe.d/]], you will need to [[regenerate the initramfs]] if using [[NVIDIA#DRM kernel mode setting|early KMS]].}}<br />
<br />
The interaction with {{ic|/proc/driver/nvidia/suspend}} is handled by the simple Unix shell script at {{ic|/usr/bin/nvidia-sleep.sh}}, which will itself be called by [[systemd]] or other tools. The {{Pkg|nvidia-utils}} package ships with the following services (which essentially just call {{ic|nvidia-sleep.sh}}): {{ic|nvidia-suspend.service}}, {{ic|nvidia-hibernate.service}}, {{ic|nvidia-resume.service}}. <br />
<br />
{{Note|Contrary to NVIDIA's instructions, it is currently not necessary to enable {{ic|nvidia-resume.service}} (and it is in fact probably not a good idea to enable it), because the {{ic|/usr/lib/systemd/system-sleep/nvidia}} script does the same thing as the service (but slightly earlier), and it is enabled by default (systemd calls it after waking up from a suspend). Only [[enable]] {{ic|nvidia-suspend.service}} and/or {{ic|nvidia-hibernate.service}}, unless you are using [https://gitlab.gnome.org/GNOME/gdm/-/issues/784 GDM with Wayland] which requires {{ic|nvidia-resume.service}} too.}}<br />
<br />
== Driver persistence ==<br />
<br />
NVIDIA has a daemon that can be optionally run at boot. In a standard single-GPU X desktop environment the persistence daemon is not needed and can actually create issues [https://devtalk.nvidia.com/default/topic/1044421/linux/nvidia-persistenced-causing-60-second-reboot-delays]. See the [https://docs.nvidia.com/deploy/driver-persistence/index.html#persistence-daemon Driver Persistence] section of the NVIDIA documentation for more details.<br />
<br />
To start the persistence daemon at boot, [[enable]] the {{ic|nvidia-persistenced.service}}. For manual usage see the [https://docs.nvidia.com/deploy/driver-persistence/index.html#usage upstream documentation].</div>Julhttps://wiki.archlinux.org/index.php?title=Git&diff=777859Git2023-05-12T21:39:21Z<p>Jul: Git prompt: add a note for faster prompt. This option can freeze the shell for a bit, especially on older hard disks.</p>
<hr />
<div>[[Category:Version Control System]]<br />
[[Category:Commands]]<br />
[[de:Git]]<br />
[[es:Git]]<br />
[[ja:Git]]<br />
[[zh-hans:Git]]<br />
{{Related articles start}}<br />
{{Related|Bisecting bugs with Git}}<br />
{{Related|Concurrent Versions System}}<br />
{{Related|Git server}}<br />
{{Related|Gitweb}}<br />
{{Related|HTTP tunneling#Tunneling Git}}<br />
{{Related|Subversion}}<br />
{{Related|VCS package guidelines}}<br />
{{Related articles end}}<br />
:"I've met people who thought git is a front-end to GitHub. They were wrong, git is a front-end to the AUR." — [https://public-inbox.org/git/#didyoureallythinklinuswouldsaythat Linus T.]<br />
<br />
[[wikipedia:Git (software)|Git]] is the version control system (VCS) designed and developed by Linus Torvalds, the creator of the Linux kernel. Git is now used to maintain [[AUR]] packages, as well as many other projects, including sources for the Linux kernel.<br />
<br />
== Installation ==<br />
<br />
[[Install]] the {{Pkg|git}} package. For the development version, install the {{AUR|git-git}} package. Check the optional dependencies when using tools such as ''git svn'', ''git gui'' and ''gitk''.<br />
<br />
=== Graphical front-ends ===<br />
<br />
See also [https://git-scm.com/download/gui/linux git GUI Clients].<br />
<br />
* {{App|Giggle|GTK frontend for git.|https://wiki.gnome.org/Apps/giggle/|{{Pkg|giggle}}}}<br />
* {{App|GitAhead|Graphical git client including a built-in Merge Tool.|https://gitahead.github.io/gitahead.com/|{{AUR|gitahead}}}}<br />
* {{App|Git Cola|Sleek and powerful graphical user interface for Git written in Python.|https://git-cola.github.io/|{{AUR|git-cola}}}}<br />
* {{App|Git Extensions|Graphical user interface for Git that allows you to control Git without using the commandline.|https://gitextensions.github.io/|{{AUR|gitextensions}}}}<br />
* {{App|gitg|GNOME GUI client to view git repositories.|https://wiki.gnome.org/Apps/Gitg|{{Pkg|gitg}}}}<br />
* {{App|git-gui|Tcl/Tk based portable graphical interface to Git.|https://git-scm.com/docs/git-gui|{{Pkg|git}} + {{Pkg|tk}}}}<br />
:{{Note|To enable spell checking in ''git-gui'', {{Pkg|aspell}} is required, along with the dictionary corresponding to the {{ic|LC_MESSAGES}} [[environment variable]]. See {{Bug|28181}} and the [[aspell]] article.}}<br />
* {{App|GitHub Desktop|Electron-based graphical user interface built by the GitHub team.|https://github.com/desktop/desktop|{{AUR|github-desktop}} {{AUR|github-desktop-bin}}}}<br />
* {{App|gitk|Tcl/Tk based Git repository browser.|https://git-scm.com/docs/gitk|{{Pkg|git}} + {{Pkg|tk}}}}<br />
* {{App|Guitar|Git GUI Client.|https://github.com/soramimi/Guitar|{{AUR|guitar}}}}<br />
* {{App|lazygit|simple terminal UI for git commands.|https://github.com/jesseduffield/lazygit|{{Pkg|lazygit}}}}<br />
* {{App|QGit|Git GUI viewer to browse revisions history, view patch content and changed files, graphically following different development branches.|https://github.com/tibirna/qgit|{{Pkg|qgit}}}}<br />
* {{App|[[Wikipedia:RabbitVCS|RabbitVCS]]|Set of graphical tools written to provide simple and straightforward access to the version control systems you use.|http://rabbitvcs.org/|{{AUR|rabbitvcs}}}}<br />
* {{App|Sublime Merge|Git Client from the makers of Sublime Text. |https://www.sublimemerge.com/|{{AUR|sublime-merge}}}}<br />
* {{App|Tig|ncurses-based text-mode interface for git.|https://jonas.github.io/tig/|{{Pkg|tig}}}}<br />
* {{App|ungit|Brings user friendliness to git without sacrificing the versatility of git.|https://github.com/FredrikNoren/ungit|{{AUR|nodejs-ungit}}}}<br />
<br />
== Configuration ==<br />
<br />
In order to use Git you need to set at least a name and email:<br />
<br />
$ git config --global user.name "''John Doe''"<br />
$ git config --global user.email "''johndoe@example.com''"<br />
<br />
See [https://git-scm.com/book/en/Getting-Started-First-Time-Git-Setup Getting Started - First-Time Git Setup].<br />
<br />
See [[#Tips and tricks]] for more settings.<br />
<br />
== Usage ==<br />
<br />
A Git repository is contained in a {{ic|.git}} directory, which holds the revision history and other metadata. The directory tracked by the repository, by default the parent directory, is called the working directory. Changes in the working tree need to be staged before they can be recorded (committed) to the repository. Git also lets you restore, previously committed, working tree files.<br />
<br />
See [https://git-scm.com/book/en/Getting-Started-Git-Basics Getting Started - Git Basics].<br />
<br />
=== Getting a Git repository ===<br />
<br />
* Initialize a repository<br />
:{{ic|git init}}, see {{man|1|git-init}}<br />
* Clone an existing repository<br />
:{{ic|git clone ''repository''}}, see {{man|1|git-clone}} (also explains the Git URLs)<br />
<br />
=== Recording changes ===<br />
<br />
Git projects have a staging area, which is an {{ic|index}} file in your Git directory, that stores the changes that will go into your next commit. To record a modified file you therefore firstly need to add it to the index (stage it). The {{ic|git commit}} command then stores the current index in a new commit.<br />
<br />
==== Staging changes ====<br />
<br />
* Add working tree changes to the index<br />
:{{ic|git add ''pathspec''}}, see {{man|1|git-add}}<br />
* Remove changes from the index<br />
:{{ic|git reset ''pathspec''}}, see {{man|1|git-reset}}<br />
* Show changes to be committed, unstaged changes and untracked files<br />
:{{ic|git status}}, see {{man|1|git-status}}<br />
<br />
You can tell Git to ignore certain untracked files using {{ic|.gitignore}} files, see {{man|5|gitignore}}.<br />
<br />
Git does not track file movement. Move detection during merges is based only on content similarity. The {{ic|git mv}} command is just there for convenience and is equivalent to:<br />
<br />
$ mv -i foo bar<br />
$ git reset -- foo<br />
$ git add bar<br />
<br />
==== Committing changes ====<br />
<br />
The {{ic|git commit}} command records the staged changes to the repository, see {{man|1|git-commit}}.<br />
<br />
* {{ic|-m}} – supply the commit message as an argument, instead of composing it in your default text editor<br />
* {{ic|-a}} – automatically stage files that have been modified or deleted (does not add untracked files)<br />
* {{ic|--amend}} – redo the last commit, amending the commit message or the committed files<br />
<br />
{{Tip|Always commit small changes frequently and with meaningful messages.}}<br />
<br />
==== Revision selection ====<br />
<br />
Git offers multiple ways to specify revisions, see {{man|7|gitrevisions}} and [https://git-scm.com/book/en/v2/Git-Tools-Revision-Selection Revision Selection].<br />
<br />
Many Git commands take revisions as arguments. A commit can be identified by any of the following:<br />
<br />
* SHA-1 hash of the commit (the first 7 digits are usually sufficient to identify it uniquely)<br />
* Any commit label such as a branch or tag name<br />
* The label {{ic|HEAD}} always refers to the currently checked-out commit (usually the head of the branch, unless you used ''git checkout'' to jump back in history to an old commit)<br />
* Any of the above plus {{ic|~}} to refer to previous commits. For example, {{ic|HEAD~}} refers to one commit before {{ic|HEAD}} and {{ic|HEAD~5}} refers to five commits before {{ic|HEAD}}.<br />
<br />
==== Viewing changes ====<br />
<br />
Show differences between commits:<br />
<br />
$ git diff HEAD HEAD~3<br />
<br />
or between staging area and working tree:<br />
<br />
$ git diff<br />
<br />
View history of changes (where "''-N''" is the number of latest commits):<br />
<br />
$ git log -p ''(-N)''<br />
<br />
=== Undoing things ===<br />
<br />
* {{ic|git checkout}} - to restore working tree files, see {{man|1|git-checkout}}<br />
* {{ic|git reset}} - reset current HEAD to the specified state, see {{man|1|git-reset}}<br />
* {{ic|git revert}} - revert some existing commits, see {{man|1|git-revert}}<br />
<br />
These, along with few others, are further explained at [https://www.atlassian.com/git/tutorials/undoing-changes undoing-changes].<br />
<br />
For more complex modifications of history, such as {{ic|git commit --amend}} and {{ic|git rebase}} see, for example, [https://www.atlassian.com/git/tutorials/rewriting-history rewriting-history]. It is highly advised not to use such rewrites for commits that were collaborated with other users. Or, at the very least, highly coordinate it in advance.<br />
<br />
=== Branching ===<br />
<br />
{{Expansion|Add links for some common branching models.}}<br />
<br />
Fixes and new features are usually tested in branches. When changes are satisfactory they can merged back into the default (master) branch.<br />
<br />
Create a branch, whose name accurately reflects its purpose:<br />
<br />
$ git branch ''help-section-addition''<br />
<br />
List branches:<br />
<br />
$ git branch<br />
<br />
Switch branches:<br />
<br />
$ git checkout ''branch''<br />
<br />
Create and switch:<br />
<br />
$ git checkout -b ''branch''<br />
<br />
Merge a branch back to the master branch:<br />
<br />
$ git checkout master<br />
$ git merge ''branch''<br />
<br />
The changes will be merged if they do not conflict. Otherwise, Git will print an error message, and annotate files in the working tree to record the conflicts. The annotations can be displayed with {{ic|git diff}}. Conflicts are resolved by editing the files to remove the annotations, and committing the final version. See [[#Dealing with merges]] below.<br />
<br />
When done with a branch, delete it with:<br />
<br />
$ git branch -d ''branch''<br />
<br />
=== Collaboration ===<br />
<br />
A typical Git work-flow is:<br />
<br />
# Create a new repository or clone a remote one.<br />
# Create a branch to make changes; then commit those changes.<br />
# Consolidate commits for better organization/understanding.<br />
# Merge commits back into the main branch.<br />
# (Optional) Push changes to a remote server.<br />
<br />
==== Pull requests ====<br />
<br />
After making and committing some changes, the contributor can ask the original author to merge them. This is called a ''pull request''.<br />
<br />
To pull:<br />
<br />
$ git pull ''location'' master<br />
<br />
The ''pull'' command combines both ''fetching'' and ''merging''. If there are conflicts (e.g. the original author made changes in the same time span), then it will be necessary to manually fix them.<br />
<br />
Alternatively, the original author can pick the changes wanting to be incorporated. Using the ''fetch'' option (and ''log'' option with a special {{ic|FETCH_HEAD}} symbol), the contents of the pull request can be viewed before deciding what to do:<br />
<br />
$ git fetch ''location'' master<br />
$ git log -p HEAD..FETCH_HEAD<br />
$ git merge ''location'' master<br />
<br />
==== Using remotes ====<br />
<br />
Remotes are aliases for tracked remote repositories. A ''label'' is created defining a location. These labels are used to identify frequently accessed repositories.<br />
<br />
Create a remote:<br />
<br />
$ git remote add ''label'' ''location''<br />
<br />
Fetch a remote:<br />
<br />
$ git fetch ''label''<br />
<br />
Show differences between master and a remote master:<br />
<br />
$ git log -p master..''label''/master<br />
<br />
View remotes for the current repository:<br />
<br />
$ git remote -v<br />
<br />
When defining a remote that is a parent of the fork (the project lead), it is defined as ''upstream''.<br />
<br />
==== Push to a repository ====<br />
<br />
After being given rights from the original authors, push changes with:<br />
<br />
$ git push ''location'' ''branch''<br />
<br />
When ''git clone'' is performed, it records the original location and gives it a remote name of {{ic|origin}}.<br />
<br />
So what ''typically'' is done is this:<br />
<br />
$ git push origin master<br />
<br />
If the {{ic|-u}} ({{ic|--set-upstream}}) option is used, the location is recorded so the next time just a {{ic|git push}} is necessary.<br />
<br />
==== Dealing with merges ====<br />
<br />
See [https://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging#Basic-Merge-Conflicts Basic Merge Conflicts] in the Git Book for a detailed explanation on how to resolve merge conflicts. Merges are generally reversible. If wanting to back out of a merge one can usually use the {{ic|--abort}} command (e.g. {{ic|git merge --abort}} or {{ic|git pull --abort}}).<br />
<br />
=== History and versioning ===<br />
<br />
==== Searching the history ====<br />
<br />
{{ic|git log}} will give the history with a commit checksum, author, date, and the short message. The ''checksum'' is the "object name" of a commit object, typically a 40-character SHA-1 hash.<br />
<br />
For history with a long message (where the "''checksum''" can be truncated, as long as it is unique):<br />
<br />
$ git show (''checksum'')<br />
<br />
Search for ''pattern'' in tracked files:<br />
<br />
$ git grep ''pattern''<br />
<br />
Search in {{ic|.c}} and {{ic|.h}} files:<br />
<br />
$ git grep ''pattern'' -- '*.[ch]'<br />
<br />
==== Tagging ====<br />
<br />
Tag commits for versioning:<br />
<br />
$ git tag 2.14 ''checksum''<br />
<br />
''Tagging'' is generally done for [https://www.drupal.org/node/1066342 releasing/versioning] but it can be any string. Generally annotated tags are used, because they get added to the Git database.<br />
<br />
Tag the current commit with:<br />
<br />
$ git tag -a 2.14 -m "Version 2.14"<br />
<br />
List tags:<br />
<br />
$ git tag -l<br />
<br />
Delete a tag:<br />
<br />
$ git tag -d 2.08<br />
<br />
Update remote tags:<br />
<br />
$ git push --tags<br />
<br />
==== Organizing commits ====<br />
<br />
Before submitting a pull request it may be desirable to consolidate/organize the commits. This is done with the ''git rebase'' {{ic|--interactive}} option:<br />
<br />
$ git rebase -i ''checksum''<br />
<br />
This will open the editor with a summary of all the commits in the range specified; in this case including the newest ({{ic|HEAD}}) back to, but excluding, commit {{ic|''checksum''}}. Or to use a number notation, use for example {{ic|HEAD~3}}, which will rebase the last three commits:<br />
<br />
pick d146cc7 Mountpoint test.<br />
pick 4f47712 Explain -o option in readme.<br />
pick 8a4d479 Rename documentation.<br />
<br />
Editing the action in the first column will dictate how the rebase will be done. The options are:<br />
<br />
* {{ic|pick}} — Apply this commit as is (the default).<br />
* {{ic|edit}} — Edit files and/or commit message.<br />
* {{ic|reword}} — Edit commit message.<br />
* {{ic|squash}} — Merge/fold into previous commit.<br />
* {{ic|fixup}} — Merge/fold into previous commit discarding its message.<br />
<br />
The commits can be re-ordered or erased from the history (but be very careful with these). After editing the file, Git will perform the specified actions; if prompted to resolve merge problems, fix them and continue with {{ic|git rebase --continue}} or back out with the {{ic|git rebase --abort}} command.<br />
<br />
{{Note|Squashing commits is only used for local commits, it will cause troubles on a repository that is shared by other people.}}<br />
<br />
== Tips and tricks ==<br />
<br />
=== Using git-config ===<br />
<br />
Git reads its configuration from four INI-type configuration files:<br />
<br />
* {{ic|/etc/gitconfig}} for system-wide defaults<br />
* {{ic|~/.gitconfig}} and {{ic|~/.config/git/config}} (since 1.7.12) for user-specific configuration<br />
* {{ic|.git/config}} for repository-specific configuration<br />
<br />
These files can be edited directly, but the usual method is to use ''git config'', as shown in the examples below.<br />
<br />
List the currently set variables:<br />
<br />
$ git config {--local,--global,--system} --list<br />
<br />
Set the default editor from [[vim]] to [[nano]]:<br />
<br />
$ git config --global core.editor "nano -w"<br />
<br />
Set the default push action:<br />
<br />
$ git config --global push.default simple<br />
<br />
Set a different tool for ''git difftool'' (''meld'' by default):<br />
<br />
$ git config --global diff.tool vimdiff<br />
<br />
See {{man|1|git-config}} and [https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration Git Configuration] for more information.<br />
<br />
=== Adopting a good etiquette ===<br />
<br />
* When considering contributing to an existing project, read and understand its license, as it may excessively limit your ability to change the code. Some licenses can generate disputes over the ownership of the code.<br />
* Think about the project's community and how well you can fit into it. To get a feeling of the direction of the project, read any documentation and even the [[#History and versioning|log]] of the repository.<br />
* When requesting to pull a commit, or submit a patch, keep it small and well documented; this will help the maintainers understand your changes and decide whether to merge them or ask you to make some amendments.<br />
* If a contribution is rejected, do not get discouraged, it is their project after all. If it is important, discuss the reasoning for the contribution as clearly and as patiently as possible: with such an approach a resolution may eventually be possible.<br />
<br />
=== Speeding up authentication ===<br />
<br />
You may wish to avoid the hassle of authenticating interactively at every push to the Git server.<br />
<br />
* If you are authenticating with SSH keys, use an [[SSH agent]]. See also [[OpenSSH#Speeding up SSH]] and [[OpenSSH#Keep alive]].<br />
* If you are authenticating with username and password, switch to [[SSH keys]] if the server supports SSH, otherwise use git-credential-libsecret credential helper, or try [https://git-scm.com/docs/git-credential-cache git-credential-cache] or [https://git-scm.com/docs/git-credential-store git-credential-store].<br />
<br />
=== Using git-credential-libsecret as credential-helper ===<br />
<br />
Git may fetch your credentials from a org.freedesktop.secrets compatible keyring like [[GNOME/Keyring]] or [[KeePassXC]]. Therefore set up one compatible keyring and check if a keyring is registered to dbus using:<br />
<br />
dbus-send --session --print-reply --dest=org.freedesktop.DBus / \<br />
org.freedesktop.DBus.GetConnectionUnixProcessID \<br />
string:org.freedesktop.secrets<br />
<br />
then run<br />
<br />
git config --global credential.helper /usr/lib/git-core/git-credential-libsecret<br />
<br />
to set up git.<br />
<br />
=== Protocol defaults ===<br />
<br />
If you are running a multiplexed SSH connection as shown above, Git over SSH might be faster than HTTPS. Also, some servers (like the AUR) only allow pushing via SSH. For example, the following configuration will set Git over SSH for any repository hosted on the AUR.<br />
<br />
{{hc|~/.gitconfig|<nowiki><br />
[url "ssh://aur@aur.archlinux.org/"]<br />
insteadOf = https://aur.archlinux.org/<br />
insteadOf = http://aur.archlinux.org/<br />
insteadOf = git://aur.archlinux.org/<br />
</nowiki>}}<br />
<br />
=== Bash completion ===<br />
<br />
In order to enable Bash completion, source {{ic|/usr/share/git/completion/git-completion.bash}} in a [[Bash#Configuration files|Bash startup file]]. Alternatively, install {{pkg|bash-completion}}.<br />
<br />
=== Git prompt ===<br />
<br />
The Git package comes with a prompt script. To enable it, source the {{ic|/usr/share/git/completion/git-prompt.sh}} and set a custom prompt with the {{ic|%s}} parameter:<br />
<br />
* For [[Bash]]: {{ic|1=PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '}}<br />
* For [[zsh]]: {{ic|1=setopt PROMPT_SUBST ; PS1='[%n@%m %c$(__git_ps1 " (%s)")]\$ '}}<br />
<br />
Note that the command substitution must be escaped, see [[Bash/Prompt customization#Embedding commands]] for details. See [[Command-line shell#Configuration files]] for persistent configuration.<br />
<br />
When changing to a directory of a Git repository, the prompt will change to show the branch name. Extra details can be set to be shown by the prompt by setting the corresponding environment variable:<br />
<br />
{| class="wikitable"<br />
|+<br />
! Shell variable !! Information<br />
|-<br />
| GIT_PS1_SHOWDIRTYSTATE || {{ic|+}} for staged, {{ic|*}} if unstaged. <br />
|-<br />
| GIT_PS1_SHOWSTASHSTATE || {{ic|$}} if something is stashed.<br />
|-<br />
| GIT_PS1_SHOWUNTRACKEDFILES || {{ic|%}} if there are untracked files.<br />
|-<br />
| GIT_PS1_SHOWUPSTREAM || {{ic|<}}, {{ic|>}}, {{ic|<>}} behind, ahead, or diverged from upstream.<br />
|-<br />
| GIT_PS1_STATESEPARATOR || separator between branch name and state symbols<br />
|-<br />
| GIT_PS1_DESCRIBE_STYLE || show commit relative to tag or branch, when detached HEAD<br />
|-<br />
| GIT_PS1_SHOWCOLORHINTS || display in color<br />
|}<br />
<br />
The full documentation for the environment variables is available in the comments of the script.<br />
<br />
{{Note|If you experience that {{ic|$(__git_ps1)}} returns {{ic|((unknown))}}, then there is a {{ic|.git}} folder in your current directory which does not contain any repository, and therefore Git does not recognize it. This can, for example, happen if you mistake Git's configuration file to be {{ic|~/.git/config}} instead of {{ic|~/.gitconfig}}.}}<br />
<br />
{{Note|If your prompt is experiencing delays with very large repositories, it is likely due to the {{ic|GIT_PS1_SHOWUNTRACKEDFILES}} option, which triggers a full directory tree scan every time to detect new files, causing noticeable performance impact. To disable this option locally for those repositories, you can use the command:{{bc|$ git config --local bash.showUntrackedFiles false}}}}<br />
<br />
Alternatively, you can use one of git shell prompt customization packages from [[AUR]] such as {{AUR|bash-git-prompt}} or {{AUR|gittify}}.<br />
<br />
=== Visual representation ===<br />
<br />
To get an idea of the amount of work done:<br />
<br />
$ git diff --stat<br />
<br />
''git log'' with forking representation:<br />
<br />
$ git log --graph --oneline --decorate<br />
<br />
''git log'' graph alias (i.e. ''git graph'' will show a decorated version):<br />
<br />
$ git config --global alias.graph 'log --graph --oneline --decorate'<br />
<br />
=== Commit tips ===<br />
<br />
Reset to previous commit (very dangerous, erases everything to specified commit):<br />
<br />
$ git reset --hard HEAD^<br />
<br />
If a repository address gets changed, its remote location will need to be updated:<br />
<br />
$ git remote set-url origin git@''address'':''user''/''repo''.git<br />
<br />
Alternatively, edit {{ic|.git/config}} with the new location.<br />
<br />
Signed-off-by line append (a name-email signature is added to the commit which is required by some projects):<br />
<br />
$ git commit -s<br />
<br />
Signed-off-by automatically append to patches (when using {{ic|git format-patch ''commit''}}):<br />
<br />
$ git config --local format.signoff true<br />
<br />
Commit specific parts of files that have changed. This is useful if there are a large number of changes made that would be best split into several commits:<br />
<br />
$ git add -p<br />
<br />
=== Signing commits ===<br />
<br />
Git allows commits and tags to be signed using [[GnuPG]], see [https://git-scm.com/book/en/Git-Tools-Signing-Your-Work Signing Your Work].<br />
<br />
{{Note|To use [[pinentry]] curses for GPG signing make sure to {{ic|1=export GPG_TTY=$(tty)}} (alternatively use pinentry-tty) otherwise the signing step will fail if GPG is currently in a locked state (since it cannot prompt for pin).}}<br />
<br />
To configure Git to automatically sign commits:<br />
<br />
$ git config --global commit.gpgSign true<br />
<br />
=== Working with a non-master branch ===<br />
<br />
Occasionally a maintainer will ask that work be done on a branch. These branches are often called {{ic|devel}} or {{ic|testing}}. Begin by cloning the repository.<br />
<br />
To enter another branch beside master (''git clone'' only shows master branch but others still exist, {{ic|git branch -a}} to show):<br />
<br />
$ git checkout -b ''branch'' origin/''branch''<br />
<br />
Now edit normally; however to keep the repository tree in sync be sure to use both:<br />
<br />
$ git pull --all<br />
$ git push --all<br />
<br />
=== Directly sending patches to a mailing list ===<br />
<br />
If you want to send patches directly to a mailing list, you have to install the following packages: {{Pkg|perl-authen-sasl}} and {{Pkg|perl-io-socket-ssl}}.<br />
<br />
Make sure you have configured your username and e-mail address, see [[#Configuration]].<br />
<br />
Configure your e-mail settings:<br />
<br />
$ git config --global sendemail.smtpserver ''smtp.example.com''<br />
$ git config --global sendemail.smtpserverport ''465''<br />
$ git config --global sendemail.smtpencryption ''ssl''<br />
$ git config --global sendemail.smtpuser ''foobar@example.com''<br />
<br />
Now you should be able to send the patch to the mailing list (see also [https://www.openembedded.org/wiki/How_to_submit_a_patch_to_OpenEmbedded#Sending_patches OpenEmbedded:How to submit a patch to OpenEmbedded#Sending patches] and [https://git-send-email.io/ git-send-email.io]):<br />
<br />
$ git add ''filename''<br />
$ git commit -s<br />
$ git send-email --to=''pacman-contrib@lists.archlinux.org'' --confirm=always -M -1<br />
<br />
=== Working with a large git repository ===<br />
<br />
When working with a large remote repository, a significant amount of data has to be fetched. The following examples use the Linux kernel to illustrate how to work with such codebases.<br />
<br />
==== Fetching the entire repository ====<br />
<br />
The easiest solution is to get the entire repository: <br />
<br />
$ git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git<br />
<br />
{{Note|{{ic|git clone}} cannot be resumed if interrupted.}}<br />
<br />
You can update your repository by {{ic|git pull}}.<br />
<br />
==== Partially fetching the repository ====<br />
<br />
To limit your local repository to a smaller subset of the origin, say after v4.14 to bisect a bug, use a shallow clone:<br />
<br />
$ git clone --shallow-exclude v4.13 git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git<br />
<br />
You will get v4.14 and later, but not v4.13 and older.<br />
<br />
If you only want the latest snapshot, ignoring all history. (If a tarball is available and it suffices, choose that. Downloading from a git repository needs more bandwidth.) You can get it with:<br />
<br />
$ git clone --depth 1 git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git<br />
<br />
You can later obtain older commits, as the two following examples show: <br />
<br />
$ git fetch --tags --shallow-exclude v4.1<br />
$ git fetch --tags --shallow-since 2016-01-01<br />
<br />
{{Note|Without {{ic|--tags}}, tags will not be fetched.}}<br />
<br />
==== Getting other branches ====<br />
<br />
Your local repository tracks, in the above example, only the mainline kernel, i.e. in which the ''latest development is done''. Suppose you want the latest ''LTS'', for example the up-to-date 4.14 branch. You can get it by:<br />
<br />
$ git remote set-branches --add origin linux-4.17.y<br />
$ git fetch<br />
$ git branch --track linux-4.17.y origin/linux-4.17.y<br />
<br />
The last line is not mandatory, but probably wanted.<br />
(To know the name of the branch you want, there is no general rule. You can guess one by seeing the "ref" link in the gitweb interface.) <br />
<br />
For the snapshot of linux-4.17.y, do<br />
<br />
$ git checkout -b linux-4.17.y<br />
<br />
Or to extract it in another directory,<br />
<br />
$ mkdir /path/to/src-4.17; cd /path/to /src-4.17<br />
$ git clone --no-local --depth 1 -b linux-4.17.y ../linux-stable<br />
<br />
As usual, do {{ic|git pull}} to update your snapshot.<br />
<br />
==== Possible alternative ====<br />
<br />
Virtual File System for Git (VFS for Git), allows to access git repositories without a local one. (See [https://blogs.msdn.microsoft.com/bharry/2017/05/24/the-largest-git-repo-on-the-planet/ this Microsoft blog] or the [[wikipedia:Virtual File System for Git|Wikipedia article]].) <br />
<br />
It already has a successor : [https://github.com/microsoft/scalar Scalar], which is available in {{AUR|git-vfs}}, Microsoft's fork of git including gvfs and scalar.<br />
<br />
=== Filtering confidential information ===<br />
<br />
Occasionally, software may keep plain-text passwords in configuration files, as opposed to hooking into a keyring. In these cases, git clean-filters may be handy to avoid accidentally commiting confidential information. E. g., the following file assigns a filter to the file “some-dotfile”:<br />
<br />
{{hc|.gitattributes|<nowiki><br />
some-dotfile filter=remove-pass<br />
</nowiki>}}<br />
<br />
Whenever the file “some-dotfile” is checked into git, git will invoke the filter “remove-pass” on the file before checking it in. The filter must be defined in the git-configuration file, e. g.:<br />
<br />
{{hc|.git/config|<nowiki><br />
[filter "remove-pass"]<br />
clean = "sed -e 's/^password=.*/#password=TODO/'"<br />
</nowiki>}}<br />
<br />
{{Note|Escaping special characters for sed expressions can be a [https://stackoverflow.com/questions/49652495/git-filter-and-sed-fight-over tricky task] in this context. Remember that git is turning two backslashes into one, while the shell that git invokes to run commands will again turn two backslashes into one. For more details, see [https://stackoverflow.com/a/49654653 Git filter and sed fight over `\$`].}}<br />
<br />
=== HTML help files ===<br />
<br />
The {{ic|git help}} documentation is also available in HTML form by installing {{AUR|git-htmldocs}}. After installing, the HTML docs can be accessed by passing the {{ic|-w}} flag. For example:<br />
<br />
$ git help -w merge<br />
<br />
The HTML documentation can be loaded by default by setting a {{ic|git config}} option:<br />
<br />
$ git config --global help.format html<br />
<br />
== Extensions ==<br />
<br />
* {{App|gitflow-avh|Extend git with [https://nvie.com/posts/a-successful-git-branching-model/ Vincent Driessen's branching model]. The AVH Edition adds more functionality.|https://github.com/petervanderdoes/gitflow|{{AUR|gitflow-avh}}}}<br />
* {{App|git-extras|some utilities for git (repo summary, repl,changelog population, author commit percentages, etc.)|https://github.com/tj/git-extras|{{AUR|git-extras}}}} - If you're using [https://ohmyz.sh oh-my-zsh], you may also enable [https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/git-extras git-extras plugin]<br />
* {{App|gitmoji-cli|A [https://gitmoji.dev/ gitmoji] interactive NodeJS client for using gitmojis on commit messages.|https://github.com/carloscuesta/gitmoji-cli|{{AUR|nodejs-gitmoji-cli}}}}<br />
<br />
== See also ==<br />
<br />
* Git man pages, see {{man|1|git}}<br />
* [https://git-scm.com/book/en/ Pro Git book]<br />
* [https://git.github.io/git-reference/ Git Reference] by GitHub<br />
* [https://web.archive.org/web/20150316035247/https://nathanhoad.net/git-workflow-forks-remotes-and-pull-requests Git workflow: Forks, remotes, and pull requests]<br />
* [https://wiki.videolan.org/Git VideoLAN wiki article]<br />
* [https://gist.github.com/grawity/4392747 A comparison of protocols GitHubGist]{{Dead link|2023|04|23|status=404}}<br />
* [https://gun.io/blog/how-to-github-fork-branch-and-pull-request How to GitHub]</div>Julhttps://wiki.archlinux.org/index.php?title=Color_output_in_console&diff=777326Color output in console2023-05-06T22:35:57Z<p>Jul: Terminate the second color argument. This is to avoid 'Invalid color string' errors for utilities that modify LESS variable by appending an option to it like this: LESS="${LESS}p^COMMANDS" man less</p>
<hr />
<div>[[Category:Linux console]]<br />
[[Category:Eye candy]]<br />
[[ja:コンソールのカラー出力]]<br />
[[ru:Color output in console]]<br />
[[zh-hans:Color output in console]]<br />
{{Expansion|And maybe create something bigger. Please take active approach if you can add some valuable information. Mention {{Pkg|python-pywal}}.|Talk:Color output in console#Why and what this page is about}}<br />
{{Style|Page is partly a collection of information on different applications, partly begin to lay theory to color output process. Please contribute your knowledge, if you can.}}<br />
{{Related articles start}}<br />
{{Related|Emacs#Custom colors and theme}}<br />
{{Related|nano#Syntax highlighting}}<br />
{{Related articles end}}<br />
This page was created to consolidate colorization of CLI outputs.<br />
<br />
== Background ==<br />
<br />
{{Expansion|Probably a good idea to move the list-color scripts here now.}}<br />
<br />
=== Escape sequences ===<br />
<br />
The [[Wikipedia:ANSI escape sequence|ANSI escape sequences]] define a way to put additional information into terminal output, and color is part of this "additional information". Throughout the years the range of terminal colors has been vastly expanded, from the initial eight colors to a full 24-bit truecolor.<br />
<br />
The basic color encoding provides 8 normal-brightness colors and 8 brighter versions of these colors. Modern terminal emulators, including the Linux console itself, allows you to specify the precise RGB values that the colors translate to. This mode is supported by almost all terminal emulators.<br />
<br />
With the advent of 256-color displays came the 256-color escape. The 256 colors are the 16 basic colors, the 216 RGB colors (laid out in a 6x6x6 cube), and 24 levels of greyscale. Except for the first 16 colors, the scheme is usually not customizable as it has a well-defined mapping to RGB. This mode is supported by most terminal emulators. (A minority of emulators use a similar but incompatible encoding with only 88 colors. You are very unlikely to use them in practise, but they will appear in the terminfo database.)<br />
<br />
Less commonly supported is the truecolor mode, allowing one to use 16.7 million (2<sup>24</sup>) colors in RGB (each value ranging from 0 to 255).<br />
<br />
=== Termcap and terminfo ===<br />
<br />
Termcap and terminfo, part of {{Pkg|ncurses}}, are databases that provide information on the escape sequences terminals (usually specified by the {{ic|TERM}} env-var) understand. The {{man|1|tput}} and {{man|1|infocmp}} commands can be used to access them from command-line.<br />
<br />
== Applications ==<br />
<br />
=== diff ===<br />
<br />
diffutils from version 3.4 includes the {{ic|--color}} option ([https://lists.gnu.org/archive/html/info-gnu/2016-08/msg00004.html GNU mailing list]).<br />
<br />
$ alias diff='diff --color=auto'<br />
<br />
=== grep ===<br />
<br />
The {{ic|1=--color=auto}} option enables color highlighting. Color codes are emitted only on standard output; not in pipes or redirection.<br />
<br />
Color output in ''grep'' is also useful with [[Wikipedia:regexp|regexp]] tasks.<br />
<br />
Use an [[alias]] to permanently enable this option:<br />
<br />
alias grep='grep --color=auto'<br />
<br />
The {{ic|GREP_COLORS}} variable is used to define colors, and it configures various parts of highlighting. To change the colors, find the needed [https://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html ANSI escape sequence] and apply it. See {{man|1|grep|GREP COLORS}} for more information.<br />
<br />
The {{ic|-n}} option includes file line numbers in the output.<br />
<br />
=== ip ===<br />
<br />
{{man|8|ip}} command from {{Pkg|iproute2}} supports colors with {{ic|-c}} option. You can use an [[alias]] to enable colored output. When using {{ic|auto}} parameter, colored output will be enabled only when stdout is a terminal.<br />
<br />
alias ip='ip -color=auto'<br />
<br />
=== less ===<br />
<br />
==== Environment variables ====<br />
<br />
As with the [[#man]] case, we can tell less to emit colors when it is meaning to make bold text and other formatting effects.<br />
<br />
Add the following lines to your shell configuration file:<br />
<br />
export LESS='-R --use-color -Dd+r$Du+b$'<br />
<br />
It will set red for bold and blue for underlined.<br />
<br />
For more information about the {{ic|--use-color}} and {{ic|-D}} options, see {{man|1|less|D}} or [https://felipec.wordpress.com/2021/06/05/adventures-with-man-color/].<br />
<br />
==== Reading from stdin ====<br />
<br />
{{Note|It is recommended to add colored output through [[#Environment variables]] to your {{ic|~/.bashrc}} or {{ic|~/.zshrc}}, as the below is based on {{ic|1=export LESS='-R'}}}}<br />
<br />
When you run a command and pipe its [[Wikipedia:Standard output|standard output]] (''stdout'') to ''less'' for a paged view (e.g. {{ic|<nowiki>pacman -Qe | less</nowiki>}}), you may find that the output is no longer colored. This is usually because the program tries to detect if its ''stdout'' is an interactive terminal, in which case it prints colored text, and otherwise prints uncolored text. This is good behaviour when you want to redirect ''stdout'' to a file, e.g. {{ic|<nowiki>pacman -Qe > pkglst-backup.txt</nowiki>}}, but less suited when you want to view output in {{ic|less}}.<br />
<br />
Some programs provide an option to disable the interactive tty detection:<br />
<br />
# dmesg --color=always | less<br />
<br />
In case that the program does not provide any similar option, it is possible to trick the program into thinking its ''stdout'' is an interactive terminal with the following utilities:<br />
<br />
* {{App|ColorThis|Force colored output of a program by running it within a (group of) pty, support forwarding stdin.|https://github.com/Sasasu/ColorThis|{{AUR|colorthis-git}}}}<br />
* {{App|stdoutisatty|A small program and a {{ic|LD_PRELOAD}}-able library that catches the {{man|3|isatty}} function call.|https://github.com/lilydjwg/stdoutisatty.|{{pkg|stdoutisatty}}}}<br />
:Example: {{ic|stdoutisatty ''program'' <nowiki>| less</nowiki>}}<br />
* {{App|unbuffer|A tclsh script comes with expect, it invokes desired program within a pty.|http://expect.sourceforge.net/example/unbuffer.man.html|{{Pkg|expect}}}}<br />
:Example: {{ic|unbuffer ''program'' <nowiki>| less</nowiki>}}<br />
<br />
Alternatively, using [http://zsh.sourceforge.net/Doc/Release/Zsh-Modules.html#The-zsh_002fzpty-Module zpty] module from [[zsh]]: [https://blog.lilydjwg.me/2011/6/29/using-zpty-module-of-zsh.27677.html]<br />
<br />
{{hc|~/.zshrc|<nowiki><br />
zmodload zsh/zpty<br />
<br />
pty() {<br />
zpty pty-${UID} ${1+$@}<br />
if [[ ! -t 1 ]];then<br />
setopt local_traps<br />
trap '' INT<br />
fi<br />
zpty -r pty-${UID}<br />
zpty -d pty-${UID}<br />
}<br />
<br />
ptyless() {<br />
pty $@ | less<br />
}<br />
</nowiki>}}<br />
<br />
Usage:<br />
<br />
$ ptyless ''program''<br />
<br />
To pipe it to other pager (less in this example):<br />
<br />
$ pty ''program'' | less<br />
<br />
=== ls ===<br />
<br />
The {{ic|1=--color=auto}} option enables color highlighting. Color codes are emitted only on standard output; not in pipes or redirection.<br />
<br />
Use an [[alias]] to permanently enable this option:<br />
<br />
alias ls='ls --color=auto'<br />
<br />
The {{ic|LS_COLORS}} variable is used to define colors, and it configures various parts of highlighting. Use the {{man|1|dircolors}} command to set it. <br />
<br />
An advanced alternative to ''dircolors'' that ships with many themes is the {{Pkg|vivid}} package, see {{ic|vivid --help}} for usage.<br />
<br />
{{Note|Using the {{ic|--color}} option may incur a noticeable performance penalty when ''ls'' is run in a directory with very many entries. The default settings require ''ls'' to {{man|1|stat}} every single file it lists. However, if you would like most of the file-type coloring but can live without the other coloring options (e.g. executable, orphan, sticky, other-writable, capability), use ''dircolors'' to set the {{ic|LS_COLORS}} environment variable like this:<br />
<br />
<nowiki>eval $(dircolors -p | perl -pe 's/^((CAP|S[ET]|O[TR]|M|E)\w+).*/$1 00/' | dircolors -)</nowiki><br />
<br />
}}<br />
<br />
See {{man|1|ls}} for more information.<br />
<br />
=== man ===<br />
<br />
There is a real color facility in {{man|1|grotty}}, but it is strongly discouraged for man pages. Here we fake a colored {{Ic|man}} by hacking two main pagers, {{Ic|less}} and {{Ic|most}}: we replace the sequences for bold, standout, and underline with spiced ones that contain color.<br />
<br />
==== Using bat ====<br />
<br />
{{Pkg|bat}} can be used as a colorizing pager for man, by setting the {{ic|MANPAGER}} environment variable<br />
[https://github.com/sharkdp/bat#man as documented here].<br />
<br />
==== Using less ====<br />
<br />
See [[#less]] for a more detailed description.<br />
<br />
export MANPAGER="less -R --use-color -Dd+r -Du+b"<br />
<br />
For [[Fish]] you could accomplish this with:<br />
<br />
{{hc|~/.config/fish/config.fish|2=<br />
set -xU MANPAGER 'less -R --use-color -Dd+r -Du+b'<br />
}}<br />
<br />
Remember to source your config or restart your shell to make the changes take effect.<br />
<br />
==== Using most ====<br />
<br />
The basic function of 'most' is similar to {{Ic|less}} and {{Ic|more}}, but it has a smaller feature set. Configuring most to use colors is easier than using less, but additional configuration is necessary to make most behave like less.<br />
Install the {{Pkg|most}} package.<br />
<br />
Edit {{ic|/etc/man_db.conf}}, uncomment the pager definition and change it to:<br />
<br />
DEFINE pager most -s<br />
<br />
Test the new setup by typing:<br />
<br />
$ man whatever_man_page<br />
<br />
Modifying the color values requires editing {{ic|~/.mostrc}} (creating the file if it is not present) or editing {{ic|/etc/most.conf}} for system-wide changes. Example {{ic|~/.mostrc}}:<br />
<br />
% Color settings<br />
color normal lightgray black<br />
color status yellow blue<br />
color underline yellow black<br />
color overstrike brightblue black<br />
<br />
A list of all keybindings may be found at {{ic|/usr/share/doc/most/most-fun.txt}}. To get a basic {{ic|less}}/{{ic|vim}}-like configuration, you can copy {{ic|/usr/share/doc/most/lesskeys.rc}} to {{ic|~/.mostrc}}. The lesskeys rc included with most does not include 'g' or 'G', so you will also have to add these lines to {{ic|~/.mostrc}}:<br />
<br />
setkey bob "g"<br />
setkey eob "G"<br />
setkey page_down "d"<br />
setkey page_up "u"<br />
<br />
You may also want to set the {{ic|goto_line}} keybinding in the rc if you do not like the default of 'J'.<br />
<br />
Another example showing keybindings similar to {{Ic|less}} (jump to line is set to 'J'):<br />
<br />
% less-like keybindings<br />
unsetkey "^K"<br />
unsetkey "g"<br />
unsetkey "G"<br />
unsetkey ":"<br />
<br />
setkey next_file ":n"<br />
setkey find_file ":e"<br />
setkey next_file ":p"<br />
setkey toggle_options ":o"<br />
setkey toggle_case ":c"<br />
setkey delete_file ":d"<br />
setkey exit ":q"<br />
<br />
setkey bob "g"<br />
setkey eob "G"<br />
setkey down "e"<br />
setkey down "E"<br />
setkey down "j"<br />
setkey down "^N"<br />
setkey up "y"<br />
setkey up "^Y"<br />
setkey up "k"<br />
setkey up "^P"<br />
setkey up "^K"<br />
setkey page_down "f"<br />
setkey page_down "^F"<br />
setkey page_up "b"<br />
setkey page_up "^B"<br />
setkey other_window "z"<br />
setkey other_window "w"<br />
setkey search_backward "?"<br />
setkey bob "p"<br />
setkey goto_mark "'"<br />
setkey find_file "E"<br />
setkey edit "v"<br />
<br />
==== Using X resources ====<br />
<br />
A quick way to add color to manual pages viewed on {{Pkg|xterm}}/{{Ic|uxterm}} or {{Pkg|rxvt-unicode}} is to modify {{ic|~/.Xresources}}.<br />
<br />
===== xterm =====<br />
<br />
*VT100.colorBDMode: true<br />
*VT100.colorBD: red<br />
*VT100.colorULMode: true<br />
*VT100.colorUL: cyan<br />
<br />
which ''replaces'' the decorations with the colors. Also add:<br />
<br />
*VT100.veryBoldColors: 6<br />
<br />
if you want colors and decorations (bold or underline) ''at the same time''. See {{man|1|xterm|veryBoldColors}} for more information.<br />
<br />
===== rxvt-unicode =====<br />
<br />
URxvt.colorIT: #87af5f<br />
URxvt.colorBD: #d7d7d7<br />
URxvt.colorUL: #87afd7<br />
<br />
Run:<br />
<br />
$ xrdb -load ~/.Xresources<br />
<br />
Launch a new {{Ic|xterm/uxterm}} or {{Ic|rxvt-unicode}} and you should see colorful man pages.<br />
<br />
This combination puts colors to '''bold''' and <u>underlined</u> words in {{Ic|xterm/uxterm}} or to '''bold''', <u>underlined</u>, and ''italicized'' text in {{Ic|rxvt-unicode}}. You can play with different combinations of these attributes. See the [https://web.archive.org/web/20210512042458/http://vger.cz/setup/XFree86/app-defaults/XTerm sources] (archived) of this item.<br />
<br />
=== pacman ===<br />
<br />
[[Pacman]] has a color option. Uncomment the {{ic|Color}} line in {{ic|/etc/pacman.conf}}.<br />
<br />
== Wrappers ==<br />
<br />
{{move||Some of these could be made into sections of their own, or moved to existing sections such as [[#diff]]}}<br />
<br />
=== Universal wrappers ===<br />
<br />
(most of them outdated, but still functioning)<br />
<br />
They go with multiple preconfigured presets that can be changed, and new ones can be created/contributed.<br />
<br />
{{Warning|Wrappers replace output of commands with escape sequences. Some shell scripts and programs which use the output of standard shell utilities may not work correctly.}}<br />
<br />
* {{App|rainbow|Colorize commands output or STDIN using patterns.<br>Presets: df, diff, env, host, ifconfig, java-stack-trace, jboss, jonas, md5sum, mvn2, mvn3, ping, tomcat, top, traceroute.|https://github.com/nicoulaj/rainbow|{{AUR|rainbow}}}}<br />
* {{App|grc|Yet another colouriser for beautifying your logfiles or output of commands.<br>Presets: cat, cvs, df, diff, dig, gcc, g++, ls, ifconfig, make, mount, mtr, netstat, ping, ps, tail, traceroute, wdiff, blkid, du, dnf, docker, docker-machine, env, id, ip, iostat, last, lsattr, lsblk, lspci, lsmod, lsof, getfacl, getsebool, ulimit, uptime, nmap, fdisk, findmnt, free, semanage, sar, ss, sysctl, systemctl, stat, showmount, tune2fs and tcpdump.|https://github.com/garabik/grc|{{Pkg|grc}}}}<br />
* {{App|cope|A colourful wrapper for terminal programs.<br>Presets: acpi, arp, cc, df, dprofpp, fdisk, free, g++, gcc, id, ifconfig, ls, lspci, lsusb, make, md5sum, mpc, netstat, nm, nmap, nocope, ping, pmap, ps, readelf, route, screen, sha1sum, sha224sum, sha256sum, sha384sum, sha512sum, shasum, socklist, stat, strace, tcpdump, tracepath, traceroute, w, wget, who, xrandr.|https://github.com/yogan/cope|{{AUR|cope-git}}}}<br />
* {{App|cw|A non-intrusive real-time ANSI color wrapper for common unix-based commands. Wraps {{Pkg|file}} which can cause issues.<br>Presets: arp, arping, auth.log@, blockdev, cal, cksum, clock, configure, cpuinfo@, crontab@, cw-pipe, cw-test.cgi, date, df, diff, dig, dmesg, du, env, figlet, file, find, finger, free, fstab@, fuser, g++, gcc, group@, groups, hdparm, hexdump, host, hosts@, id, ifconfig, inittab@, iptables, last, lastlog, lsattr, lsmod, lsof, ltrace-color, make, md5sum, meminfo@, messages@, mount, mpg123, netstat, nfsstat, nmap, nslookup, objdump, passwd@, ping, pmap, pmap_dump, praliases, profile@, protocols@, ps, pstree, quota, quotastats, resolv.conf@, route, routel, sdiff, services@, showmount, smbstatus, stat, strace-color, sysctl, syslog, tar, tcpdump, tracepath, traceroute, umount, uname, uptime, users, vmstat, w, wc, whereis, who, xferlog.|http://cwrapper.sourceforge.net/|{{AUR|cw}}}}<br />
* {{App|ccze|A fast log colorizer written in C, intended to be a drop-in replacement for colorize|https://github.com/cornet/ccze/|{{Pkg|ccze}}}}<br />
<br />
=== Libraries for colorizing an output ===<br />
<br />
* {{App|libtextstyle|A C library for styling text output to terminals|https://www.gnu.org/software/gettext/libtextstyle/manual/index.html|{{Pkg|gettext}}}}<br />
* {{App|ruby-rainbow|Rainbow is extension to ruby's String class adding support for colorizing text on ANSI terminal|https://rubygems.org/gems/rainbow/|{{Pkg|ruby-rainbow}}}}<br />
* {{App|python-blessings|A thin, practical wrapper around terminal coloring, styling, and positioning|https://github.com/erikrose/blessings|{{AUR|python-blessings}}}}<br />
* {{App|lolcat|Ruby program that makes the output colorful like a rainbow|https://github.com/busyloop/lolcat/|{{Pkg|lolcat}}}}<br />
<br />
=== Application specific ===<br />
<br />
==== Compilers ====<br />
<br />
* {{App|colorgcc|A Perl wrapper to colorize the output of compilers with warning/error messages matching the gcc output format|https://schlueters.de/colorgcc.html|{{Pkg|colorgcc}}}}<br />
<br />
==== diff ====<br />
<br />
Diff has [[#diff|built-in color output]], which is reasonable to use. But the following wrappers can be used:<br />
<br />
* {{App|colordiff|Perl script for ''diff'' highlighting.|https://www.colordiff.org/|{{Pkg|colordiff}}}}<br />
* {{App|cwdiff|''(w)diff'' wrapper with directories support and highlighting.|https://github.com/junghans/cwdiff|{{AUR|cwdiff}}}}<br />
* {{App|git-delta|A syntax-highlighting pager for git and diff output.|https://github.com/dandavison/delta|{{Pkg|git-delta}}}}<br />
<br />
==== cat ====<br />
<br />
* {{App|bat|Cat clone with syntax highlighting and git integration.|https://github.com/sharkdp/bat|{{Pkg|bat}}}}<br />
<br />
==== less ====<br />
<br />
===== source-highlight =====<br />
<br />
You can enable code syntax coloring in ''less''. First, [[install]] {{Pkg|source-highlight}}, then add these lines to your shell configuration file:<br />
<br />
{{hc|~/.bashrc|<nowiki><br />
export LESSOPEN="| /usr/bin/source-highlight-esc.sh %s"<br />
export LESS='-R '<br />
</nowiki>}}<br />
<br />
===== lesspipe =====<br />
<br />
Frequent users of the command line interface might want to install {{Pkg|lesspipe}}.<br />
<br />
Users may now list the compressed files inside of an archive using their pager:<br />
<br />
{{hc|$ less ''compressed_file''.tar.gz|2=<br />
==> use tar_file:contained_file to view a file in the archive<br />
-rw------- ''username''/''group'' 695 2008-01-04 19:24 ''compressed_file''/''content1''<br />
-rw------- ''username''/''group'' 43 2007-11-07 11:17 ''compressed_file''/''content2''<br />
''compressed_file''.tar.gz (END)<br />
}}<br />
<br />
''lesspipe'' also grants ''less'' the ability of interfacing with files other than archives, serving as an alternative for the specific command associated for that file-type (such as viewing HTML via {{Pkg|python-html2text}}).<br />
<br />
Re-login after installing ''lesspipe'' in order to activate it, or source {{ic|/etc/profile.d/lesspipe.sh}}.<br />
<br />
==== Make ====<br />
<br />
* {{App|colormake|A simple wrapper around make to make its output more readable.|https://github.com/pagekite/Colormake/|{{AUR|colormake}}}}<br />
<br />
==== Ping ====<br />
<br />
* {{App|prettyping|Add some great features to ping monitoring. A wrapper around the standard ping tool with the objective of making the output prettier, more colorful, more compact, and easier to read.|https://denilson.sa.nom.br/prettyping/|{{Pkg|prettyping}}}}<br />
<br />
== Shells ==<br />
<br />
=== bash ===<br />
<br />
See [[Bash/Prompt customization#Colors]].<br />
<br />
=== Fish ===<br />
<br />
See [[Fish#Web interface]].<br />
<br />
=== xonsh ===<br />
<br />
See [https://xon.sh/tutorial.html#customizing-the-prompt Customizing the Prompt].<br />
<br />
=== zsh ===<br />
<br />
See [[Zsh#Colors]].<br />
<br />
== Terminal emulators ==<br />
<br />
=== Virtual console ===<br />
<br />
{{Style|Lacks clarity on what "the colors" are, i.e. in [[#Virtual console]] they are about the ''representations'' of the 16 base colors (RGB values for yellow, red, blue, etc.), while in [[#Login screen]] they are about the base colors themselves. See also {{man|4|console_codes}} and [[User:Isacdaavid/Linux_Console]]}}<br />
<br />
The colors in the [[w:Virtual console|Linux virtual console]] running on the framebuffer can be changed. This is done by writing the escape code {{ic|\\e]PXRRGGBB}}, where {{ic|X}} is the hexadecimal index of the color from 0-F, and {{ic|RRGGBB}} is a traditional hexadecimal RGB code. <br />
<br />
For example, to reuse existing colors defined in {{ic|~/.Xresources}}, add the following to the shell initialization file (such as {{ic|~/.bashrc}}):<br />
<br />
if [ "$TERM" = "linux" ]; then<br />
_SEDCMD='s/.*\*color\([0-9]\{1,\}\).*#\([0-9a-fA-F]\{6\}\).*/\1 \2/p'<br />
for i in $(sed -n "$_SEDCMD" $HOME/.Xresources | awk '$1 < 16 {printf "\\e]P%X%s", $1, $2}'); do<br />
echo -en "$i"<br />
done<br />
clear<br />
fi<br />
<br />
==== Login screen ====<br />
<br />
The below is a colored example of the virtual console login screen in {{ic|/etc/issue}}. Create a backup of the original file with {{ic|mv /etc/issue /etc/issue.bak}} as root, and create a new {{ic|/etc/issue}}:<br />
<br />
\e[H\e[2J<br />
\e[1;30m| \e[34m\r \s<br />
\e[36;1m/\\\\ \e[37m|| \e[36m| = \e[30m|<br />
\e[36m/ \\\\ \e[37m|| \e[36m| \e[30m| \e[32m\t<br />
\e[1;36m/ \e[0;36m.. \e[1m\\\\ \e[37m//==\\\\\\ ||/= /==\\\\ ||/=\\\\ \e[36m| | |/\\\\ | | \\\\ / \e[30m| \e[32m\d<br />
\e[0;36m/ . . \\\\ \e[37m|| || || || || || \e[36m| | | | | | X \e[1;30m|<br />
\e[0;36m/ . . \\\\ \e[37m\\\\\\==/| || \\\\==/ || || \e[36m| | | |\ \\/| / \\\\ \e[1;30m| \e[31m\U<br />
\e[0;36m/ .. .. \\\\ \e[0;37mA simple, lightweight linux distribution. \e[1;30m|<br />
\e[0;36m/_' `_\\\\ \e[1;30m| \e[35m\l \e[0mon \e[1;33m\n<br />
\e[0m <br />
<br />
See also:<br />
<br />
* https://bbs.archlinux.org/viewtopic.php?pid=386429#p386429<br />
* https://www.linuxfromscratch.org/blfs/view/svn/postlfs/logon.html<br />
<br />
=== X window system ===<br />
<br />
Most [[Xorg]] terminals, including [[xterm]] and [[urxvt]], support at least 16 basic colors. The colors 0-7 are the 'normal' colors. Colors 8-15 are their 'bright' counterparts, used for highlighting. These colors can be modified through [[X resources]], or through specific terminal settings. For example:<br />
<br />
{{hc|1=~/.Xresources|2=<br />
! Black + DarkGrey<br />
*color0: #000000<br />
*color8: #555753<br />
! DarkRed + Red<br />
*color1: #ff6565<br />
*color9: #ff8d8d<br />
! DarkGreen + Green<br />
*color2: #93d44f<br />
*color10: #c8e7a8<br />
! DarkYellow + Yellow<br />
*color3: #eab93d<br />
*color11: #ffc123<br />
! DarkBlue + Blue<br />
*color4: #204a87<br />
*color12: #3465a4<br />
! DarkMagenta + Magenta<br />
*color5: #ce5c00<br />
*color13: #f57900<br />
!DarkCyan + Cyan (both not tango)<br />
*color6: #89b6e2<br />
*color14: #46a4ff<br />
! LightGrey + White<br />
*color7: #cccccc<br />
*color15: #ffffff<br />
}}<br />
<br />
{{Warning|Color resources such as {{ic|foreground}} and {{ic|background}} can be read by other applications (such as [https://www.gnu.org/software/emacs/manual/html_node/emacs/Table-of-Resources.html emacs]). This can be avoided by specifiying the class name, for example {{ic|XTerm.foreground}}.}}<br />
<br />
See also:<br />
<br />
* [[#Using X resources]] for how to color bold and underlined text automatically.<br />
* [https://web.archive.org/web/20090130061234/http://phraktured.net/terminal-colors/ Color Themes] - Extensive list of terminal color themes by Phraktured.<br />
* [https://github.com/dkeg/xcolors Xcolors by dkeg] (see files with paths matching {{ic|theme/dkeg - ''theme''}} in the repository)<br />
* [https://github.com/chriskempson/base16 base16 color schemes]<br />
<br />
=== Display the 256 colors ===<br />
<br />
{{Expansion|256 is far from "all" the colors. We really need a bit of introduction to the various color modes.}}<br />
<br />
Prints the 256 colors across the screen.<br />
<br />
$ (x=`tput op` y=`printf %76s`;for i in {0..256};do o=00$i;echo -e ${o:${#o}-3:3} `tput setaf $i;tput setab $i`${y// /=}$x;done)<br />
<br />
=== Display tput escape codes ===<br />
<br />
{{Merge|Bash/Prompt_customization|More context on ''tput'' is provided in that article}}<br />
<br />
Replace {{ic|tput op}} with whatever tput you want to trace. {{ic|op}} is the default foreground and background color.<br />
<br />
{{hc|<nowiki>$ ( strace -s5000 -e write tput op 2>&2 2>&1 ) | tee -a /dev/stderr | grep -o '"[^"]*"'</nowiki>|<br />
033[\033[1;34m"\33[39;49m"\033[00m<br />
}}<br />
<br />
=== Enumerate supported colors ===<br />
<br />
The following command will let you discover all the terminals you have terminfo support for, and the number of colors each terminal supports. The possible values are: 8, 15, 16, 52, 64, 88 and 256.<br />
<br />
{{hc|<nowiki>$ for T in `find /usr/share/terminfo -type f -printf '%f '`;do echo "$T `tput -T $T colors`";done|sort -nk2</nowiki>|<br />
Eterm-88color 88<br />
rxvt-88color 88<br />
xterm+88color 88<br />
xterm-88color 88<br />
Eterm-256color 256<br />
gnome-256color 256<br />
konsole-256color 256<br />
putty-256color 256<br />
rxvt-256color 256<br />
screen-256color 256<br />
screen-256color-bce 256<br />
screen-256color-bce-s 256<br />
screen-256color-s 256<br />
xterm+256color 256<br />
xterm-256color 256<br />
}}<br />
<br />
=== Enumerate terminal capabilities ===<br />
<br />
{{Merge|Bash/Prompt_customization|More context on ''tput'' is provided in that article}}<br />
<br />
This command is useful to see what features that are supported by your terminal.<br />
<br />
{{hc|<nowiki>$ infocmp -1 | tr -d '\0\t,' | cut -f1 -d'=' | grep -v "$TERM" | sort | column -c80</nowiki>|<br />
acsc ed kcuu1 kich1 rmso<br />
am el kDC kLFT rmul<br />
bce el1 kdch1 km rs1<br />
bel enacs kel kmous rs2<br />
blink eo kend knp s0ds<br />
bold flash kEND kNXT s1ds<br />
btns#5 fsl kent kpp s2ds<br />
bw home kf1 kPRV s3ds<br />
ccc hpa kf10 kRIT sc<br />
civis hs kf11 kslt setab<br />
clear ht kf12 lines#24 setaf<br />
cnorm hts kf13 lm#0 setb<br />
colors#0x100 ich kf14 mc0 setf<br />
cols#80 ich1 kf15 mc4 sgr<br />
cr il kf16 mc5 sgr0<br />
csr il1 kf17 mc5i sitm<br />
cub ind kf18 mir smacs<br />
cub1 indn kf19 msgr smam<br />
cud initc kf2 ncv#0 smcup<br />
cud1 is1 kf20 npc smir<br />
cuf is2 kf3 op smkx<br />
cuf1 it#8 kf4 pairs#0x7fff smso<br />
cup ka1 kf5 rc smul<br />
cuu ka3 kf6 rev tbc<br />
cuu1 kb2 kf7 ri tsl<br />
cvvis kbs kf8 rin u6<br />
dch kc1 kf9 ritm u7<br />
dch1 kc3 kfnd rmacs u8<br />
dl kcbt kFND rmam u9<br />
dl1 kcub1 kHOM rmcup vpa<br />
dsl kcud1 khome rmir xenl<br />
ech kcuf1 kIC rmkx xon<br />
<br />
}}<br />
<br />
=== Color scheme scripts ===<br />
<br />
See [https://paste.xinu.at/m-dAiJ/] for scripts which display a chart of your current terminal scheme.<br />
<br />
=== True color support ===<br />
<br />
Some terminals support the full range of 16 million colors (RGB, each with 8 bit resolution): xterm, konsole, st, etc. The corresponding TERM values {{ic|xterm-direct}}, {{ic|konsole-direct}}, {{ic|st-direct}}, etc. are supported starting with ncurses version 6.1 [https://lists.gnu.org/archive/html/bug-ncurses/2018-01/msg00045.html]. For more info about terminal emulators and applications that support true color, see [https://github.com/termstandard/colors/blob/master/README.md].<br />
<br />
Note that the Linux kernel supports the SGR (Select Graphic Rendition) escape sequences for true-color, but it is pointless to use it, because the driver maps the 24-bit color specifications to a 256-colors color map in the kernel (see the functions {{ic|rgb_foreground}}, {{ic|rgb_background}}). For this reason, there is no terminfo entry {{ic|linux-direct}}.<br />
<br />
== See also ==<br />
<br />
* [https://gkbrk.com/2016/07/lolcat-clone-in-x64-assembly/ lolcat clone in x64 assembly]</div>Julhttps://wiki.archlinux.org/index.php?title=Install_Arch_Linux_via_SSH&diff=584645Install Arch Linux via SSH2019-10-07T16:50:37Z<p>Jul: Added tip: set TERM variable</p>
<hr />
<div>[[Category:Installation process]]<br />
[[Category:Secure Shell]]<br />
[[cs:Install from SSH]]<br />
[[es:Install from SSH]]<br />
[[it:Install from SSH]]<br />
[[ja:SSH からインストール]]<br />
[[pt:Install from SSH]]<br />
[[ru:Install from SSH]]<br />
[[zh-hans:Install from SSH]]<br />
{{Move|Installation via SSH|Sounds better.}}<br />
This article is intended to show users how to install Arch remotely via an [[SSH]] connection. Consider this approach when the host is located remotely or you wish to use the copy/paste ability of an SSH client to do the Arch install.<br />
<br />
== On the remote (target) machine ==<br />
<br />
{{Note|These steps require physical access to the machine. If the host is physically located elsewhere, this may need to be coordinated with another person.}}<br />
<br />
Boot the target machine into a live Arch environment via the [[Getting and installing Arch|Live CD/USB image]]: this will log the user in as root.<br />
<br />
At this point, setup the network on the target machine as for example suggested in [[Installation guide#Connect to the internet]].<br />
<br />
Secondly, setup a root password which is needed for an SSH connection, since the default Arch password for root is empty:<br />
<br />
# passwd<br />
<br />
Now check that {{ic|PermitRootLogin yes}} is present (and uncommented) in {{ic|/etc/ssh/sshd_config}}. This setting allows root login with password authentication on the SSH server.<br />
<br />
Finally, [[start]] the openssh daemon with {{ic|sshd.service}}, which is included by default on the live CD.<br />
<br />
{{Note|Unless required, after installation it is recommended to remove {{ic|PermitRootLogin yes}} from {{ic|/etc/ssh/sshd_config}}.}}<br />
<br />
{{Tip|If the target machine is behind a NAT router, and you require external access, the SSH port (22 by default) will need to be forwarded to the target machine's LAN IP address.}}<br />
<br />
== On the local machine ==<br />
<br />
On the local machine, connect to the target machine via SSH with the following command:<br />
<br />
$ ssh root@''ip.address.of.target''<br />
<br />
{{Tip|If {{ic|Backspace}}, {{ic|Del}}, {{ic|Tab}}, … keys don't work as expected over ssh, then you probably need to set the terminal type correctly:<br />
{{bc|1=$ TERM=linux ssh root@''ip.address.of.target''}}<br />
}}<br />
<br />
From here one is presented with the live environment's welcome message and is able to administer the target machine as if sitting at the physical keyboard. At this point, if the intent is to simply install Arch from the live media, follow the guide at [[Installation guide]]. If the intent is to edit an existing Linux install that got broken, follow the [[Install from existing Linux]] wiki article.<br />
<br />
{{Tip|Consider installing a [[List_of_applications#Terminal_multiplexers|terminal multiplexer]] on the target machine's live (in memory) system, so that if you are disconnected you can reattach to your multiplexer's session.}}</div>Jul