nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Remove all regular files from the current directory tree that were modified between August 10th and August 17th
find . -type f -newermt "Aug 10" ! -newermt "Aug 17" -exec rm {} \;
Print the current directory tree with the date of last modification for each file or directory
tree -D
Read a single character from standard input into variable "doit" with prompt "Do that? [y,n]"
read -n1 -p "Do that? [y,n]" doit
Show who is logged on
who
Rename uppercase file or folder name $1 to lower case name
mv $1 `echo $1 | tr '[:upper:]' '[:lower:]'`
display all files in current folder which have not been modified in the last 60 minutes
find -mmin +60
Save the canonical filename of the script in variable "me"
me=$(readlink --canonicalize --no-newline $0)
Make directories "$@" and replace "mkdir: created directory " with "$USER created folder " in the output
mkdir "$@" |sed -e"s/mkdir: created directory /$USER created folder /"
Gets IP address of 'eth0' network interface.
ifconfig eth0 | awk '/inet addr/{sub("addr:",""); print $2}'
Updates 'openssl' packages without using of 'epel' repository.
sudo yum --disablerepo epel update openssl
Request MX record of 'example.com' domain, and filter out all comment strings
dig mx example.com | grep -v '^;' | grep example.com
Removes symlinks for formula bash-completion from the Homebrew prefix.
brew unlink bash-completion
create a symbolic link named "/usr/bin/my-editor" to file "/usr/share/my-ditor/my-editor-executable"
ln -s /usr/share/my-ditor/my-editor-executable /usr/bin/my-editor
Get domain name from dig reverse lookup.
$dig -x 8.8.8.8 | grep PTR | grep -o google.*
list files under the current directory that match the filename '...', suppressing all error messages
find . -name '...' 2>/dev/null
ERROR - will overwrite the executable if it's not a symlink.
sudo ln -sf /usr/local/ssl/bin/openssl `which openssl`
Find all regular files in the current directory tree last modified between 1 and 3 days ago and list them using find's -ls option
find ./ -daystart -mtime -3 -type f ! -mtime -1 -exec ls -ld {} \;
Recursively change the group of all files in "/var/lib/php/session" to "lighttpd"
chown -R :lighttpd /var/lib/php/session
Find all foo.mp4 files in the current directory tree
find ./ -name "foo.mp4" -exec echo {} \;
Find all files that are set user ID to root
find . -user 0 -perm -4000 -print
Read a line from standard input into variable "text" with the prompt " Enter Here: "
read -p " Enter Here : " text
List the files in the /etc directory tree containing text '128.200.34.'
find /etc -type f -print | xargs grep -il '128\.200\.34\.'
Display the output of "ls" for an 80 character wide display
ls | column -c 80
Find all directories named "D" in the current directory tree
find . -name "D" -type d
Change the file extension from '.txt' to '.bak' for all files/directories under current directory tree
find . -name "*.txt" | sed "s/\.txt$//" | xargs -i echo mv {}.txt {}.bak | sh
display all the text files in the temp folder
find /tmp -name *.txt
List the files/directories under /PATH_to_SEARCH, do a numeric sort and print the ones with different inode numbers
find /PATH_to_SEARCH -ls | sort -n | awk '!seen[$1]++'
Decompress and extract 'archive.tar.gz' into '/destination'
gzip -dc archive.tar.gz | tar -xf - -C /destination
Make directories "tmp/real_dir1" and "tmp/real_dir2" as needed
mkdir -p tmp/real_dir1 tmp/real_dir2
display a long listing of all the files in the current folder that have been accessed in today from the start of the day
find -daystart -atime 0 -ls
Find all files/directories under ${CURR_DIR} directory
cd ${CURR_DIR} && find .
Go to first directory specified in PATH which contains the command 'oracle'
cd $(which oracle | xargs dirname)
find regular files in the current directory, without descending into sub-directories and display as a null separated list.
find -maxdepth 1 -type f -printf '%f\000'
Find recursively all files changed within the last 5 minutes starting from directory b
find b -cmin -5
find all the *.conf files under / (root)
find / -name "*.conf"
Remove the last 3 characters from 987654321, keeping only 987654
echo 987654321 | rev | cut -c 4- | rev
Search the /path directory tree for files lacking the group writable bit
find /path ! -perm /g+w
Find all regular files in /usr/bin accessed more than 20 days ago
find /usr/bin -type f -atime +20
find all the files in the folder ~/Music which begin with "Automatically Add"
find ~/Music/ -name "Automatically Add*"
Find all PHP files in the current directory recursively
find . -name \*.php -type f
find all files starting with capital letter in the current folder
find . — name "[A‑Z]*" — print
convert all the normal files in the current folder from dos format to unix format
find . -type f -exec dos2unix {} \;
display all the regular files in the current folder which dont not have the permission 777
find . -type f ! -perm 777
Prints process list with id numbers of a process having id 'pid'.
pstree -p [pid ...]
Login to "$HOST" and create file "$FILE_PATH" if it does not exist
ssh -q $HOST "[[ ! -f $FILE_PATH ]] && touch $FILE_PATH"
Copy recursively "/source/backup" to "/destination" preserving symbolic links, modification times, and permissions
rsync -rtvpl /source/backup /destination
Print the full path of executable "lshw"
which lshw
change the extension of all the ".abc" files in the folder "/the/path" to ".edefg" and do not change in the sub directories. execdir ensures that the command after it is executed only in the folder where the file is found
find /the/path -type f -name '*.abc' -execdir rename 's/\.\/(.+)\.abc$/version1_$1.abc/' {} \;
Prints list of user 'myuser' groups in a format: 'groups: [comma-separated groups list]'.
echo "groups: [ $(groups myuser | sed -e 's/.\+\s\+:\s\+\(.\+\)/\1/g' -e 's/\(\s\+\)/, /g') ]"
Send Output From Find The Find Command To A File
find / -name *.mp3 -fprint nameoffiletoprintto
use find -exec with multiple commands regardless of their success or failure
find . -name "*.txt" \( -exec echo {} \; -o -exec true \; \) -exec grep banana {} \;
Remount the root file system with read and write permission
mount -o rw,remount -t rootfs /
Replace all sequence of 'blank' characters in file 'log' with a single occurence of such symbol and print space-separated fields of each string but first two fields
cat log | tr -s [:blank:] |cut -d' ' -f 3-
search for all the links in a folder and display all the broken links
find -L /target -type l | while read -r file; do echo $file is orphaned; done
Print 2 lines of "123456789"
yes 123456789 | head -2
Set file permission to 664 and directory permission to 775 for all files and directories under htdocs
find htdocs -type f -exec chmod 664 {} + -o -type d -exec chmod 775 {} +
Store N symbols of input into variable 'buffer'
read -N $BUFSIZE buffer
Find all files under current directory excluding the $OUTPUT file, calculate their md5sum with $MD5SUM_OPTIONS options and redirect the result to $OUTPUT
find . -type f ! -name "$OUTPUT" -exec md5sum $MD5SUM_OPTIONS {} + > $OUTPUT
Find all files/directories named 'document' in the root filesystem partition
find / -xdev -name document -print
Create symbolic links in the current directory for all files located in directory "/path/with/files" with a name containing "txt"
find /path/with/files -type f -name "*txt*" -exec ln -s {} . ';'
Remount "/" without writing in "/etc/mtab"
mount -n -o remount /
Set the bash prompt to "username@hostname"
PS1="`whoami`@`hostname | sed 's/\..*//'`"
Find all files/directories under current directory tree whose paths match the regex 'filename-regex.\*\.html'
find . -regex filename-regex.\*\.html
Find things changed today
find /path/to/search -daystart -ctime -1
Search the /path directory tree for files missing g+w or o+w bits
find /path ! -perm -022
Find all test2.h files under current directory
sudo find . -name test2.h
Recursively removes all files like '*.pyc' in a current folder.
rm `find . -name \*.pyc`
Delete all regular files that have not been modified in the last 60 weeks under $DIR directory tree
find $DIR -type f -mtime +60w -exec rm {} \;
display all directories in current folder excluding those which do not have read permission to all users and save the output to a file
find . -type d ! -perm -g+r,u+r,o+r -prune -o -print > files_and_folders
Copy "fileName.txt" to all directories listed in "allFolders.txt" - names may not contain spaces.
cat allFolders.txt | xargs -n 1 cp fileName.txt
Find "*201512*" regular files in /home/myhome/data/ARCHIVE/ and move them to /home/myhome/ARCHIVE/TempFolder/
find /home/myhome/data/ARCHIVE/. -name . -o -type d -prune -o -name '*201512*' -print | xargs -i mv {} /home/myhome/ARCHIVE/TempFolder/.
Move all files in the current directory tree that match "some_pattern" to "target_location"
find . -name some_pattern -print0 | xargs -0 -J % mv % target_location
Prints only unique strings of those stored in variables $COMMANDS and $ALIASES.
echo "$COMMANDS"$'\n'"$ALIASES" | sort -u
recursively change owner of the directory /usr/lib/node_modules/ to the current user
sudo chown -R $(whoami) /usr/lib/node_modules/
extracts text between pattern1 and pattern2 if and only if the pattern1 is followed by pattern2
tac infile | sed -ne '/pattern2/,/pattern1/ p' | tac -
Recursively copy all files with names ending with .txt from dir_1 to the same location within copy_of_dir_1
rsync --recursive --prune-empty-dirs --include="*.txt" --filter="-! */" dir_1 copy_of_dir_1
Lists all manual pages.
apropos -r '.*'
Save number of processors in system to 'NP' variable
NP=`cat /proc/cpuinfo | grep processor | wc -l`
Print the current user's real name
getent passwd `whoami` | cut -d : -f 5
find and delete all the empty directories in the current folder and all its sub directories too
find . -depth -empty -type d -delete
Installs locally located 'ffmpeg-2.6.4-1.fc22.x86_64.rpm' package.
yum install ffmpeg-2.6.4-1.fc22.x86_64.rpm
Split "t.txt" into files with at most 30000000 lines each and use a prefix "t" and numeric suffixes of length 2
split --lines=30000000 --numeric-suffixes --suffix-length=2 t.txt t
List executable files in the current directory, sort the list and then display the differences between the list and file .gitignore.
find . -perm /111 -type f | sed 's#^./##' | sort | diff -u .gitignore -
Follows symbolic link $BASH_SOURCE, and prints path to its target.
$(dirname $)
Find all files/directories matching the regex .*sql.*
find -regex .*sql.*
Remove all tmp/*.mp3 files
find tmp -maxdepth 1 -name '*.mp3' -maxdepth 1 | xargs rm
Print "$1" or default 10 random lines from standard input
nl | sort -R | cut -f2 | head -"${1:-10}"
Find all files/directories in level 2 down the current directory
find -mindepth 2 -maxdepth 2
Replace all occurrences of '2013 Magento Inc.' with '2012 Magento Inc.' in all files with '.php, '.xml' and '.phtml' extensions under current directory tree
find . -name '*.php' -print0 -o -name '*.xml' -print0 -o -name '*.phtml' -print0 | xargs -0 sed -i '' 's/2013 Magento Inc./2012 Magento Inc./g'
display the list of all the normal files excluding hidden files which have been accessed in the last 500 days
find . -type f -not -name ‘.*’ -mtime +500 -exec ls {} \;
Find all .java files starting from the current folder
find . -name "*.java"
copy all the files with the extension ".type" from one folder to a target directory
find "$sourcedir" -type f -name "*.type" -exec sh -c 'for f; do cp "$f" "$0"; done' "$targetdir" {} +
Find files that are empty
find -empty -type -f
Find all directories by the name `httpdocs' on the system
find / -type d -name 'httpdocs'
List the z* links in the /usr/bin directory with inode information and the file to which it points to
find /usr/bin -type l -name "z*" -ls
Search the current directory tree for file "a.txt"
find . -name "a.txt" -print
Identify CMS version/releases accross all your Wordpress websites
find /home/*/public_html/ -type f -iwholename "*/wp-includes/version.php" -exec grep -H "\$wp_version =" {} \;
Find a more recent version of httpd.conf file than /etc/apache-perl/httpd.conf in entire file system
find / -name httpd.conf -newer /etc/apache-perl/httpd.conf
Delete empty lines from standard input
sed -n "s/^$//;t;p;"
display all the files in the home folder which end with ".xbm"
find ~ -name '*.xbm'