nl stringlengths 13 387 | bash stringlengths 1 532 |
|---|---|
returns the first 100 bytes in the file | head -c 100 file |
Return the list of files named "filename" that are 50 megabytes or larger | find / -size +50M -iname "filename" |
Returns the single most recent file in a directory | ls -t | head -n1 |
Reverse the order of lines in "myfile.txt" using BSD "tail" command | tail -r myfile.txt |
Reversibly sorts content of the '${TMP}/${SCRIPT_NAME}.kb' file, comparing human readable numbers in file strings. | cat ${TMP}/${SCRIPT_NAME}.kb|sort -rh; |
Reversibly sorts content of the '${TMP}/${SCRIPT_NAME}.name' file | cat ${TMP}/${SCRIPT_NAME}.name|sort -r; |
Reversibly sorts content of the '${TMP}/${SCRIPT_NAME}.pid' file, comparing human readable numbers in file strings. | cat ${TMP}/${SCRIPT_NAME}.pid|sort -rh; |
Reverse the space separated words in "35 53 102 342" | echo 35 53 102 342|tr ' ' '\n'|tac|tr '\n' ' ' |
Reverse the text in $input by taking each 4 characters as each units and save the result in variable 'output' | output=$(echo $input | fold -w4 | tac | tr -d \\n) |
Revert $string value and print first 20 space-separated fields | echo $string | rev | cut -d ' ' -f -20 |
Run "./configure" with a new environment variable CC set to the full path of the command 'cc' | CC=$(which cc) ./configure |
Run "./configure" with a new environment variable CC set to the full path of the command 'gcc' | CC=$(which gcc) ./configure |
Run "command" on server "host" as user "user" | echo "command" | ssh user@host |
Run 'chmod 0644' on all files in the current directory tree | find . -type f -exec chmod 0644 {} \; |
Run 'chmod 0755' on all directories in the current directory tree | find . -type d -exec chmod 0755 {} \; |
Runs `file' on every file in or below the current directory. | find . -type f -exec file '{}' \; |
Run 'make -e' with an environment variable 'HOSTNAME' set to the system hostname | HOSTNAME=$(hostname) make -e |
Run 'somecommand' in an environment without the FOO variable. | env -u FOO somecommand |
Run 'top' in batch mode (don't accept user input) with delay of 1 second between updates, and duplicate the standard output to file 'output.log' in current directory. | top -b -d 1 | grep myprocess.exe | tee output.log |
Run .makeall.sh in an empty environment. | env -i ./makeall.sh |
Run commands "df -k;uname -a" on server "192.168.79.134" | echo "df -k;uname -a" | ssh 192.168.79.134 |
Run command 'su whoami' on host 'remotehost' | echo "su whoami" |ssh remotehost |
Run command specified by $line, replace space (' ') with newline and save the output to variable 'arr' | arr=$( $line | tr " " "\n") |
Run the file command on every regular file under current directory | find . -type f -exec file '{}' \; |
Run the find command with all shell positional arguments | `which find` "$@" -print0; |
run ksh shell as user apache | su apache -s /bin/ksh |
run ls command on *.pl files | find . -name "*.pl" -exec ls -ld {} \; |
run ls command on files found | find . -name "*.pl" -exec ls -ld {} \; |
Run perl -V (displays informations about perl's setup) in an empty environment. | env -i perl -V |
Run rsync with options specified by variable OPTS, copying directory(ies) specified by variable FIND, and to destination specified by variable BACKUPDIR. | rsync $OPTS $FIND $BACKUPDIR |
same as above example with -exec , in this example with -OK it should ask for confirmation before executing the rm command . that is called user intractive command | find . -name core -ok rm {} \; |
Save "something" into variable "param" in ksh | echo something | read param |
Save $line line in history | history -s "$line" |
Save 'echo whatever you "want your" command to be' in history | history -s 'echo whatever you "want your" command to be' |
Save 'foo' into variable 'bar' in ksh | echo foo | read bar |
Save a comma separated list of all $MY_DIRECTORY/*/ directories to variable 'FOLDER' | FOLDERS=`ls -dm $MY_DIRECTORY/*/ | tr -d ' '` |
Save a comma separated list of all directories under current directory tree to variable 'FOLDER' | FOLDERS=$(find . -type d -print0 | tr '\0' ',') |
Save a line of 100 random characters either "." or " " in variable "foo" | foo=$(cat /dev/urandom | tr -dc '. ' | fold -w 100 | head -1) |
Save a list of all 755 permission files/directories under $dir directory tree to the variable 'files' | files="$(find $dir -perm 755)" |
Save a list of all the files/directories under current directory tree to a file named 'foo' | find . -fprint foo |
Save a unique list of the currently logged in usernames to variable "line" | line=$(who | cut -d' ' -f1 | sort -u) |
Save absolute path of "$path" that must exist along with all parents to variable "abspath" | abspath=$(readlink -e $path) |
Save absolute path of "$path" that may not exist to variable "abspath" | abspath=$(readlink -m $path) |
Save the absolute path of "$path" to variable "full_path" | full_path=`readlink -fn -- $path` |
Save the absolute path of "$path" to variable "fullpath" | fullpath=`readlink -f "$path"` |
Save absolute path of "/home/nohsib/dvc/../bop" in variable "absolute_path" | absolute_path=$(readlink -m /home/nohsib/dvc/../bop) |
Save the absolute path of the current script to variable "SELF" | SELF=$(readlink /proc/$$/fd/255) |
Save the absolute path of the current script to variable "SELF" | SELF=`readlink /proc/$$/fd/255` |
Save the absolute path of the current script to variable "SELF" | actual_path=$(readlink -f "${BASH_SOURCE[0]}") |
Save the absolute path of the current script to variable "SELF" | script="`readlink -f "${BASH_SOURCE[0]}"`" |
Save actual working directory in variable "target_PWD" | target_PWD=$(readlink -f .) |
Save all directories under the current directory as a comma separated list in variable "FOLDERS" | FOLDERS=$(find $PWD -type d | paste -d, -s) |
Save all directories under the current directory as a comma separated list in variable "FOLDERS" | FOLDERS=$(find . -type d | paste -d, -s) |
Save all entries that are wrapped around with opening and closing square brackets in file 'FILENAME' to variable 'var' | var=`egrep -o '\[.*\]' FILENAME | tr -d ][` |
Saves bytes count of the value of '$each' variable. | a=$(echo $each | wc -c) |
Saves byte size of $myvar variable value in the 'var2' variable. | var2=$(echo $myvar | wc -c) |
Save the canonical filename of "$BASH_SOURCE" in variable "me" | me=$(readlink --canonicalize --no-newline $BASH_SOURCE) |
Save the canonical path of "$dir/$file" in variable "path" | path=`readlink --canonicalize "$dir/$file"` |
Save count of lines from file $file matching with pattern $filter and not matching with pattern $nfilter in variable 'totalLineCnt' | totalLineCnt=$(cat "$file" | grep "$filter" | grep -v "$nfilter" | wc -l | grep -o '^[0-9]\+'); |
Save the current date to 'DATE' variable | DATE=$(echo `date`) |
Save the current time formatted according to the format string "%Y-%m-%d %H:%M:%S" to the variable 'CDATE' | CDATE=$(date "+%Y-%m-%d %H:%M:%S") |
Save the current user name in variable "myvariable" | myvariable=$(whoami) |
Save the current working directory and the directory name of the current script to variable "DIR" | DIR=`pwd`/`dirname $0` |
Save the current working directory to variable "CURRENT" | CURRENT=`pwd` |
Save the current working directory with resolved symbolic links to variable "real1" | real1=$(pwd -P) |
Save the date 222 days before today to the variable 'date_222days_before_TodayDay' | date_222days_before_TodayDay=$(date --date="222 days ago" +"%d") |
Save the day of the year from the time string "20131220" to variable 'DATECOMING' | DATECOMING=$(echo `date -d "20131220" +%j`) |
Save the directory name of the canonical path to the current script in variable "MY_DIR" | MY_DIR=$(dirname $(readlink -f $0)) |
Save the directory of the full path to the current script in variable "dir" | dir=$(dirname $(readlink -m $BASH_SOURCE)) |
Save the directory of the full path to the current script in variable "dir" | dir=$(dirname $(readlink /proc/$$/fd/255)) |
Saves file sctipt.sh size in 'size' variable. | size=`cat script.sh | wc -c` |
Save the first "." separated field of the system host name to variable "HOSTZ" | HOSTZ=$( hostname | cut -d. -f1 ) |
Save the first two letters of the system host name to variable "DC" | DC=`hostname | cut -b1,2` |
Save the first three octets of the host name's IP address to variable "subnet" | subnet=$(hostname -i | cut -d. -f1,2,3) |
Save first IP address of domain 'google.com' in 'address' variable | address=$(dig +short google.com | grep -E '^[0-9.]+$' | head -n 1) |
Save the first line of "$j" into variable "k" in ksh | echo $j | read k |
Save first one of space separated parts of each line in $LOCKFILE file to the 'CURRENT_PID_FROM_LOCKFILE' variable | CURRENT_PID_FROM_LOCKFILE=`cat $LOCKFILE | cut -f 1 -d " "` |
Save the first word of the first difference in ".dir_list_2" compared to ".dir_list_1" into variable "extract_dir" | extract_dir=$(diff .dir_list_1 .dir_list_2 | grep '>' | head -1 | cut -d' ' -f2) |
Saves folder path where target of symbolic link $file file is located in 'base' variable. | base=$(dirname $(readlink $file)) |
Save the FQDN host name of the system in variable "fhost" | fhost=`hostname -f` |
Save the FQDN host name of the system in variable "hnd" | hnd=$(hostname -f) |
Save full path of command "mktemp" to variable "MKTEMP" | MKTEMP=`which mktemp` |
Save the full path of command "oracle" to variable "path" | path=`which oracle` |
Save full path of command "rm" to variable "RM" | RM=`which rm` |
Save full path of command "tr" to variable "TR" | TR=`which tr` |
Save the full path of command "~/f" to variable "foo" | foo=`which ~/f` |
Save host name in variable "thisHOSTNAME" | thisHOSTNAME=`hostname` |
Save in QUEUE_PIDS variable only pid numbers that stored in $NEW_PIDS variable | QUEUE_PIDS=$(comm -23 <(echo "$NEW_PIDS" | sort -u) <(echo "$LIMITED_PIDS" | sort -u) | grep -v '^$') |
Saves index number of file 'script.sh' in the 'inode' variable. | inode=`ls -i ./script.sh | cut -d" " -f1` |
Saves invoked command 'check_script_call=$(history |tail -1|grep myscript.sh )' in variable 'check_script_call', preceeding by its number in history. | check_script_call=$(history |tail -1|grep myscript.sh ) |
Save the latest modification time (in format "%T@ %t" of any file under "./$dir" to variable "timestamp" | timestamp=$(find ./$dir -type f -printf "%T@ %t\\n" | sort -nr -k 1,2 | head -n 1) |
Saves listing of a current folder in 'OUTPUT' variable. | OUTPUT="$(ls -1)" |
Save the list of all .py files under and below the current directory that contain "something" in their pathnames to output.txt | find . -name '*.py' | tee output.txt | xargs grep 'something' |
Save list of groups which user $line belongs to and not matching pattern "_unknown|sciences|everyone|netaccounts" in 'results' variable | results=$(groups "$line" | tr ' ' '\n' | egrep -v "_unknown|sciences|everyone|netaccounts") |
Saves list of logged in users in system together with 'USER' header in the 'a' variable. | a=`w|cut -d' ' -f1`; |
Saves location of file $1 in 'dir' variable. | dir=$(dirname -- "$1") |
Saves location of file $1 in 'dir_context' variable. | dir_context=$(dirname -- "$1") |
Save the logical current working directory to variable "basedir" | basedir=$(pwd -L) |
Save long listing of all files listed in file 'filenames.txt' to 'listing' variable | listing=$(ls -l $(cat filenames.txt)) |
Save long listing of all running processes in the 'log' file, and save number of process strings that contain 'cntps' in the 'cnt' variable. | cnt=`ps -ef| tee log | grep "cntps"|grep -v "grep" | wc -l` |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.