Bash

Bash: Changing Owner of a folder

 

If you want to change the user owning this file or directory (folder), you will have to use the command chown. For instance, if you run

sudo chown username: myfolder

the user owning myfolder will be username. Then you can execute

sudo chmod u+w myfolder

to add the write permission to the username user.

But if you want to add this user to the group associated with "myfolder", you can run

sudo usermod -a -G groupname username

and then execute

sudo chmod g+w myfolder

to add the write permission to the group.

Tags

Bash: Pipe Options

which php | ls -la

cp `which php` destination/directory/path

which php | xargs ls -1 -la

Tags

Bash: sed for String Substitution

using sed to replace strings in text files without a text editor

sed 's/sedtest/seedtest/' sedtest.txt > seedtest.txt && mv seedtest.txt sedtest.txt
  • s = substitute
  • find = sedtest
  • replace with = seedtest
  • sed won't alter the source file, but a destination file can be specified
  • if one wants to effectively update the SOURCE file, simply append the command with 'mv'

see also: https://www.computerhope.com/unix/used.htm

Tags

Sed: Search/Replace to edit files inside Docker containers

root@c460eb9bda94:/usr/local/apache2# sed 's/LogLevel warn/LogLevel debug/' conf/httpd.conf > conf/httpd.conf.changed && mv conf/httpd.conf.changed conf/httpd.conf
  1. Search/Replace in  conf/httpd.conf
  2. Pipe to conf/httpd.conf.changed
  3. move conf/httpd.conf.changed to conf/httpd.conf
Tags

Bash: Symlinks

 

ln -s TARGET LINK_NAME

 

To create a new symlink (will fail if symlink exists already):

ln -s /path/to/file /path/to/symlink

To create or update a symlink:

ln -sf /path/to/file /path/to/symlink
Tags

Bash: Menu Seed Script

 

Simple seed script for creating a menu system on linux( from stackoverflow )

#!/bin/bash
# Menu Runner

PS3='Please enter choice: '
opts=("ls" "pwd" "opt3" "Quit")
select opt in "${opts[@]}"
do
    case $opt in
        "ls")
            echo "u chose ls"
            ;;
        "pwd")
            echo "u chose pwd"
            ;;
        "opt3")
            echo "u typed '$REPLY' which calls '$opt'"
            ;;
        "Quit")
            break
            ;;
            *) echo "invalid option $REPLY";;
    esac
done

 

Tags
Subscribe to Bash