mirror of
https://github.com/chubin/cheat.sheets
synced 2024-11-17 09:25:32 +00:00
Merge pull request #100 from terminalforlife/master
Wording, Formatting, & Entries
This commit is contained in:
commit
684d77f68d
7
sheets/colrm
Normal file
7
sheets/colrm
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# colrm
|
||||||
|
# Remove columns from a file or STDIN
|
||||||
|
|
||||||
|
# Remove the first, second, third, and fourth column.
|
||||||
|
colrm 1 4 [FILE]
|
||||||
|
# Same approach as the above, but via STDIN.
|
||||||
|
printf 'Some of this is omitted.' | colrm 1 4
|
11
sheets/dd
11
sheets/dd
@ -1,5 +1,8 @@
|
|||||||
# Read from {/dev/urandom} 2*512 Bytes and put it into {/tmp/test.txt}
|
# dd
|
||||||
# Note: both iterations each read 512 Bytes (the selected block size).
|
# Convert and copy a file (AKA: Destroyer of Disks)
|
||||||
|
|
||||||
|
# Read from `/dev/urandom`, 2*512 Bytes, and put it into `/tmp/test.txt`.
|
||||||
|
# Note: each iteration reads 512 bytes (the selected block size).
|
||||||
dd if=/dev/urandom of=/tmp/test.txt count=2 bs=512
|
dd if=/dev/urandom of=/tmp/test.txt count=2 bs=512
|
||||||
|
|
||||||
# Watch the progress of dd(1).
|
# Watch the progress of dd(1).
|
||||||
@ -20,10 +23,10 @@ done
|
|||||||
# installed with the following command: apt-get install pv zenity
|
# installed with the following command: apt-get install pv zenity
|
||||||
(
|
(
|
||||||
pv -n /dev/zero | dd of=/dev/null bs=128M conv=notrunc,noerror
|
pv -n /dev/zero | dd of=/dev/null bs=128M conv=notrunc,noerror
|
||||||
) 2>&1 | zenity --title 'Running dd command (cloning), please wait...' --progress
|
) 2>&1 | zenity --title 'Cloning with dd(1) -- please wait...' --progress
|
||||||
|
|
||||||
# Watch the progress of dd(1) with the built-in `progress` functionality, -
|
# Watch the progress of dd(1) with the built-in `progress` functionality, -
|
||||||
# introduced in coreutils v8.24.
|
# introduced in CoreUtils v8.24.
|
||||||
dd if=/dev/zero of=/dev/null bs=128M status=progress
|
dd if=/dev/zero of=/dev/null bs=128M status=progress
|
||||||
|
|
||||||
# DD with "graphical" return
|
# DD with "graphical" return
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
# df
|
||||||
|
# Report file system disk space usage
|
||||||
|
|
||||||
# Print free disk space in a [h]uman-readable format.
|
# Print free disk space in a [h]uman-readable format.
|
||||||
df -h
|
df -h
|
||||||
|
|
||||||
|
@ -1,3 +1,10 @@
|
|||||||
|
# printf
|
||||||
|
# Format and print data
|
||||||
|
|
||||||
|
# This command is typically available as a built-in to many shells, such as the
|
||||||
|
# Bourne shell and the Bourne Again Shell. However, there also exists a GNU
|
||||||
|
# alternative, sometimes found over at `/usr/bin/printf`.
|
||||||
|
|
||||||
# Assign the current date (timestamp style) as a shell variable, using the Bash
|
# Assign the current date (timestamp style) as a shell variable, using the Bash
|
||||||
# builtin, and make it a suitable filename for a Gzip-compressed Tar archive.
|
# builtin, and make it a suitable filename for a Gzip-compressed Tar archive.
|
||||||
printf -v FileName 'Backup_%(%F_%X)T.tgz' -1
|
printf -v FileName 'Backup_%(%F_%X)T.tgz' -1
|
||||||
@ -10,8 +17,11 @@ printf '%s\n' "$USER"
|
|||||||
# one million, in a human-readable kind of way, by appropriately
|
# one million, in a human-readable kind of way, by appropriately
|
||||||
# comma-separating the units.
|
# comma-separating the units.
|
||||||
printf "%'d\n" {1..1000000}
|
printf "%'d\n" {1..1000000}
|
||||||
|
# Getting these results by using the comma is actually also viable in AWK, but
|
||||||
|
# you'll likely have to jump through a quotation hoop to get access to it.
|
||||||
|
|
||||||
# Zero-pad a number in order to maintain a width of 3 characters.
|
# Zero-pad a number in order to maintain a width of 3 characters. It's also
|
||||||
|
# possible to instead provide a `0` in-place of the hash (`#`).
|
||||||
printf '%#.3d\n' 12
|
printf '%#.3d\n' 12
|
||||||
# As above, but instead, space-pad the number. Prefix the `3` with a hyphen
|
# As above, but instead, space-pad the number. Prefix the `3` with a hyphen
|
||||||
# (`-`) to left-align the number, causing the padding to occur on the right.
|
# (`-`) to left-align the number, causing the padding to occur on the right.
|
||||||
|
@ -1,6 +1,15 @@
|
|||||||
# This is a shell built-in available in Bash, but not in the Bourne Shell
|
# source
|
||||||
# (`sh`). The contents of FILE (assuming shell script) will be sourced into the
|
# Execute commands from a file in the current shell
|
||||||
# current session, allowing external use of its functions, variables, etc.
|
|
||||||
|
# This is a shell built-in, available within most if not all shells. However, -
|
||||||
|
# it may only be available as `.` in some older shells, such as Bourne shell.
|
||||||
|
# Its first argument is a file, with all proceeding arguments being parameters
|
||||||
|
# to the aforementioned file.
|
||||||
|
|
||||||
|
# Run shell code residing within FILE as though you'd entered it in yourself.
|
||||||
source FILE
|
source FILE
|
||||||
# The above can be written in short-hand, for the same effect:
|
# The above can be written in short-hand, for the same effect, shell allowing.
|
||||||
. FILE
|
. FILE
|
||||||
|
|
||||||
|
# Source FILE with the given arguments to said file.
|
||||||
|
source FILE Argument_1 Argument_2 Argument_3 ...
|
||||||
|
25
sheets/ss
25
sheets/ss
@ -1,5 +1,6 @@
|
|||||||
# Utility to investigate sockets
|
# ss
|
||||||
#
|
# Another utility to investigate sockets
|
||||||
|
|
||||||
# Options:
|
# Options:
|
||||||
# -4/-6 list ipv4/ipv6 sockets
|
# -4/-6 list ipv4/ipv6 sockets
|
||||||
# -n numeric addresses instead of hostnames
|
# -n numeric addresses instead of hostnames
|
||||||
@ -7,19 +8,23 @@
|
|||||||
# -u/-t/-x list udp/tcp/unix sockets
|
# -u/-t/-x list udp/tcp/unix sockets
|
||||||
# -p Show process(es) that using socket
|
# -p Show process(es) that using socket
|
||||||
|
|
||||||
# show all listening tcp sockets including the corresponding process
|
# Show all listening TCP ports, including the corresponding process.
|
||||||
ss -tlp
|
ss -tlp
|
||||||
|
|
||||||
# show all sockets connecting to 192.168.2.1 on port 80
|
# Show a summary of all ports connecting to 192.168.2.1 via port 80.
|
||||||
ss -t dst 192.168.2.1:80
|
ss -t dst 192.168.2.1:80
|
||||||
|
|
||||||
# show all ssh related connection
|
# Show all SSH-related connection.
|
||||||
# documentation on the filter syntax: sudo apt-get install iproute2-doc
|
#
|
||||||
|
# Documentation on the filter syntax can be installed via the following command
|
||||||
|
# if on a Debian- or Ubuntu-based distribution of Linux:
|
||||||
|
#
|
||||||
|
# sudo apt-get install iproute2-doc
|
||||||
|
#
|
||||||
ss -t state established '( dport = :ssh or sport = :ssh )'
|
ss -t state established '( dport = :ssh or sport = :ssh )'
|
||||||
|
|
||||||
# Display timer information
|
# Display timer information.
|
||||||
ss -tn -o
|
ss -tno
|
||||||
|
|
||||||
# Filtering connections by tcp state
|
# Filter connections by TCP state.
|
||||||
ss -t4 state established
|
ss -t4 state established
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# ssh
|
# ssh
|
||||||
# access a remote host via SSH
|
# OpenSSH SSH client (remote login program)
|
||||||
|
|
||||||
# SSH in via PEM file, which normally needs 0600 permissions.
|
# SSH in via PEM file, which normally needs 0600 permissions.
|
||||||
ssh -i /path/to/file.pem user@example.com
|
ssh -i /path/to/file.pem user@example.com
|
||||||
@ -50,8 +50,10 @@ ssh -o PubkeyAuthentication=no username@hostname.com
|
|||||||
# Install SSHFS from: https://github.com/libfuse/sshfs
|
# Install SSHFS from: https://github.com/libfuse/sshfs
|
||||||
sshfs name@server:/path/to/folder /path/to/mount/point
|
sshfs name@server:/path/to/folder /path/to/mount/point
|
||||||
|
|
||||||
# EMACS can read files through SSH.
|
# EMACS can read files through SSH. Below, is a link to related documentation.
|
||||||
# Doc: http://www.gnu.org/software/emacs/manual/html_node/emacs/Remote-Files.html
|
#
|
||||||
|
# http://www.gnu.org/software/emacs/manual/html_node/emacs/Remote-Files.html
|
||||||
|
#
|
||||||
emacs /ssh:name@server:/path/to/file
|
emacs /ssh:name@server:/path/to/file
|
||||||
|
|
||||||
# Get help for SSH escape sequences. Useful for terminating unresponsive
|
# Get help for SSH escape sequences. Useful for terminating unresponsive
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
# stat
|
||||||
|
# Display file or file system status
|
||||||
|
|
||||||
# display numerical values for file permissions
|
# display numerical values for file permissions
|
||||||
stat -c '%a %n' *
|
stat -c '%a %n' *
|
||||||
|
|
||||||
|
57
sheets/sudo
57
sheets/sudo
@ -1,33 +1,64 @@
|
|||||||
# sudo
|
# sudo
|
||||||
# Execute a command as another user.
|
# Execute a command as another user
|
||||||
|
|
||||||
# List of an unreadable directory:
|
# List contents of directory to which the user otherwise wouldn't have access.
|
||||||
sudo ls /usr/local/scrt
|
sudo ls /usr/local/scrt
|
||||||
|
|
||||||
# To edit a file as user www:
|
# Edit the given file as the `www` user. This is a great example of why sudo(8)
|
||||||
|
# is or was often, and more accurately, referred to as "substitute user do".
|
||||||
sudo -u www vi /var/www/index.html
|
sudo -u www vi /var/www/index.html
|
||||||
|
|
||||||
# To shutdown the machine:
|
# Shut down (halt) the machine when 10 minutes have passed. The quoted text is
|
||||||
|
# messaged to the terminal of all applicable users, known as a 'wall message'.
|
||||||
sudo shutdown -h +10 "Cya soon!"
|
sudo shutdown -h +10 "Cya soon!"
|
||||||
|
# Note, that the above is the old method. On machines with SystemD, the below
|
||||||
|
# command can instead be used.
|
||||||
|
sudo systemctl reboot
|
||||||
|
|
||||||
# To repeat the last command as sudo:
|
# In Bash, `!!` (bang, bang) is an event designator, as described in bash(1), -
|
||||||
|
# and is used to refer to the previous command, synonymous for `!-1`.
|
||||||
|
#
|
||||||
|
# In this case, the user is able to prefix the entirety of the previous command
|
||||||
|
# with `sudo`, being most useful when forgetting that `root` access is needed.
|
||||||
sudo !!
|
sudo !!
|
||||||
|
|
||||||
# Save a file you edited in vim
|
# For use in the vim(1) modal text editor, this command allows the user to save
|
||||||
|
# the currently opened file as the `root` user, despite having not previously
|
||||||
|
# opened it with such privileges.
|
||||||
:w !sudo tee > /dev/null %
|
:w !sudo tee > /dev/null %
|
||||||
|
|
||||||
# Make sudo forget password instantly
|
# Reset the current user's sudo(8) timestamp, resulting in the user having to
|
||||||
|
# once again enter his or her password when next using sudo(8). Use of this
|
||||||
|
# flag does not actually require `root` privileges.
|
||||||
sudo -K
|
sudo -K
|
||||||
|
|
||||||
# List your sudo rights
|
# List the current user's sudo(8) privileges.
|
||||||
sudo -l
|
sudo -l
|
||||||
|
|
||||||
# Add a line to a file using sudo
|
# Add a line to a file using sudo(8). This is especially useful when making
|
||||||
|
# changes to a kernel parameter file, like the `/proc/sys/vm/swappiness` file.
|
||||||
echo "foo bar" | sudo tee -a /path/to/some/file
|
echo "foo bar" | sudo tee -a /path/to/some/file
|
||||||
|
|
||||||
# run root shell
|
# Begin a shell session as the system's `root` user.
|
||||||
sudo -i
|
sudo -i
|
||||||
|
|
||||||
# to disable password for sudo for user superuser add
|
# To disable password for sudo(8) for the `superuser` user, add the below line
|
||||||
# superuser ALL=(ALL) NOPASSWD:ALL
|
# to the `/etc/sudoers` file, preferably by using the visudo(8) executable.
|
||||||
# in /etc/sudoers
|
#
|
||||||
|
# superuser ALL=(ALL) NOPASSWD: ALL
|
||||||
|
#
|
||||||
|
# This would result in the aforementioned user not needing to enter in a
|
||||||
|
# password when using `sudo`, otherwise he or she would be required to do so.
|
||||||
|
#
|
||||||
|
# Likewise, the below can be entered if this is wished for an entire group, -
|
||||||
|
# which in this case would be the `special` group.
|
||||||
|
#
|
||||||
|
# %special ALL=(ALL) NOPASSWD: ALL
|
||||||
|
#
|
||||||
|
# Do note that neither of these configurations are at all recommended and can
|
||||||
|
# pose a massive security risk.
|
||||||
|
|
||||||
|
# Run `CMD` as the `root` user, but maintain the current user's environment. In
|
||||||
|
# systems like Ubuntu, this is assumed, but systems like Debian would require
|
||||||
|
# that the user make use of this flag when wanting to keep their environment.
|
||||||
|
sudo -E [CMD]
|
||||||
|
10
sheets/wget
10
sheets/wget
@ -1,6 +1,12 @@
|
|||||||
# Quietly download a file, continuing where it left of, if the connection fails.
|
# wget
|
||||||
# Note that the file will be downloaded to the current working directory.
|
# The non-interactive network downloader
|
||||||
|
|
||||||
|
# Quietly download a file, continuing where it left of, if the connection
|
||||||
|
# fails. The file will be downloaded to the current working directory.
|
||||||
wget -qc [URL]
|
wget -qc [URL]
|
||||||
|
|
||||||
# Specify a location to download the given file.
|
# Specify a location to download the given file.
|
||||||
wget -qcO [PATH] [URL]
|
wget -qcO [PATH] [URL]
|
||||||
|
|
||||||
|
# Download URL using the user agent string provided to the `-U` flag.
|
||||||
|
wget -U 'Mozilla/5.0' [URL]
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# xset
|
# xset
|
||||||
# user preference utility for X
|
# User preference utility for X
|
||||||
|
|
||||||
# Disable screen saver blanking
|
# Disable screen saver blanking
|
||||||
xset s off
|
xset s off
|
||||||
|
Loading…
Reference in New Issue
Block a user