Commands tagged hostname (9)

  • I usually have 5 or more ssh connections to various servers, and putting this command in my .bash_profile file makes my putty window or x terminal window title change to this easily recognizable and descriptive text. Includes the username, group, server hostname, where I am connecting from (for SSH tunneling), which device pts, current server load, and how many processes are running. You can also use this for your PROMPT_COMMAND variable, which updates the window title to the current values each time you exec a command. I prefix running this in my .bash_profile with [[ ! -z "$SSH_TTY" ]] && which makes sure it only does this when connecting via SSH with a TTY. Here's some rougher examples from http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html # If set, the value is executed as a command prior to issuing each primary prompt. #H=$((hostname || uname -n) 2>/dev/null | sed 1q);W=$(whoami) #export PROMPT_COMMAND='echo -ne "\033]0;${W}@${H}:${PWD/#$HOME/~} ${SSH_TTY/\/dev\//} [`uptime|sed -e "s/.*: \([^,]*\).*/\1/" -e "s/ //g"`]\007"' #PROMPT_COMMAND='echo -ne "\033]0;`id -un`:`id -gn`@`hostname||uname -n 2>/dev/null|sed 1q` `command who -m|sed -e "s%^.* \(pts/[0-9]*\).*(\(.*\))%[\1] (\2)%g"` [`uptime|sed -e "s/.*: \([^,]*\).*/\1/" -e "s/ //g"` / `command ps aux|wc -l`]\007"' #[[ -z "$SSH_TTY" ]] || export PROMPT_COMMAND #[[ -z "$SSH_TTY" ]] && [[ -f /dev/stdout ]] && SSH_TTY=/dev/stdout And here's a simple function example for setting the title: function set_window_title(){ echo -e "\033]0; ${1:-$USER@$HOST - $SHLVL} \007"; } Show Sample Output


    4
    echo -ne "\033]0;`id -un`:`id -gn`@`hostname||uname -n|sed 1q` `who -m|sed -e "s%^.* \(pts/[0-9]*\).*(\(.*\))%[\1] (\2)%g"` [`uptime|sed -e "s/.*: \([^,]*\).*/\1/" -e "s/ //g"` / `ps aux|wc -l`]\007"
    AskApache · 2009-09-19 06:57:53 4
  • Get your ip address, hostname, ASN and geolocation information. If you want just one field as a text response you can also get that,eg curl ipinfo.io/ip Show Sample Output


    1
    curl ipinfo.io
    coderholic · 2013-10-31 05:16:47 7
  • With sed you can replace strings on the fly.


    1
    sed -i 's/oldname/newname/' /etc/hosts /etc/hostname
    adria · 2014-11-02 22:03:48 24
  • When booting a VM through OpenStack and managed through cloudinit, the hosts file gets to write a line simiar to 127.0.1.1 ns0.novalocal ns0 This command proven useful while installing a configuration manager such as Salt Stack (or Puppet, or Ansible) and getting node name


    0
    sed -e "s/^127.0.1.1 $(hostname).novalocal/127.0.1.1/g" /etc/hosts
    renoirb · 2014-09-25 15:38:43 12
  • useful for human readable reports Show Sample Output


    0
    echo "$HOSTNAME restarted $(uptime | tr , ' ' | awk '{print $3" "$4}') ago"
    forestb · 2015-11-20 19:25:15 10
  • I use it after a clean CentOS 7 minimal server installation to automatically populate the /etc/hosts file. Not sure why the installation does not add this entry by itself. Tested on CentOS 7 with the simplest use case: 1 static ip address and the hostname provided during installation. Show Sample Output


    0
    echo "$(ip addr show dev $(ip r | grep -oP 'default.*dev \K\S*') | grep -oP '(?<=inet )[^/]*(?=/)') $(hostname -f) $(hostname -s)"
    acavagni · 2019-06-15 16:40:38 42
  • I've seen some versions of hostname that don't have the -i option, so this may not work everywhere. When available, it's a better alternative than using ifconfig and wasting eyeball muscle to search for the address, and it's definitely simpler than using awk/sed.


    -2
    hostname -i
    kFiddle · 2009-04-17 21:26:56 7
  • The command above has been changed due to very good constructive criticism - thanks x 2! This command can be used after acquiring mac's, ip's and hostname's or any of the above from a freshly scanned LAN. User must be root, and remember to change your settings on your network managing software manually (Fedc10 NetworkManager Applet 0.7.1 is mine) instead of 'auto DHCP'. You can also substitute eth0 for wlan0 etc - be good and ENJOY!


    -3
    ifconfig eth0 down hw ether (newmacaddresshere) && ifconfig eth0 up && ifconfig eth0 (newipaddresshere) netmask 255.255.255.0 up && /bin/hostname (newhostnamehere)
    localGhost · 2009-06-04 20:25:49 9

  • -3
    python -c "import platform; print platform.node()"
    keimlink · 2010-03-24 09:09:34 5

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands


Check These Out

Get your external IP address ( 10 characters long )
Shortest url to a external IP-service, 10 characters.

execute your commands and avoid history records
$ secret_command;export HISTCONTROL= This will make "secret_command" not appear in "history" list.

Stream YouTube URL directly to mplayer.

Find usb device in realtime
Using this command you can track a moment when usb device was attached.

Write comments to your history.
A null operation with the name 'comment', allowing comments to be written to HISTFILE. Prepending '#' to a command will *not* write the command to the history file, although it will be available for the current session, thus '#' is not useful for keeping track of comments past the current session.

Delicious search with human readable output
You can install filterous with $ sudo apt-get install libxslt1-dev; sudo easy_install -U filterous

list block devices
Shows all block devices in a tree with descruptions of what they are.

Notify me when users log in
Notifyme is a program that listen in background for users login, and report on login and logout. Users can be specified from a list or in a ~/notify.rc file. -C options force to display messages on the center of the screen.See man notifyme for more details. Part of notifyme package, tested on Debian.

Display usb power mode on all devices

hard disk information - Model/serial no.
Get the hard disk information with out shutting down and opening the system. It gives information on model no., serial no., cylinders/heads/sectors, and the supported features of the hard disk.


Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: