Main Menu

search

You are here

Linux commands

[last updated: 2024-05-01]
Linux home page
top 50 Linux commands (from: digitalOcean)
file and directory commands:
Linux script files
mounting external storage devices

(link to:) tecmint on systemd & systemctl

-----

On (or linked from) this page:

  • General Notes:
  • General Commands:
      apt-get update & upgrade, clear, who, date, inxi, startx
  • File and Directory Commands:
    • File commands:
      cp, mv, rm, find
    • Directory commands:
      pwd, cd, mkdir, rm
    • Ownership and Permission commands:
      chmod, chown
  • System Commands:
      ps, df, raspi-config, reboot, shutdown, dpkg, cat /proc/version and other variations, uname, python --version
  • Conditional & Loop Commands:
      if, while, for
  • Mounting external storage
  • Other Commands:
      sudo, su, exit, lsusb, ls -l, whoami, chown, arecord -l, aplay, echo $PATH, dmesg, ifconfig, ssh

===============================================================

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

  • General commands:
    • Before installing anything new (or even more often), do these commands:
      $ sudo apt-get update
      $ sudo apt-get upgrade
      • $ sudo apt-get update ... synchronizes packages on your system with repository.
      • $ sudo apt-get upgrade ... upgrades all installed packages
        This step takes a few minutes to complete.
      • However recently saw recommendation to use dist-upgrade instead of upgrade.
        I confess I didn't understand the explanations of the differences,
        More study needed, but for now I'll stick with upgrade.
      • There is also confusion over whether to use apt or apt-get.
        Best advice I've seen is that for Linux Mint, apt is sufficient

    • $ reboot ... as name implies...
    • $ shutdown -h now ... as name implies...
    • $ clear ... clears terminal screen
    • $ whoami ... the name of current user
        $ who ... the name of the current user, the terminal they are logged in at, the date and time when they logged in. If it is a remote session, it also tell where they are logged in from.
    • $ date ... gives current date
      • $ sudo date -s "18 APR 2023 07:25:00" ... change date if wrong and offline
    • $ inxi -Fxz ... gives printout of hardware
    • $ startx ... Opens the GUI (Graphical User Interface)
      However this opens automatically on my installation, so I'm not sure when you'd need to use this...

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

  • File and Directory commands:
    -----------------------------------------------------------------

  • System commands:
  • -----------------------------------------------------------------

  • Conditional & Loop Commands:
    • if
    • while
    • for

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

  • Other Commands:
    • $ sudo & su:
      • sudo is used in front of many commands in order to invoke one-time root privilege.
      • $ sudo su ... will change user to root, so that any commands executed will have root privilege, and 'sudo' is not needed with each command.
      • $ exit ... to leave superuser status and return to standard user status.

    • $ lsusb ... shows all USB devices attached
      Especially helpful in troubleshooting Arduino connection issues

    • $ cat /etc/passwd ... shows all defined users
    • $ whoami ... gives name of current user
    • If you wish to change ownership of all files inside a directory, you can use the -R option:
      $ sudo chown -R [user] [path/directory/]
    • $ ls -l ... shows owner
    • $ arecord -l ... list of all audio devices connected
    • $ sudo aplay -l ... list of "devices"
      use: "hw:X,Y", where X is "card number", and Y is "device number"
    • $ which [some command]
      will return the directory where the command executable is located.
    • $ echo $PATH
      prints out the current system variable PATH
        To add another folder to the PATH variable, use:
          $ PATH=$PATH:~/opt/bin
          -or- to add it temporarily...
          $ export PATH="/[dir to add]:$PATH"
          -or- to add it permanently, edit /home/.bashrc
          and add this line to the end of the file:
          export PATH="/Directory1:$PATH"
          save, exit, reboot (or just execute the script - how??)

    • Investigating drivers/modules:
      • $ dmesg
        $ dmesg | grep [module/driver name]

    • $ time [ command ]
      • This command prints out the time consumed to execute the command

    • $ ifconfig
      prints out a bunch of stuff, among which is the IP address of your computer
      This address will usu be dynamic, ie the next time you {log in? reboot?]... you'll have a different IP address
      -----------------------------------------------------------------

    • SSH:
      Suppose you have a "Local Computer", and you want to use it to log into a "Remote Computer".
      Executing SSH on the local computer will allow you to log into the remote computer using your local keyboard.
      Both computers must be on the same network.
        Note, (I think...) this only allows using command-line control, not viewing the entire desktop...

      • first - on the remote computer:
        • open a terminal.
        • find username:
          $ whoami
        • find IP address of remote computer:
          • $ ifconfig
          • On my Dell 4600 laptop, this command output 3 blocks of data
            Relevant line starts with "inet", followed by an IP address that might start with 192.168...
            I had two such blocks, one from my wifi connection, one from wired Ethernet connection.
          • I disconnected thh Ethernet cable, and re-did ifconfig to see which one it was.
            I wanted to use the wired connection rather than wifi.
      • on local computer:
        • open a terminal.
        • $ ssh [username in remote computer]@[IP address of remote computer]

        You'll be prompted for the password of your remote computer.

      • The prompt in your local terminal will change to reflect that you're now logged into your remote computer.
      • when done, close SSH connection on local computer:
        $ exit

      SSH links:
      https://linuxhandbook.com/transfer-files-ssh/
      https://www.simplified.guide/ssh/copy-file

    ----------

  • Transfer files between computers:
    • $ scp [source] [destination]
      You do NOT need to use ssh to log into remote computer.
      The scp command does that automatically, and logs you out again when done.

    • copy a file from a local computer to a remote computer:
      log in to local computer
      open terminal in local computer
      $ scp [path to source file on local computer] [username on remote computer]@[IP of remote computer]:[path to file destination on remote computer]
      you will be prompted for password of the remote computer

    • copy a file from a remote computer to a local computer:
      log in to local computer
      open terminal in local computer
      $ scp [username on remote computer]@[IP of remote computer]:[path to source file on remote computer] [path to file destination on local computer]
      you will be prompted for password of the remote computer

    • copy a directory:
      $ scp -r ...

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

  • ports and sockets: (link to:) tecmint

.

.

.

eof