User Tools

Site Tools


linux:bash

This is an old revision of the document!


BASH

Toggle Bash History

Turn Off

set +o history

Turn on

set -o history

Convert to Uppercase

echo ${VARNAME^^}

Convert to Lowercase

echo ${VARNAME,,}

Copy and Preserve Permissions

Add -p to the cp command to preserve ownership and permissions

Copy Permissions

To replicate the permissions of one file onto a second file, use the following

chown --reference=file1 file2
chmod --reference=file1 file2
restorecon --reference=file1 file2

cat Multiple Lines

This will append the text to outputfile.txt. Replace

<<

with

<

to overwrite the entire file.

cat << EOF >> outputfile.txt
Line1 - The first line
Line2 - The middle line
Line3 - The last line
EOF

Polish Start/Stop Scripts

On CentOS, you can use echo_success and echo_failure to add [ OK ] and [ FAILED] to the screen

#!/bin/bash
# This next line must be included
. /etc/init.d/functions

echo -n "Starting My Service:"
# Success or Failure will depend on whether the function
# start_my_service_function returns a 0 or a non0 number
start_my_service_function && echo_success || echo_failure
echo
linux/bash.1590394819.txt.gz · Last modified: (external edit)