Main Menu

search

You are here

Linux: system level commands

[last updated: 2025-09-26]
Linux home page
Linux commands
-----

ps, df, raspi-config, reboot, shutdown, dpkg, cat /proc/version and other variations, uname, python --version

  • hardware info:
    • $ uname -m ... shows whether 64-bit or 32-bit system
    • lscpu ... shows processor and related info

  • hostname:
    • Find hostname:
        $ hostname
    • Change hostname:
        $ sudo hostnamectl set-hostname [new_hostname]

  • user name:
    • Find username:
        $ whoami
    • Change username:
        This is un-edited text from somewhere online...

        Changing a username in Linux involves several steps to ensure consistency across the system, including updating the username itself, the home directory, and the primary group. It is crucial to perform these actions while not logged in as the user whose name is being changed.
        Here are the steps to change a username in Linux: Create a Temporary Admin User.
        Create a new temporary user with administrative privileges (e.g., in the sudo group) to perform the changes. This ensures you can still log in and manage the system while the original user's account is being modified.
        Code

        sudo adduser temp_admin
        sudo usermod -aG sudo temp_admin

        Log Out and Log In as Temporary Admin:

        Log out of the current user's session and then log in as the newly created temp_admin user. Change the Username and Home Directory.
        Use the usermod command to change the username and simultaneously move and rename the home directory to match the new username.
        Code

        sudo usermod -l new_username -m -d /home/new_username old_username

        Replace new_username with the desired new username and old_username with the current username. The -m flag moves the home directory content, and -d specifies the new home directory path.

        Change the Primary Group Name (Optional but Recommended):

        If the primary group name is the same as the old username, it is generally recommended to change it to match the new username for consistency.
        Code

        sudo groupmod -n new_username old_username

        Log Out and Log In as the New User:

        Log out of the temp_admin account and log back in using the new_username and its associated password. Remove the Temporary Admin User (Optional).
        Once you have confirmed that the new user account is functioning correctly, you can delete the temporary admin account.
        Code

        sudo userdel -r temp_admin

        The -r flag removes the user's home directory and mail spool as well.
        Important Considerations:

        Backup:

        Before making any system-level changes, it is always advisable to back up important data.
        Active Processes:
        Ensure the user whose name is being changed is not actively logged in or running any processes, as this can lead to errors. Rebooting or dropping to a single-user mode can help prevent issues with active processes and file locks.
        Application Data:
        Some applications might store configuration files or data that reference the old username or home directory path. While the home directory move helps, some applications might require manual adjustments or reconfigurations to function correctly with the new path.

    ----------------------------------------------------------------------------

  • password:
    • If you forget your password, you must do this procedure to reset it:
      • shut down your rpi and remove the SD card.
      • insert the SD card into a SD reader on a different computer.
      • Edit the file:
        boot cmdline.txt
      • At the end of the file, add this text (without the quotes):
          " init=/bin/sh"
      • Save the edit, eject and remove the SD card from the reader.
      • Insert the edited SD card back into your rpi and power-on to boot
      • Boot process will proceed, but then will hang.
        Press the enter key, and you should get a "#" prompt
      • enter this command:
          mount -o remount,rw /dev/mmcblk0p2 /

        press enter
        message should confirm it was remounted

      • type:
          passwd pi

        enter desired new password
        retype to confirm
        message should confirm successful update

      • type:
          synch

        press enter

      • shut down rPi and remove SD card
      • insert SD card back into the other computer with a SD card reader
        again edit the cmdline.txt file
        remove the init line you added previously
      • save, eject, and remove the SD card
        re-install it back into the rPi
      • power-up to boot the rpi
        enter username and new password
        it should boot

    ----------------------------------------------------------------------------

  • memory (MemTot):
    $ cat /proc/meminfo
  • memory (free):
    $ df or df -h
  • processes running:
    $ ps ... lists all processes running (use sudo to see all of them...)
    $ ps -A ... lists info on them
    or - $ ps axg
  • $ sudo raspi-config ... opens original bootup menu for setting various preferences (such as enabling i2c)
  • update & upgrade:
    • These commands update to most current version of software packages. They do Not change your installed core version of Raspbian.
      However there is lots of chat in the forums about the proper/best form/syntax to use. Some of it depends on age/version of your software.
      In any case, here's what I use now:
      • $ sudo apt update
      • $ sudo apt upgrade
    • Some of the forums suggest that upgrade does not remove things that are no longer needed because dependencies have changed.
      If you want to do that, you can follow upgrade with $ sudo apt autoremove
      Or, you can instead use $ sudo apt dist-upgrade, which will correct changed dependencies for you,
      However it's recommended to use dist-upgrade with caution because it can change things you may not want changed...
    • There is also forum chat about the difference between apt and apt-get.
      My best guess is that apt is currently considered to be the best.
  • =================================================
      -----------------------------------------------------------------

      -----------------------------------------------------------------

    • $ cat /proc/sys/vm/swappiness
      Default is 60; lower may speed up operation by reducing the amount of memory swaps that happen.
    • Available Disk Space:
      $ df
      "disk free" shows usage and availability of all partitions
    • List Installed Disks:
      $ lsblk
    • Find version of Linux Kernel you have:
      $ uname -r
      $ hostnamectl | grep Kernel
      $ cat /proc/version

  • Linux & Python info:
    • $ cat /etc/os-release ... returns Linux version
      $ lsb_release -a ... returns the same but shorter (less detail)
      $ hostnamectl ... returns Linux (OS) info, as well as hardware and kernel info
      $ uname -r ... returns Linux kernel

    • $ ls /usr/bin/python* ... what versions of python are loaded?
    • $ python ... what version of python is default?
      This actually opens a python command line interpreter,
      in which you can enter python commands.
      But the opening header lists the version of python that is being executed.
      To exit the program, type <ctrl>d
    • $ python --version ... same
      shows I'm using 3.5.3 (after having done below procedure for updating alternatives list)
    • If you want to change to a different default version of python:
      • first see what's in the "symbol list":
        $ update-alternatives --list python
      • if error, then - no alternatives.
        However it is possible for versions to be installed but still not added to the symbol list,
        so update the list:
        • $ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
          $ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.2 2
          The '1' and '2' at the end of the command is the priority.
          The default will be the one with the highest priority.
      • confirm changes with:
        $ sudo update-alternatives -- list python
        $ python --version
      • now you can change default with:
        $ update-alternatives --config python
        and enter the selection number desired from the table

    • What version of Linux am I running?
      $ cat /etc/os-release
      says I'm currently running Debian Raspbian Linux 9 stretch
      previous versions were: 7 wheezy and 8 jessie

eof