nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Split "${fspec}" into 6 files with about equal number of lines each and use prefix "xyzzy."
split --number=l/6 ${fspec} xyzzy.
List all files/directories under current directory ensuring white space safety
find -print0 | xargs --null
display all the directories in the folder /path/to/dest except tmp directory
find /path/to/dest -type d \ -print
Dry run making directories in "/TARGET_FOLDER_ROOT/" for each ".mov" file in the current directory tree
find . -type f -iname \*.mov -printf '%h\n' | sort | uniq | xargs -n 1 -d '\n' -I '{}' echo mkdir -vp "/TARGET_FOLDER_ROOT/{}"
Find all files/directories under 'my key phrase' directory and redirect the output to mylist.txt
find 'my key phrase' > mylist.txt
Find files in the /var/log folder which were modified an hour or more ago
find /var/log/ -mmin +60
Force remove all files and folders in the physical current working directory
rm -rf "$"/*
search for all the files in the folder /home/user1 which end with ".bin"
find /home/user1 -name "*.bin"
Check if *RBENV* variable is defined in tmux session 'sessname' environment.
tmux show-environment -t sessname | grep RBENV
Find files in the /home/user directory tree changed exactly 10 minutes ago
find /home/user/ -cmin 10 -print
Rename "www_new" to "www" even if "www" directory exists
mv -T www_new www
Change all variables containing "gcc.4.2" to containing "gcc64" in the current shell's environment.
source <
Find all .txt files list & List the first lines of text files
find $HOME/. -name *.txt -exec head -n 1 -v {} \; > report.txt
search for the file centos in /usr folder
find /usr -iname centos
Delete all directories under '.cache/chromium/Default/Cache/' directory tree that are bigger than 100MB and are at least 1 level deep
find .cache/chromium/Default/Cache/ -mindepth 1 -type d -size +100M -exec rm -rf {} \;
Compress "mysqldbbackup.sql" with gzip and email it with subject "MySQL DB" to "[email protected]"
gzip -c mysqldbbackup.sql | uuencode mysqldbbackup.sql.gz | mail -s "MySQL DB" [email protected]
Creates temporary directory in '/tmp/' folder and saves path to it in 'my_tmp_dir' variable.
my_tmp_dir=$
Find regular non-hidden files containing `some text' in their names with hidden directories optimization
find . -type d -path '*/\.*' -prune -o -not -name '.*' -type f -name '*some text*' -print
Find all files named "something" in the current folder and below and run them through the ls -l command, one by one.
find . -name something -exec ls -l {} \;
Search the current directory recursively for regular files last accessed more than 2 days ago
find . type -f -atime +2
change the permissions of all the regular/normal files to 644 in the folder /home/nobody/public_html
find /home/nobody/public_html -type f -exec chmod 644 {} \;
Replace all occurrences of edx (case insensitive) with gurukul in all *.css (case insensitive) files under ./cms/djangoapps/contentstore/views directory
find ./cms/djangoapps/contentstore/views -iname *.css | xargs sed -i s/[Ee][Dd][Xx]/gurukul/g
search for a pattern in all the python files in the current folder. and save the output to a txt file
find . -name "*.py" -type f -exec sh -c 'grep "something" <"$0" >"$0.txt"' {} \;
set a crontab to create or update the timestamp of "washere2" in the current directory every 30 minutes.
echo "30 * * * * touch $/washere2" | crontab
Search the entire file hierarchy for all regular files owned by olduser and change their ownership to newuser.
find / -user olduser -type f -exec chown newuser {} \
List non-hidden regular files in the current directory tree that were last modified more than 500 days ago
find . -type f -not -name '.*' -mtime +500 -exec ls {} \;
Find file `hosts'
find /etc -name hosts
List all files matching regular expression '*foo*' in a human-readable form
find . -name '*foo*' -exec ls -lah {} \;
change the permission of all the rpm files in the entire file system to 755
find / -name *.rpm -exec chmod 755 '{}' \;
Print the list of all regular files from the current directory tree that contain "confirm", case insensitive
find . -type f -exec grep -il confirm {} \;
Print amount of space available on the file system containing path to the current working directory in megabytes.
df . -B MB | tail -1 | awk {'print $4'} | grep .[0-9]*
Find all files and directories containing "disc" in their names
find . -name *disc*
search for the pattern in all the regular/normal files in the entire file system
find / -type f -print0 | xargs -0 grep -i pattern
Add a cron job to existing list, without removing existing ones, ro tun "scripty.sh" at 2:01 am, 3rd day of april (4th month), if that day happens to be a friday (5th day of the week starting with sunday=0).
cat <(crontab -l) <(echo "1 2 3 4 5 scripty.sh") | crontab -
Change directory to the alphabetically last path under the current directory
cd "$(find . -print0 | sort -z | tr '\0' '\n' | tail -1)"
Set variable "MAVEN_DEBUG_OPTS" to "-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000" on Windows machines
set MAVEN_DEBUG_OPTS=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
display all the files in current folder
find .
find all the regular files in the current directory which do not have a read permission
find -type f ! -perm -444
Removes strings with pattern from file 'filename'.
grep -v "pattern" filename > filename2; mv filename2 filename
Delete all files named 'Waldo' under ~/Books directory tree where '~' expands to user's home directory
find ~/Books -type f -name Waldo -exec rm {} \;
find all "tar.gz" files in a folder and sort them according to the name and display the first 2 files
(find $DIR/tmp/daily/ -name *.tar.gz | sort -n | head -2
Print the last mounted drive
mount | tail -1 | sed 's/ on .* ]*)$//'
Replace "_" with newlines in "Testing\r\nTested_Hello_World" and display the named characters
echo -e "Testing\r\nTested_Hello_World" | awk -v RS="_" '{ print $0; }' | od -a
display a long listing of all the files in the current folder which have been modified in the last 24 hours
find . -mtime -1 -ls
Delete all files in the /TBD directory that were modified more than 1 day ago
find /TBD/* -mtime +1 -exec rm -rf {} \;
Unset IFS and read standard input into variable "file" until a null character is found without allowing backslashes to escape characters
IFS= read -d $'\0' -r file
removes last N lines from file.txt
head --lines=-N file.txt
Shows MAC address of network interface eth0.
ifconfig eth0 | grep HWaddr |cut -dH -f2|cut -d\ -f2
count all the regular files that are present in a directory
find . -type f | wc -l
This will remove all files (type f) modified longer than 14 days ago under /root/Maildir/ recursively from there and deeper (mindepth 1
find /root/Maildir/ -mindepth 1 -type f -mtime +14 | xargs rm
Find the passwd file in the current directory and one level down
find -maxdepth 2 -name passwd
Print all directories under $root appending a : at the end of each path without descending into directories matching the pattern .[a-z]*
find "$root" -name ".[a-z]*" -prune -o -type d -printf '%p:'
Find all files/directories that belong to the group 'audio' under '/dev' directory tree
find /dev -group audio
Find in the current direcoty whose suffix is .tmp , find will not serach recursively limit of find is 2 subdirectory .
find . -maxdepth 2 -name '*.tmp'
Find files with 002 permission under /tmp and print them with the string 'Found world write permissions:' printed as the first line of output or print 'No world writable found' if no such files were found
find /tmp -type f -perm -002 | awk -- '1{print "Found world write permissions:";print};END{ifprint "No world writable found."}'
display all the files in the current folder which start with either "fileA_" or "fileB_"
find . -name 'fileA_*' -o -name 'fileB_*'
Pass "y" to all the prompts for the command "execute_command"
yes | execute_command
List all environment variables whose name or value contains current user's login name.
env | sed -n /"$USERNAME"/p
Find all xx* files/directories excluding 'xxx' files/directories under your home directory
find ~ -name 'xx*' -and -not -name 'xxx'
As root, edit the cron job list of user "apache" using the editor specified by EDITOR environment variable, or default /usr/bin/editor if this variable is not set.
sudo crontab -e -u apache
delete all files that have the extension "bam" in current directory
find . -name "*.bam" | xargs rm
Find all $tofind* files/directories under $parentdir
find $parentdir -name $tofind*
Limits the number of results from grep to 2 lines
grep -o '1.' yourfile | head -n2
change the ownership of all directories in the current folder
find . -type d -exec chown username {} \;
search for files cart4 or cart5 or cart6 in the folder junk which is in home folder and delete it.
find ~/junk -name 'cart[4-6]' -exec rm {} \;
Print git branch currently checked out in a working directory.
git branch --no-color | grep -E '^\*' | cut -d ' ' -f 2
split $SOURCE_FILE" into pieces per 100 lines
split -l 100 "$SOURCE_FILE"
Search in current directory downwards all files whose size is greater than 10 bytes .
find . -size +10c -print
Recursively and forcibly removes $TMP folder with all content.
rm -fR "${TMP}/";
Find all files under the current directory whose pathnames do not end with "Video", ignoring the case
find . -maxdepth 1 -not -iwholename '*Video'
Output line number and lines 200000000 through 200000005 from the infinite input of "y"
yes | sed -n '200000000,${=;p};200000005q'
delete all instances of the file "bad" if its size is 0 bytes
find . -name bad -empty -delete
Find files and directories whose owner is daniel
find . -user daniel
Archive "/home/abc/*" to "/mnt/windowsabc" with human readable output
rsync -avh /home/abc/* /mnt/windowsabc
List all files under current directory matching the regex '.*$'
find -E . -type f -regex '.*$' -exec ls {} \;
List the files in the /etc directory tree containing text "old1.old2.co.com"
find /etc -type f -print | xargs grep -il old1\.old2\.co\.com
find all text files in current folder and trim the extra spaces in all lines in these files and save it to the original file
find . -type f -name "*.txt" -exec sh -c 'for i;do sed 's/[[:space:]]*$//' "$i">/tmp/.$$ && mv /tmp/.$$ "$i";done' arg0 {} +
Output the variable "filename" without the last dot-separated section.
echo ${filename%.*}
Remove empty folder, and skip error message if one is not empty.
rmdir --ignore-fail-on-non-empty newBaseDir/Data/NewDataCopy
Find all files, folders, symlinks, etc matching pattern "*.php" in the current directory recursively
find . -name \*.php
Read a line from standard input into the variable "yn" using the first argument as the prompt
read -p "$1 " yn
bind word "pwd\n" to key code "\e[24~"
bind '"\e[24~":"pwd\n"'
Convert the contents of 'var1' variable to lowercase
var1=`echo $var1 | tr '[A-Z]' '[a-z]'`
find all the files in the file system which have not been modified in the last 100*24 hours
find / -mtime +100 -print
Search for "vid=123" in all compressed files found under "/my_home" matching "*log.20140226*"
zcat `find /my_home -name '*log.20140226*'`|grep 'vid=123'
Remove all .txt files in and below the current directory
find . -name "*.txt" | xargs rm
Find all files in the current directory and its sub-directories that have been modified sometime in the last 24 hours.
find . -mtime -1 -prin
Creates file with random 10-byte size content.
shred -s 10 - > my-file
Sets 'extglob' shell variable.
shopt -s extglob
Look for any instance of "ds1337" in the modules.alias file matching current kernel release
grep ds1337 /lib/modules/`uname -r`/modules.alias
set alias "your_env" for command 'source ~/scripts/your_env.sh'
alias your_env='source ~/scripts/your_env.sh'
change the extension of all the ".lst" files in the current folder to "a.lst"
find -name ‘*.lst’ -exec rename .lst a.lst {} \;
Search for 'It took' in all $srch1* (case insensitive) files under current directory and run the sed script 'N;s/(.*)\n(.*)/\2 \1/' on the output
find . -iname "$srch1*" -exec grep "It took" {} \; -print |sed -r 'N;s/(.*)\n(.*)/\2 \1/'
Locate OGG files under the home directory smaller than 100 megabytes
find $HOME -iname '*.ogg' -type f -size -100M
find all the text files in the current directory which have been modified in the last 4 days and not today and copy them to another folder
find . -name "*.txt" -type f -daystart -mtime -4 -mtime +0|xargs -i cp {} /home/ozuma/tmp
copy a files from one folder to all the folder in the /raid which have an extension local_sd_customize.
find /raid -type d -name ".local_sd_customize" -ok cp /raid/04d/MCAD-apps/I_Custom/SD_custom/site_sd_customize/user_filer_project_dirs {} \;
Print the current default full path of the "java" executable
echo "The current default java is $(readlink --canonicalize `which java`)"
Recursively copy all files and directories in "demo" excluding ".git" to "demo_bkp"
find demo -depth -name .git -prune -o -print0 | cpio -0pdv --quiet demo_bkp
find all the files in the current folder and create a backup of it in floppy
find . -depth -print | cpio -ov > /dev/fd0
find all the html files that are acces in the last 24 hours in the current folder
find . -mtime 1 -name "*.html" -print