Skip to content

Instantly share code, notes, and snippets.

@barbietunnie
Last active June 29, 2022 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barbietunnie/fd9631c12c357e29d17eea76b50e1f7e to your computer and use it in GitHub Desktop.
Save barbietunnie/fd9631c12c357e29d17eea76b50e1f7e to your computer and use it in GitHub Desktop.
Bash Tips

Bash Tips

List all local users

cut -d: -f1 /etc/passwd

Change file permissions

The permissions can be changed using the chmod keyword. The syntax for the command is:

chmod <flags> <permissions> <filename>
  • flags are the additional options users can set.
  • permissions define if the user can read, write, or execute the file. They can be represented using symbolic or octal numbers.
  • filename is the name of the file whose permission is to be changed.
chmod u=rwx,g=r,o=r file**

where:

  • r gives read permissions
  • w gives write permissions
  • x gives execute permissions

The same command can be run using octal notation:

chmod 744 file

Each digit represents the sum of the permissions allowed:

  • 4 → read permission
  • 2 → write permission
  • 1 → execute permission
  • 0 → no permission

The sum of these permissions are used to represent each type of author.

Generate random password

cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1

Pipefail

set -euo pipefail

-e: Exit immediately if a command exits with a non-zero status.

-u: If you try to access an undefined variable, that is an error.

-o pipefail: If any command in a pipeline returns a non-zero exit code, the return code of the entire pipeline is the exit code of the last failed command.

How to detect OS Architecture (e.g. 386, amd64, arm, or arm64)

dpkg --print-architecture

An alternative is to use uname -m, however, this returns aarch64 rather than arm64 for Apple M1 Silicon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment